Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync typeshed #17586

Merged
merged 5 commits into from
Jul 25, 2024
Merged

Sync typeshed #17586

merged 5 commits into from
Jul 25, 2024

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Jul 25, 2024

Source commit:
python/typeshed@9eae1ae

cdce8p and others added 5 commits July 25, 2024 18:51
This is allegedly causing large performance problems, see 13821

typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.

If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.

(Reminder: add this to the sync_typeshed script once merged)
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

setuptools (https://github.com/pypa/setuptools)
  setuptools/command/__init__.py:6: error: No overload variant of "__setitem__" of "list" matches argument types "str", "Tuple[str, str]"  [call-overload]
  setuptools/command/__init__.py:6: note: Possible overload variants:
  setuptools/command/__init__.py:6: note:     def __setitem__(self, SupportsIndex, str, /) -> None
  setuptools/command/__init__.py:6: note:     def __setitem__(self, slice, Iterable[str], /) -> None

pandas (https://github.com/pandas-dev/pandas)
  pandas/io/common.py:915: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer"  [type-var]
  pandas/io/common.py:916: error: Unused "type: ignore" comment  [unused-ignore]

aioredis (https://github.com/aio-libs/aioredis)
- aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview | int")  [operator]
  aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview[int] | int")  [operator]
- aioredis/connection.py:934: error: Item "memoryview" of "bytes | memoryview | int" has no attribute "split"  [union-attr]
  aioredis/connection.py:934: error: Item "memoryview[int]" of "bytes | memoryview[int] | int" has no attribute "split"  [union-attr]
- aioredis/connection.py:934: error: Item "int" of "bytes | memoryview | int" has no attribute "split"  [union-attr]
  aioredis/connection.py:934: error: Item "int" of "bytes | memoryview[int] | int" has no attribute "split"  [union-attr]
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Any | None]", variable has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]")  [assignment]
  aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[int], Any | None]", variable has type "dict[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]")  [assignment]
- aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview, Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]"  [arg-type]
  aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview[int], Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]"  [arg-type]
- aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]")  [assignment]
  aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]")  [assignment]

ibis (https://github.com/ibis-project/ibis)
- ibis/backends/sqlite/tests/conftest.py:44: error: Incompatible types in assignment (expression has type "TextIOWrapper", variable has type "StringIO")  [assignment]
  ibis/backends/sqlite/tests/conftest.py:44: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "StringIO")  [assignment]

urllib3 (https://github.com/urllib3/urllib3)
  test/test_response.py:808: error: Unused "type: ignore" comment  [unused-ignore]
  test/test_response.py:808: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse"  [type-var]
  test/test_response.py:808: note: Error code "type-var" not covered by "type: ignore" comment
  test/test_response.py:822: error: Unused "type: ignore" comment  [unused-ignore]
  test/test_response.py:822: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse"  [type-var]
  test/test_response.py:822: note: Error code "type-var" not covered by "type: ignore" comment
  test/test_response.py:829: error: Unused "type: ignore" comment  [unused-ignore]
  test/test_response.py:829: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse"  [type-var]
  test/test_response.py:829: note: Error code "type-var" not covered by "type: ignore" comment

rich (https://github.com/Textualize/rich)
- rich/console.py:92: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
  rich/console.py:92: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno"  [union-attr]
- rich/console.py:96: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
  rich/console.py:96: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno"  [union-attr]
- rich/console.py:100: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
  rich/console.py:100: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno"  [union-attr]

pytest (https://github.com/pytest-dev/pytest)
  src/_pytest/capture.py:180: error: Returning Any from function declared to return "str"  [no-any-return]
  src/_pytest/capture.py:180: error: "_WrappedBuffer" has no attribute "mode"  [attr-defined]
  src/_pytest/capture.py:553: error: Incompatible return value type (got "Buffer", expected "bytes")  [return-value]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1130: note:     def [R, P`2102] builds(cls, type[BuildsWithSig[type[R], P]], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]
  src/hydra_zen/structured_configs/_implementations.py:1130: note:     def [R, P`2103] builds(cls, type[BuildsWithSig[type[R], P]], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]
- src/hydra_zen/structured_configs/_implementations.py:1130: note:     def [P`2104, R] builds(cls, Callable[P, R], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]
  src/hydra_zen/structured_configs/_implementations.py:1130: note:     def [P`2105, R] builds(cls, Callable[P, R], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]

... (truncated 8 lines) ...

vision (https://github.com/pytorch/vision)
- torchvision/models/_api.py:128: error: Unused "type: ignore" comment  [unused-ignore]

aiohttp (https://github.com/aio-libs/aiohttp)
  aiohttp/web_fileresponse.py:70: error: Unused "type: ignore" comment  [unused-ignore]
  aiohttp/web.py:327:25: error: Argument 2 to "TCPSite" has incompatible type "str | memoryview[Any]"; expected "str | None"  [arg-type]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/filesystems.py:359: error: Incompatible types in assignment (expression has type "Path", variable has type "TextIOWrapper")  [assignment]
  src/prefect/filesystems.py:359: error: Incompatible types in assignment (expression has type "Path", variable has type "TextIOWrapper[_WrappedBuffer]")  [assignment]
- src/prefect/filesystems.py:360: error: "TextIOWrapper" has no attribute "relative_to"  [attr-defined]
  src/prefect/filesystems.py:360: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "relative_to"  [attr-defined]
- src/prefect/filesystems.py:369: error: "TextIOWrapper" has no attribute "is_dir"  [attr-defined]
  src/prefect/filesystems.py:369: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "is_dir"  [attr-defined]
- src/prefect/filesystems.py:372: error: "TextIOWrapper" has no attribute "as_posix"  [attr-defined]
  src/prefect/filesystems.py:372: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "as_posix"  [attr-defined]

werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper", variable has type "LimitedStream")  [assignment]
  tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper[BufferedReader]", variable has type "LimitedStream")  [assignment]

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/web/server/component_request_handler_test.py: note: In function "test_support_binary_files_request":
- lib/tests/streamlit/web/server/component_request_handler_test.py:195:38: error: Argument 1 to "TextIOWrapper" has incompatible type "str"; expected "_WrappedBuffer"  [arg-type]

@cdce8p cdce8p mentioned this pull request Jul 25, 2024
@cdce8p
Copy link
Collaborator Author

cdce8p commented Jul 25, 2024

Mypy primer analysis

@JelleZijlstra JelleZijlstra merged commit e67decb into python:master Jul 25, 2024
19 checks passed
@cdce8p cdce8p deleted the update-typeshed branch July 25, 2024 17:56
@cdce8p
Copy link
Collaborator Author

cdce8p commented Jul 25, 2024

@JelleZijlstra Could you delete the mypybot/sync-typeshed branch? Not sure if it would cause an issue during the next typeshed update if the branch already exists. https://github.com/python/mypy/branches/active

@JelleZijlstra
Copy link
Member

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants