fix Incorrect type inference when overriding zip and other builtins #2385#2533
fix Incorrect type inference when overriding zip and other builtins #2385#2533asukaminato0721 wants to merge 3 commits intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes incorrect type inference when user code overrides builtins (e.g., zip) by ensuring implicit builtins wildcard imports do not shadow existing definitions during static scope initialization.
Changes:
- Adjust static scope setup to treat
builtins/__builtins__.pyiwildcard imports as fallback-only when names already exist. - Add a regression test covering
zipshadowing combined withreversed(...)type inference.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/binding/scope.rs |
Prevents builtins/extra_builtins wildcard imports from overwriting existing static-scope bindings. |
pyrefly/lib/test/simple.rs |
Adds a regression test validating correct inference when zip is locally overridden. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Presumably this PR also resolves #1197? |
|
It does, thanks! |
rchen152
left a comment
There was a problem hiding this comment.
Passing along some feedback from @grievejia:
What would happen if we use conditional overrides like this?
if cond(): # or while, try, with, etc. def zip(*args) -> list[int]: return [] # Would pyrefly completely disregard the built-in zip here?I'm a little concerned that unconditionally overwriting any built-in names might be too aggressive. What if the user actually wants to reuse the types or names from the built-ins?
|
yes Why this is correct:
|
e867f9d to
ace4242
Compare
rchen152
left a comment
There was a problem hiding this comment.
@asukaminato0721 I think the behavior you're observing is specific to function-local names, and Jia's concern was about conditionally overwriting a builtin at the module level. Try running this script a bunch of times:
import random
x = random.randint(0, 1)
if x:
def zip(*args):
return [42, 42, 42]
def f():
print(list(zip([1], [2])))
f()
Sometimes it prints [(1, 2)], and other times it prints [42, 42, 42], showing that when the local zip isn't defined, the Python runtime indeed falls back to the zip builtin. So it would be wrong for pyrefly to treat zip as unconditionally overwritten.
This comment has been minimized.
This comment has been minimized.
|
add a test to show it. function scope vs module scope. |
This comment has been minimized.
This comment has been minimized.
|
did some check... update track whether a definition is conditional; propagate this through control‑flow constructs. only skip builtins wildcard injection when a name is unconditionally defined; conditional defs still merge with builtins. |
This comment has been minimized.
This comment has been minimized.
9c8e6b4 to
6e2b8c3
Compare
|
Diff from mypy_primer, showing the effect of this PR on open source code: urllib3 (https://github.com/urllib3/urllib3)
- ERROR src/urllib3/connectionpool.py:479:32-33: `BaseSSLError | CertificateError | NewConnectionError | OSError | urllib3.exceptions.SSLError | ssl.SSLError | urllib3.exceptions.TimeoutError | builtins.TimeoutError` is not assignable to `Exception` [bad-assignment]
+ ERROR src/urllib3/connectionpool.py:479:32-33: `BaseSSLError | CertificateError | NewConnectionError | OSError | urllib3.exceptions.SSLError | ssl.SSLError | TimeoutError` is not assignable to `Exception` [bad-assignment]
- ERROR src/urllib3/connectionpool.py:824:32-33: `BaseSSLError | CertificateError | HTTPException | OSError | ProtocolError | ProxyError | urllib3.exceptions.SSLError | ssl.SSLError | urllib3.exceptions.TimeoutError | builtins.TimeoutError` is not assignable to `Exception` [bad-assignment]
+ ERROR src/urllib3/connectionpool.py:824:32-33: `BaseSSLError | CertificateError | HTTPException | OSError | ProtocolError | ProxyError | urllib3.exceptions.SSLError | ssl.SSLError | TimeoutError` is not assignable to `Exception` [bad-assignment]
psycopg (https://github.com/psycopg/psycopg)
- ERROR tests/scripts/dectest.py:40:14-34: Cannot index into `list[str]` [bad-index]
colour (https://github.com/colour-science/colour)
- ERROR colour/continuous/signal.py:1089:46-76: No matching overload found for function `pow` called with arguments: (ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) [no-matching-overload]
- ERROR colour/io/luts/lut.py:638:34-55: No matching overload found for function `pow` called with arguments: (ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) [no-matching-overload]
bandersnatch (https://github.com/pypa/bandersnatch)
- ERROR src/bandersnatch/tests/test_utils.py:47:35-43: Unexpected keyword argument `function` in function `hash` [unexpected-keyword]
- ERROR src/bandersnatch/tests/test_utils.py:48:35-43: Unexpected keyword argument `function` in function `hash` [unexpected-keyword]
- ERROR src/bandersnatch/verify.py:187:64-68: Argument `((obj: object, /) -> int) | ((path: Path, function: str = 'sha256') -> str)` is not assignable to parameter `func` with type `(object) -> int` in function `asyncio.events.AbstractEventLoop.run_in_executor` [bad-argument-type]
+ ERROR src/bandersnatch/verify.py:187:53-79: Unpacked argument `tuple[Path]` is not assignable to parameter `*args` with type `tuple[Path, str]` in function `asyncio.events.AbstractEventLoop.run_in_executor` [bad-argument-type]
Expression (https://github.com/cognitedata/Expression)
- ERROR expression/collections/array.py:373:16-25: Returned type `int | _TSourceSum` is not assignable to declared return type `int` [bad-return]
- ERROR expression/collections/asyncseq.py:18:20-39: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Self@AsyncSeq, ((AsyncIterable[TSource]) -> AsyncIterable[TResult]) | map[@_]) [no-matching-overload]
- ERROR expression/collections/asyncseq.py:18:30-38: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (TSource) -> TResult) [no-matching-overload]
- ERROR expression/collections/block.py:781:12-24: Returned type `((Block[tuple[*_P]]) -> Block[_TResult]) | map[@_]` is not assignable to declared return type `(Block[tuple[*_P]]) -> Block[_TResult]` [bad-return]
- ERROR expression/collections/block.py:781:15-24: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (args: tuple[*_P]) -> _TResult) [no-matching-overload]
- ERROR expression/collections/maptree.py:350:17-27: No matching overload found for function `iter` called with arguments: ((Key, Value) -> None, Option[MapTreeLeaf[Key, Value]]) [no-matching-overload]
- ERROR expression/collections/maptree.py:352:17-28: No matching overload found for function `iter` called with arguments: ((Key, Value) -> None, Option[MapTreeLeaf[Key, Value]]) [no-matching-overload]
- ERROR expression/collections/maptree.py:400:21-30: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (Key, Value) -> Result, Option[MapTreeLeaf[Key, Value]]) [no-matching-overload]
- ERROR expression/collections/maptree.py:402:21-31: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (Key, Value) -> Result, Option[MapTreeLeaf[Key, Value]]) [no-matching-overload]
- ERROR expression/collections/maptree.py:403:46-48: Argument `Option[MapTreeLeaf[Key, Result]] | map[@_]` is not assignable to parameter `left` with type `Option[MapTreeLeaf[Key, Result]]` in function `MapTreeNode.__init__` [bad-argument-type]
- ERROR expression/collections/maptree.py:403:50-52: Argument `Option[MapTreeLeaf[Key, Result]] | map[@_]` is not assignable to parameter `right` with type `Option[MapTreeLeaf[Key, Result]]` in function `MapTreeNode.__init__` [bad-argument-type]
- ERROR expression/collections/seq.py:93:20-37: Expected a callable, got `filter[@_]` [not-callable]
- ERROR expression/collections/seq.py:93:26-37: No matching overload found for function `filter.__new__` called with arguments: (type[filter[_T]], (_TSource) -> bool) [no-matching-overload]
- ERROR expression/collections/seq.py:196:24-43: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Self@Seq, ((Iterable[_TSource]) -> Iterable[_TResult]) | map[@_]) [no-matching-overload]
- ERROR expression/collections/seq.py:196:34-42: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (_TSource) -> _TResult) [no-matching-overload]
- ERROR expression/collections/seq.py:291:16-25: Returned type `Literal[0] | _TSupportsSum` is not assignable to declared return type `_TSupportsSum` [bad-return]
- ERROR expression/collections/seq.py:717:12-24: Returned type `((Iterable[Any]) -> Iterable[Any]) | map[@_]` is not assignable to declared return type `(Iterable[Any]) -> Iterable[Any]` [bad-return]
- ERROR expression/collections/seq.py:717:15-24: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (args: tuple[Any, ...]) -> Any) [no-matching-overload]
- ERROR expression/collections/seq.py:879:12-46: Returned type `Literal[0] | _TSupportsSum` is not assignable to declared return type `_TSupportsSum` [bad-return]
- ERROR expression/extra/parser.py:63:21-29: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (_A) -> _B) [no-matching-overload]
- ERROR expression/extra/parser.py:64:20-34: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Self@Parser, ((parser: Parser[_A]) -> Parser[_B]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:212:16-215:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[Any], ((parser: Parser[tuple[Any, ...]]) -> Parser[Any]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:214:12-21: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (values: tuple[Any, ...]) -> Any) [no-matching-overload]
- ERROR expression/extra/parser.py:237:16-242:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[(_A) -> _B], (p1: Parser[(_A) -> _B]) -> Parser[tuple[(_A) -> _B, _A]], ((parser: Parser[tuple[(_A) -> _B, _A]]) -> Parser[_B]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:241:12-20: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (fx: tuple[(_A) -> _B, _A]) -> _B) [no-matching-overload]
- ERROR expression/extra/parser.py:271:16-277:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (str, [_TSource](xs: Iterable[_TSource]) -> Block[_TSource], (Block[str]) -> Block[Parser[str]], [_A](parser_list: Block[Parser[_A]]) -> Parser[Block[_A]], ((parser: Parser[Unknown]) -> Parser[Unknown]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:276:12-34: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (x: Unknown) -> Unknown) [no-matching-overload]
- ERROR expression/extra/parser.py:348:36-52: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[_A], ((parser: Parser[_A]) -> Parser[Option[_A]]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:348:43-51: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (a: _A) -> Option[_A]) [no-matching-overload]
- ERROR expression/extra/parser.py:374:16-378:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[_A], (p1: Parser[_A]) -> Parser[tuple[_A, Any]], ((parser: Parser[tuple[_A, Any]]) -> Parser[_A]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:377:12-20: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (value: tuple[_A, Any]) -> _A) [no-matching-overload]
- ERROR expression/extra/parser.py:399:16-403:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[Any], (p1: Parser[Any]) -> Parser[tuple[Any, _B]], ((parser: Parser[tuple[Any, _B]]) -> Parser[_B]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:402:12-20: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (value: tuple[Any, _B]) -> _B) [no-matching-overload]
- ERROR expression/extra/parser.py:523:16-526:6: No matching overload found for function `expression.core.pipe.pipe` called with arguments: (Parser[Any], ((parser: Parser[Any]) -> Parser[None]) | map[@_]) [no-matching-overload]
- ERROR expression/extra/parser.py:525:12-20: No matching overload found for function `map.__new__` called with arguments: (type[map[_S]], (_: Any) -> None) [no-matching-overload]
- ERROR tests/test_map.py:11:24-33: Class `map` has no class attribute `empty` [missing-attribute]
- ERROR tests/test_map.py:12:12-24: Class `map` has no class attribute `is_empty` [missing-attribute]
- ERROR tests/test_map.py:18:24-33: Class `map` has no class attribute `empty` [missing-attribute]
- ERROR tests/test_map.py:19:16-28: Class `map` has no class attribute `is_empty` [missing-attribute]
- ERROR tests/test_map.py:27:9-19: Class `map` has no class attribute `create` [missing-attribute]
- ERROR tests/test_map.py:34:9-19: Class `map` has no class attribute `of_seq` [missing-attribute]
- ERROR tests/test_map.py:41:10-20: Class `map` has no class attribute `of_seq` [missing-attribute]
- ERROR tests/test_map.py:48:10-21: Class `map` has no class attribute `of_list` [missing-attribute]
- ERROR tests/test_map.py:49:19-29: Class `map` has no class attribute `to_seq` [missing-attribute]
- ERROR tests/test_map.py:74:21-31: Class `map` has no class attribute `remove` [missing-attribute]
- ERROR tests/test_map.py:82:10-20: Class `map` has no class attribute `of_seq` [missing-attribute]
- ERROR tests/test_map.py:90:10-22: Class `map` has no class attribute `of_block` [missing-attribute]
- ERROR tests/test_map.py:100:10-22: Class `map` has no class attribute `of_block` [missing-attribute]
- ERROR tests/test_map.py:107:10-16: Class `map` has no class attribute `of` [missing-attribute]
- ERROR tests/test_map.py:109:18-25: Class `map` has no class attribute `map` [missing-attribute]
- ERROR tests/test_map.py:111:18-24: Class `map` has no class attribute `of` [missing-attribute]
- ERROR tests/test_map.py:116:25-31: Class `map` has no class attribute `of` [missing-attribute]
- ERROR tests/test_map.py:118:34-43: Class `map` has no class attribute `count` [missing-attribute]
- ERROR tests/test_map.py:123:22-28: Class `map` has no class attribute `of` [missing-attribute]
pyodide (https://github.com/pyodide/pyodide)
- ERROR src/py/webbrowser.py:31:13-34: No matching overload found for function `open` called with arguments: (str, int, bool) [no-matching-overload]
- ERROR src/py/webbrowser.py:49:16-24: No matching overload found for function `open` called with arguments: (str, Literal[1]) [no-matching-overload]
- ERROR src/py/webbrowser.py:53:16-24: No matching overload found for function `open` called with arguments: (str, Literal[2]) [no-matching-overload]
zulip (https://github.com/zulip/zulip)
- ERROR zerver/tests/test_link_embed.py:681:45-62: Argument `requests.exceptions.ConnectionError | builtins.ConnectionError` is not assignable to parameter `body` with type `requests.exceptions.ConnectionError | str | None` in function `PreviewTestCase.create_mock_response` [bad-argument-type]
- ERROR zerver/tests/test_link_embed.py:896:45-62: Argument `requests.exceptions.ConnectionError | builtins.ConnectionError` is not assignable to parameter `body` with type `requests.exceptions.ConnectionError | str | None` in function `PreviewTestCase.create_mock_response` [bad-argument-type]
asynq (https://github.com/quora/asynq)
- ERROR asynq/tests/test_base.py:39:14-29: No matching overload found for function `set.__init__` called with arguments: (Unknown, Unknown) [no-matching-overload]
- ERROR asynq/tests/test_base.py:46:20-32: No matching overload found for function `set.__init__` called with arguments: (Literal[0], Literal['value']) [no-matching-overload]
- ERROR asynq/tests/test_performance.py:53:14-29: No matching overload found for function `set.__init__` called with arguments: (Unknown, Unknown) [no-matching-overload]
- ERROR asynq/tests/test_performance.py:62:14-20: No matching overload found for function `set.__init__` called with arguments: (Literal[0], Literal[0]) [no-matching-overload]
operator (https://github.com/canonical/operator)
- ERROR ops/pebble.py:2255:21-38: Class `Warning` has no class attribute `from_dict` [missing-attribute]
+ ERROR ops/pebble.py:2255:20-66: Returned type `list[builtins.Warning]` is not assignable to declared return type `list[ops.pebble.Warning]` [bad-return]
pandera (https://github.com/pandera-dev/pandera)
+ WARN pandera/__init__.py:15:15-18:6: `__all__` could not be statically analyzed; falling back to module-level definitions for star imports [unresolvable-dunder-all]
streamlit (https://github.com/streamlit/streamlit)
- ERROR lib/streamlit/testing/v1/element_tree.py:2151:32-61: `streamlit.testing.v1.element_tree.Warning | builtins.Warning` is not assignable to variable `new_node` with type `Block | Element` [bad-assignment]
- ERROR lib/streamlit/testing/v1/element_tree.py:2151:51-55: Unexpected keyword argument `root` in function `BaseException.__init__` [unexpected-keyword]
- ERROR lib/streamlit/testing/v1/element_tree.py:2181:28-63: `streamlit.testing.v1.element_tree.Exception | builtins.Exception` is not assignable to variable `new_node` with type `Block | Element` [bad-assignment]
- ERROR lib/streamlit/testing/v1/element_tree.py:2181:53-57: Unexpected keyword argument `root` in function `BaseException.__init__` [unexpected-keyword]
setuptools (https://github.com/pypa/setuptools)
- ERROR setuptools/_vendor/backports/tarfile/__init__.py:2829:21-35: No matching overload found for function `open` called with arguments: (fileobj=Unknown) [no-matching-overload]
strawberry (https://github.com/strawberry-graphql/strawberry)
- ERROR strawberry/experimental/pydantic/object_type.py:325:16-334:6: No matching overload found for function `type.__new__` called with arguments: (type[type], model=type[PydanticModel], name=str | None, is_input=Literal[True], is_interface=bool, description=str | None, directives=Sequence[object] | None, all_fields=bool, use_pydantic_alias=bool) [no-matching-overload]
- ERROR strawberry/experimental/pydantic/object_type.py:353:16-362:6: No matching overload found for function `type.__new__` called with arguments: (type[type], model=type[PydanticModel], name=str | None, is_input=bool, is_interface=Literal[True], description=str | None, directives=Sequence[object] | None, all_fields=bool, use_pydantic_alias=bool) [no-matching-overload]
mitmproxy (https://github.com/mitmproxy/mitmproxy)
- ERROR mitmproxy/tools/console/window.py:61:18-31: Object of class `_Helper` has no attribute `HelpView` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:30:14-26: Class `zip` has no class attribute `prettify` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:40:12-32: Class `zip` has no class attribute `syntax_highlight` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:48:9-21: Class `zip` has no class attribute `prettify` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:53:12-31: Class `zip` has no class attribute `render_priority` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:54:12-31: Class `zip` has no class attribute `render_priority` [missing-attribute]
- ERROR test/mitmproxy/contentviews/test__view_zip.py:55:12-31: Class `zip` has no class attribute `render_priority` [missing-attribute]
bokeh (https://github.com/bokeh/bokeh)
- ERROR src/bokeh/core/validation/check.py:198:70-89: Class `Warning` has no class attribute `get_by_code` [missing-attribute]
- ERROR src/bokeh/core/validation/decorators.py:76:25-43: Class `Warning` has no class attribute `get_by_name` [missing-attribute]
- ERROR src/bokeh/core/validation/decorators.py:80:29-47: Class `Warning` has no class attribute `get_by_code` [missing-attribute]
- ERROR src/bokeh/core/validation/issue.py:52:9-26: Class `Warning` has no class attribute `_code_map` [missing-attribute]
- ERROR src/bokeh/core/validation/issue.py:53:9-26: Class `Warning` has no class attribute `_name_map` [missing-attribute]
+ ERROR src/bokeh/core/validation/check.py:198:70-101: Argument `builtins.Warning` is not assignable to parameter `warning` with type `bokeh.core.validation.issue.Warning` in function `is_silenced` [bad-argument-type]
+ ERROR src/bokeh/core/validation/decorators.py:76:25-50: `Error | Warning` is not assignable to variable `issue` with type `Issue` [bad-assignment]
+ ERROR src/bokeh/core/validation/decorators.py:80:29-61: `Error | Warning` is not assignable to variable `issue` with type `Issue` [bad-assignment]
+ ERROR src/bokeh/core/validation/issue.py:52:40-44: Cannot set item in `dict[int, Warning]` [unsupported-operation]
+ ERROR src/bokeh/core/validation/issue.py:53:40-44: Cannot set item in `dict[str, Warning]` [unsupported-operation]
aioredis (https://github.com/aio-libs/aioredis)
- ERROR aioredis/client.py:1105:34-46: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/client.py:1105:34-46: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/client.py:4047:34-46: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/client.py:4047:34-46: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/client.py:4452:34-46: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/client.py:4452:34-46: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/client.py:4461:24-25: Expression `e` has type `aioredis.exceptions.ConnectionError | builtins.ConnectionError | aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` or `None` [bad-raise]
+ ERROR aioredis/client.py:4461:24-25: Expression `e` has type `ConnectionError | TimeoutError`, expected `BaseException` or `None` [bad-raise]
- ERROR aioredis/client.py:4473:38-50: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/client.py:4473:38-50: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/client.py:4648:34-46: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/client.py:4648:34-46: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/client.py:4656:24-25: Expression `e` has type `aioredis.exceptions.ConnectionError | builtins.ConnectionError | aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` or `None` [bad-raise]
+ ERROR aioredis/client.py:4656:24-25: Expression `e` has type `ConnectionError | TimeoutError`, expected `BaseException` or `None` [bad-raise]
- ERROR aioredis/connection.py:281:23-66: Expression `TimeoutError("Timeout reading from socket")` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ ERROR aioredis/connection.py:281:23-66: Expression `TimeoutError("Timeout reading from socket")` has type `TimeoutError`, expected `BaseException` [bad-raise]
- ERROR aioredis/connection.py:509:23-66: Expression `TimeoutError("Timeout reading from socket")` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ ERROR aioredis/connection.py:509:23-66: Expression `TimeoutError("Timeout reading from socket")` has type `TimeoutError`, expected `BaseException` [bad-raise]
- ERROR aioredis/connection.py:696:19-63: Expression `TimeoutError("Timeout connecting to server")` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ ERROR aioredis/connection.py:696:19-63: Expression `TimeoutError("Timeout connecting to server")` has type `TimeoutError`, expected `BaseException` [bad-raise]
- )` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ )` has type `TimeoutError`, expected `BaseException` [bad-raise]
- ERROR aioredis/connection.py:826:38-50: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/connection.py:826:38-50: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/connection.py:835:37-40: Expression `err` has type `aioredis.exceptions.ConnectionError | builtins.ConnectionError | aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` or `None` [bad-raise]
+ ERROR aioredis/connection.py:835:37-40: Expression `err` has type `ConnectionError | TimeoutError`, expected `BaseException` or `None` [bad-raise]
- ERROR aioredis/connection.py:866:19-60: Expression `TimeoutError("Timeout writing to socket")` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ ERROR aioredis/connection.py:866:19-60: Expression `TimeoutError("Timeout writing to socket")` has type `TimeoutError`, expected `BaseException` [bad-raise]
- ERROR aioredis/connection.py:903:19-80: Expression `TimeoutError(f"Timeout reading from {self.host}:{self.port}")` has type `aioredis.exceptions.TimeoutError | builtins.TimeoutError`, expected `BaseException` [bad-raise]
+ ERROR aioredis/connection.py:903:19-80: Expression `TimeoutError(f"Timeout reading from {self.host}:{self.port}")` has type `TimeoutError`, expected `BaseException` [bad-raise]
- ERROR aioredis/sentinel.py:223:38-50: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/sentinel.py:223:38-50: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
- ERROR aioredis/sentinel.py:253:53-65: Invalid exception class: `aioredis.exceptions.TimeoutError | builtins.TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
+ ERROR aioredis/sentinel.py:253:53-65: Invalid exception class: `TimeoutError` does not inherit from `BaseException` [invalid-inheritance]
prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/prefect/task_worker.py:518:41-520:10: No matching overload found for function `BaseExceptionGroup.split` called with arguments: (tuple[type[StopTaskWorker], type[CancelledError], type[KeyboardInterrupt], type[TimeoutError]]) [no-matching-overload]
pip (https://github.com/pypa/pip)
- ERROR src/pip/_vendor/pygments/__init__.py:82:48-55: Expected 2 positional arguments, got 3 in function `format` [bad-argument-count]
- ERROR src/pip/_vendor/requests/adapters.py:659:40-47: Unexpected keyword argument `request` in function `BaseException.__init__` [unexpected-keyword]
- ERROR src/pip/_vendor/requests/adapters.py:677:38-45: Unexpected keyword argument `request` in function `BaseException.__init__` [unexpected-keyword]
- ERROR src/pip/_vendor/requests/adapters.py:680:38-45: Unexpected keyword argument `request` in function `BaseException.__init__` [unexpected-keyword]
jax (https://github.com/google/jax)
- (a: _SupportsShape[Never]) -> tuple[Any, ...]
- [_ShapeT: tuple[int, ...]](a: _SupportsShape[_ShapeT]) -> _ShapeT
- (a: _PyScalar) -> tuple[()]
- (a: _PyArray) -> tuple[int]
- (a: _PyArray) -> tuple[int, int]
- (a: bytearray | memoryview[int]) -> tuple[int]
- (a: ArrayLike) -> tuple[Any, ...]
- ], dict_values[ErrorEffect, Bool]) [no-matching-overload]
- ERROR jax/_src/checkify.py:230:15-46: No matching overload found for function `map.__new__` called with arguments: (type[map[object]], Overload[
- ERROR jax/_src/interpreters/mlir.py:2148:65-74: Argument `list[Unknown] | map[Unknown]` is not assignable to parameter `avals_out` with type `Sequence[AbstractValue]` in function `_emit_lowering_rule_as_fun` [bad-argument-type]
- ERROR jax/_src/interpreters/remat.py:142:36-46: Argument `list[Unknown] | map[Unknown]` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- ERROR jax/experimental/jax2tf/call_tf.py:191:15-194:53: Argument `list[tuple[Any, ShapedArray]] | list[tuple[Any, None]] | zip[tuple[Any, ShapedArray]] | zip[tuple[Any, None]]` is not assignable to parameter `iterable` with type `Iterable[tuple[Any, ShapedArray]]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR jax/experimental/jax2tf/call_tf.py:191:15-194:53: Argument `list[tuple[Any, ShapedArray]] | list[tuple[Any, None]]` is not assignable to parameter `iterable` with type `Iterable[tuple[Any, ShapedArray]]` in function `enumerate.__new__` [bad-argument-type]
- ERROR jax/experimental/roofline/roofline.py:221:22-43: Argument `list[AbstractValue] | map[AbstractValue]` is not assignable to parameter `avals_in` with type `Sequence[AbstractValue]` in function `RooflineRuleContext.__init__` [bad-argument-type]
- ERROR jax/experimental/roofline/roofline.py:222:23-45: Argument `list[AbstractValue] | map[AbstractValue]` is not assignable to parameter `avals_out` with type `Sequence[AbstractValue]` in function `RooflineRuleContext.__init__` [bad-argument-type]
- ERROR jax/experimental/roofline/roofline.py:234:38-51: Argument `list[RooflineShape] | map[RooflineShape]` is not assignable to parameter `shapes` with type `Sequence[RooflineShape]` in function `sum_bytes` [bad-argument-type]
materialize (https://github.com/MaterializeInc/materialize)
- ERROR test/aws/mzcompose.py:160:17-23: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:161:48-54: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:176:17-23: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:177:47-53: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:201:16-22: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:201:61-67: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:222:20-26: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:228:17-23: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:228:64-70: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:231:17-23: Object of class `SystemError` has no attribute `diag` [missing-attribute]
- ERROR test/aws/mzcompose.py:233:20-26: Object of class `SystemError` has no attribute `diag` [missing-attribute]
sphinx (https://github.com/sphinx-doc/sphinx)
- ERROR sphinx/directives/admonitions.py:100:34-41: Argument `type[sphinx.directives.admonitions.Warning] | type[builtins.Warning]` is not assignable to parameter `cls` with type `type[Directive]` in function `sphinx.application.Sphinx.add_directive` [bad-argument-type]
pywin32 (https://github.com/mhammond/pywin32)
- ERROR Pythonwin/pywin/Demos/ocx/msoffice.py:16:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/Demos/ocx/msoffice.py:53:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/framework/intpydde.py:25:9-22: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR Pythonwin/pywin/framework/intpydde.py:42:9-22: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/docview.py:56:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/docview.py:61:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/docview.py:85:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/docview.py:98:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/thread.py:12:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/mfc/window.py:10:9-25: Class `object` has no class attribute `CmdTarget` [missing-attribute]
- ERROR Pythonwin/pywin/tools/hierlist.py:75:20-33: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR win32/Demos/dde/ddeserver.py:10:9-22: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR win32/Demos/dde/ddeserver.py:18:9-22: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR win32/Demos/dde/ddeserver.py:28:9-22: Class `object` has no class attribute `Object` [missing-attribute]
- ERROR win32/Demos/desktopmanager.py:84:5-12: `+=` is not supported between `(obj: object, /) -> int` and `Literal[1]` [unsupported-operation]
|
Primer Diff Classification❌ 4 regression(s) | ✅ 16 improvement(s) | ➖ 2 neutral | 22 project(s) total 4 regression(s) across bandersnatch, pandera, bokeh, jax. error kinds:
Detailed analysis❌ Regression (4)bandersnatch (+1, -3)
pandera (+1)
bokeh (+5, -5)
jax (+1, -6)
✅ Improvement (16)psycopg (-1)
colour (-2)
Expression (-54)
pyodide (-3)
zulip (-2)
asynq (-4)
operator (+1, -1)
streamlit (-4)
setuptools (-1)
strawberry (-2)
mitmproxy (-7)
prefect (-1)
pip (-4)
materialize (-11)
sphinx (-1)
pywin32 (-15)
➖ Neutral (2)urllib3 (+2, -2)
aioredis (+16, -16)
Suggested FixSummary: The PR fixed builtin shadowing issues but introduced regressions where imported names are incorrectly resolved to builtins instead of their proper imports. 1. In Static::
2. In Static::
3. In the conditional tracking logic in
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (2 heuristic, 20 LLM) |
kinto0
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #2385
Prevented builtins wildcard imports from shadowing existing definitions during static scope setup, so local overrides (like zip) no longer get merged with builtins.
Test Plan
Added a regression test to cover shadowing zip and using reversed.