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 #12321

Merged
merged 7 commits into from
Apr 8, 2022
Merged

Sync typeshed #12321

merged 7 commits into from
Apr 8, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Mar 9, 2022

Source commit:
python/typeshed@4e87b90

@github-actions

This comment has been minimized.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 9, 2022

There's quite a lot of fallout. I will investigate the (possible) regressions and test failures later.

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 9, 2022

To save you some time on a few of these:

@hauntsaninja
Copy link
Collaborator

Here's a PR that will fix several of the broken tests here: #12323

@github-actions

This comment has been minimized.

@graingert
Copy link
Contributor

This doesn't seem right, __anext__ Can return any Awaitable object

 tornado/gen.py:429: note:     Expected:
+ tornado/gen.py:429: note:         def __anext__(self) -> Coroutine[Any, Any, Any]
+ tornado/gen.py:429: note:     Got:
+ tornado/gen.py:429: note:         def __anext__(self) -> Future[Any]
+

@graingert
Copy link
Contributor

This doesn't seem right, __anext__ Can return any Awaitable object

 tornado/gen.py:429: note:     Expected:
+ tornado/gen.py:429: note:         def __anext__(self) -> Coroutine[Any, Any, Any]
+ tornado/gen.py:429: note:     Got:
+ tornado/gen.py:429: note:         def __anext__(self) -> Future[Any]
+

Being fixed here python/typeshed#7491

@AlexWaygood
Copy link
Member

This doesn't seem right, __anext__ Can return any Awaitable object

 tornado/gen.py:429: note:     Expected:
+ tornado/gen.py:429: note:         def __anext__(self) -> Coroutine[Any, Any, Any]
+ tornado/gen.py:429: note:     Got:
+ tornado/gen.py:429: note:         def __anext__(self) -> Future[Any]
+

python/typeshed#7491 has now been merged, so I think this particular regression has now been fixed on typeshed's master branch (thanks again for your help reviewing @graingert).

@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2022

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

boostedblob (https://github.com/hauntsaninja/boostedblob)
+ boostedblob/boost.py:547: error: Need type annotation for "task"
+ boostedblob/boost.py:547: error: Argument 1 to "create_task" has incompatible type "Awaitable[T]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]"

bidict (https://github.com/jab/bidict)
+ bidict/_frozenbidict.py:38: error: Unused "type: ignore" comment

paasta (https://github.com/yelp/paasta)
- paasta_tools/instance/kubernetes.py:571: error: Argument 1 to "append" of "list" has incompatible type "Task[Sequence[Any]]"; expected "Future[Dict[str, Any]]"
+ paasta_tools/instance/kubernetes.py:563: error: Need type annotation for "pods_task"
+ paasta_tools/instance/kubernetes.py:564: error: Argument 1 to "create_task" has incompatible type "Awaitable[Sequence[Any]]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]"
+ paasta_tools/instance/kubernetes.py:1054: error: Need type annotation for "pods_task"
+ paasta_tools/instance/kubernetes.py:1055: error: Argument 1 to "create_task" has incompatible type "Awaitable[Sequence[Any]]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]"
+ paasta_tools/instance/kubernetes.py:1239: error: Need type annotation for "pods_task"
+ paasta_tools/instance/kubernetes.py:1240: error: Argument 1 to "create_task" has incompatible type "Awaitable[Sequence[Any]]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]"

pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/class_validators.py:332: error: Need type annotation for "all_attributes"  [var-annotated]
+ pydantic/class_validators.py:332: error: Argument 1 to "ChainMap" has incompatible type "*List[MappingProxyType[str, Any]]"; expected "MutableMapping[<nothing>, <nothing>]"  [arg-type]

pandera (https://github.com/pandera-dev/pandera)
+ pandera/checks.py:74: error: Argument 1 to "ChainMap" has incompatible type "MappingProxyType[str, Any]"; expected "MutableMapping[str, Callable[..., Any]]"  [arg-type]
+ pandera/model.py:373: error: Need type annotation for "attrs" (hint: "attrs: Dict[<type>, <type>] = ...")  [var-annotated]

anyio (https://github.com/agronholm/anyio)
+ src/anyio/from_thread.py:397: error: Argument 2 to "submit" of "Executor" has incompatible type "Callable[[], Coroutine[Any, Any, None]]"; expected "Callable[..., Coroutine[Any, Any, T_Retval]]"  [arg-type]
+ src/anyio/_backends/_asyncio.py:1365: error: Redundant cast to "StreamProtocol"  [redundant-cast]
+ src/anyio/_backends/_asyncio.py:1555: error: Redundant cast to "DatagramProtocol"  [redundant-cast]
+ src/anyio/_backends/_asyncio.py:1571: error: Unused "type: ignore" comment

pip (https://github.com/pypa/pip)
+ src/pip/_internal/network/session.py:406: error: Argument 1 to "ip_address" has incompatible type "Optional[str]"; expected "Union[int, str, bytes, IPv4Address, IPv6Address]"
+ src/pip/_internal/network/lazy_wheel.py:139: error: "__exit__" of "_TemporaryFileWrapper" does not return a value

steam.py (https://github.com/Gobot1234/steam.py)
- steam/_const.py:16: error: Module "typing_extensions" has no attribute "Never"  [attr-defined]
- steam/enums.py:118: error: Incompatible types in "yield from" (actual type "Enum", expected type "E")  [misc]
- steam/enums.py:181: note:     def [_TT <: type] __new__(cls, cls: Type[_TT], str, Tuple[type, ...], Dict[str, Any], **kwds: Any) -> _TT
+ steam/enums.py:181: note:     def [Self] __new__(cls, cls: Type[Self], str, Tuple[type, ...], Dict[str, Any], **kwds: Any) -> Self
- steam/manifest.py:45: error: Module "typing_extensions" has no attribute "Never"  [attr-defined]
+ steam/clan.py:555: error: Parameter 1 of Literal[...] is invalid  [misc]
+ steam/clan.py:567: error: Variable "steam.enums.ClanEvent.Other" is not valid as a type  [valid-type]
+ steam/clan.py:567: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ steam/clan.py:567: error: Parameter 1 of Literal[...] is invalid  [misc]
+ steam/http.py:114: error: Variable "steam.http.StrOrURL" is not valid as a type  [valid-type]
- steam/clan.py:555: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ steam/http.py:114: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/debug/tbtools.py:378: error: Unsupported operand types for - ("None" and "int")  [operator]
+ src/werkzeug/debug/tbtools.py:378: note: Left operand is of type "Optional[int]"
+ src/werkzeug/test.py:94: error: Incompatible types in assignment (expression has type "Callable[[bytes], int]", variable has type "Callable[[Arg(bytes, 's')], int]")  [assignment]
- tests/test_wrappers.py:1109: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1123: error: Function is missing a return type annotation  [no-untyped-def]
- tests/test_wrappers.py:1123: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1132: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ tests/test_wrappers.py:1109: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)

zulip (https://github.com/zulip/zulip)
+ zerver/lib/test_console_output.py:123: error: Return type "Optional[bool]" of "__exit__" incompatible with return type "None" in supertype "IO"  [override]

tornado (https://github.com/tornadoweb/tornado)
+ tornado/platform/asyncio.py:662: error: Return type "None" of "remove_reader" incompatible with return type "bool" in supertype "AbstractEventLoop"
+ tornado/platform/asyncio.py:666: error: Return type "None" of "remove_writer" incompatible with return type "bool" in supertype "AbstractEventLoop"

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/locale/__init__.py: note: In member "__radd__" of class "_TranslationProxy":
+ sphinx/locale/__init__.py:62:5: error: Argument 1 of "__radd__" is incompatible with supertype "UserString"; supertype defines the argument type as "object"
+ sphinx/locale/__init__.py:62:5: note: This violates the Liskov substitution principle
+ sphinx/locale/__init__.py:62:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
+ sphinx/locale/__init__.py:62:5: error: Return type "str" of "__radd__" incompatible with return type "_TranslationProxy" in supertype "UserString"
+ sphinx/locale/__init__.py: note: In member "__rmod__" of class "_TranslationProxy":
+ sphinx/locale/__init__.py:68:5: error: Return type "str" of "__rmod__" incompatible with return type "_TranslationProxy" in supertype "UserString"
+ sphinx/locale/__init__.py: note: In member "__rmul__" of class "_TranslationProxy":
+ sphinx/locale/__init__.py:74:5: error: Return type "str" of "__rmul__" incompatible with return type "_TranslationProxy" in supertype "UserString"
+ sphinx/domains/python.py:1442: error: Unused "type: ignore" comment

pylint (https://github.com/pycqa/pylint)
+ pylint/config/arguments_manager.py:84: error: Argument "action" to "add_argument" of "_ActionsContainer" has incompatible type "str"; expected "Union[Type[Action], Literal['store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'count', 'help', 'version', 'extend']]"  [arg-type]
+ pylint/config/arguments_manager.py:129: error: Argument "action" to "add_argument" of "_ActionsContainer" has incompatible type "str"; expected "Union[Type[Action], Literal['store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'count', 'help', 'version', 'extend']]"  [arg-type]

python-chess (https://github.com/niklasf/python-chess)
+ chess/engine.py:122: error: Unused "type: ignore" comment
+ chess/engine.py:123: error: Unused "type: ignore" comment
+ chess/engine.py:1214: error: Unused "type: ignore" comment

pyp (https://github.com/hauntsaninja/pyp)
+ pyp.py:643: error: Argument 1 to "code_for_line" has incompatible type "Optional[int]"; expected "int"
+ pyp.py:643: note: Error code "arg-type" not covered by "type: ignore" comment

pylox (https://github.com/sco1/pylox)
- pylox/containers/array.py:84: error: All overload variants of "pop" of "MutableMapping" require at least one argument  [call-overload]
+ pylox/containers/array.py:84: error: All overload variants of "pop" of "dict" require at least one argument  [call-overload]
- pylox/containers/array.py:84: note:     def [_T] pop(self, Any, Union[Any, _T] = ...) -> Union[Any, _T]
+ pylox/containers/array.py:84: note:     def [_T] pop(self, Any, Union[Any, _T]) -> Union[Any, _T]

websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/client.py:641: error: "_ProtocolT" has no attribute "close"
+ src/websockets/legacy/client.py:655: error: Incompatible types in assignment (expression has type "WebSocketClientProtocol", variable has type "_ProtocolT")
+ src/websockets/legacy/client.py:658: error: "_ProtocolT" has no attribute "handshake"
+ src/websockets/legacy/client.py:660: error: "_ProtocolT" has no attribute "origin"
+ src/websockets/legacy/client.py:661: error: "_ProtocolT" has no attribute "available_extensions"
+ src/websockets/legacy/client.py:662: error: "_ProtocolT" has no attribute "available_subprotocols"
+ src/websockets/legacy/client.py:663: error: "_ProtocolT" has no attribute "extra_headers"
+ src/websockets/legacy/client.py:666: error: "_ProtocolT" has no attribute "fail_connection"
+ src/websockets/legacy/client.py:667: error: "_ProtocolT" has no attribute "wait_closed"
+ src/websockets/legacy/client.py:671: error: "_ProtocolT" has no attribute "fail_connection"
+ src/websockets/legacy/client.py:672: error: "_ProtocolT" has no attribute "wait_closed"
+ src/websockets/legacy/client.py:676: error: Incompatible return value type (got "_ProtocolT", expected "WebSocketClientProtocol")

xarray (https://github.com/pydata/xarray)
+ xarray/core/alignment.py:534: error: Argument 1 to "_reindex_one" of "Aligner" has incompatible type "Tuple[DataAlignable, Dict[Tuple[Tuple[Tuple[Hashable, Tuple[Hashable, ...]], ...], Type[Index]], Index]]"; expected "DataAlignable"  [arg-type]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/connector.py:1298: error: Redundant cast to "ResponseHandler"  [redundant-cast]

freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/data/history/jsondatahandler.py:27: error: Signature of "ohlcv_get_available_data" incompatible with supertype "IDataHandler"
+ freqtrade/data/history/jsondatahandler.py:49: error: Signature of "ohlcv_get_pairs" incompatible with supertype "IDataHandler"
+ freqtrade/data/history/jsondatahandler.py:140: error: Signature of "trades_get_pairs" incompatible with supertype "IDataHandler"
+ freqtrade/data/history/hdf5datahandler.py:25: error: Signature of "ohlcv_get_available_data" incompatible with supertype "IDataHandler"
+ freqtrade/data/history/hdf5datahandler.py:48: error: Signature of "ohlcv_get_pairs" incompatible with supertype "IDataHandler"
+ freqtrade/data/history/hdf5datahandler.py:145: error: Signature of "trades_get_pairs" incompatible with supertype "IDataHandler"

core (https://github.com/home-assistant/core)
+ homeassistant/util/async_.py:158: error: Item "None" of "Optional[str]" has no attribute "strip"  [union-attr]
+ homeassistant/util/async_.py:164: error: Item "None" of "Optional[str]" has no attribute "strip"  [union-attr]
+ homeassistant/helpers/frame.py:112: error: Item "None" of "Optional[str]" has no attribute "strip"  [union-attr]
+ homeassistant/core.py:441: error: Argument 1 to "create_task" of "AbstractEventLoop" has incompatible type "Awaitable[_R]"; expected "Union[Coroutine[Any, Any, _R], Generator[Any, None, _R]]"  [arg-type]
+ homeassistant/core.py:472: error: Need type annotation for "task"  [var-annotated]
+ homeassistant/core.py:472: error: Argument 1 to "create_task" of "AbstractEventLoop" has incompatible type "Awaitable[_R]"; expected "Union[Coroutine[Any, Any, <nothing>], Generator[Any, None, <nothing>]]"  [arg-type]
+ homeassistant/runner.py:51: error: Unused "type: ignore[misc, valid-type]" comment
+ homeassistant/runner.py:62: error: "HassEventLoopPolicy" has no attribute "_loop_factory"  [attr-defined]
+ homeassistant/runner.py:62: note: Error code "attr-defined" not covered by "type: ignore" comment
+ homeassistant/components/fritz/config_flow.py:133: error: Argument 1 to "ip_address" has incompatible type "Optional[str]"; expected "Union[int, str, bytes, IPv4Address, IPv6Address]"  [arg-type]
+ homeassistant/components/statistics/sensor.py:648: error: Argument "method" to "quantiles" has incompatible type "str"; expected "Literal['inclusive', 'exclusive']"  [arg-type]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/_libs/tslibs/timestamps.pyi:116: error: Return type "datetime" of "replace" incompatible with return type "Timestamp" in supertype "datetime"  [override]
+ pandas/_libs/tslibs/timestamps.pyi:116: error: Signature of "replace" incompatible with supertype "date"  [override]
+ pandas/_libs/tslibs/timestamps.pyi:116: note:      Superclass:
+ pandas/_libs/tslibs/timestamps.pyi:116: note:          def replace(self, year: int = ..., month: int = ..., day: int = ...) -> Timestamp
+ pandas/_libs/tslibs/timestamps.pyi:116: note:      Subclass:
+ pandas/_libs/tslibs/timestamps.pyi:116: note:          def replace(self, year: int = ..., month: int = ..., day: int = ..., hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ..., tzinfo: Optional[tzinfo] = ..., fold: int = ...) -> datetime
+ pandas/_config/localization.py:48: error: Argument 1 to "join" of "str" has incompatible type "Tuple[Optional[str], Optional[str]]"; expected "Iterable[str]"  [arg-type]
+ pandas/io/parsers/base_parser.py:1044: error: Incompatible types in assignment (expression has type "defaultdict[str, Union[ExtensionDtype, str, dtype[Any], Type[object], Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]]]]]", variable has type "Optional[Union[Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]], Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]]]]]")  [assignment]
+ pandas/io/parsers/base_parser.py:1045: error: Unused "type: ignore[arg-type, return-value]" comment
+ pandas/io/parsers/base_parser.py:1066: error: Value of type "Optional[Union[Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]], Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]]]]]" is not indexable  [index]
+ pandas/io/parsers/base_parser.py:1073: error: Value of type "Optional[Union[Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]], Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any], Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object]]]]]]" is not indexable  [index]

@JukkaL
Copy link
Collaborator Author

JukkaL commented Apr 8, 2022

I investigated most of the remaining errors. A few things look like real regressions, but since they don't seem to cause a lot of trouble, I'm going to merge this now and file issues (or create PRs) about them afterwards (next week).

@JukkaL JukkaL merged commit 756277c into master Apr 8, 2022
@JukkaL JukkaL deleted the sync-typeshed branch April 8, 2022 13:33
JukkaL added a commit to JukkaL/typeshed that referenced this pull request Apr 12, 2022
These were introduced in python#7329 and they cause false positives
in code that used to be accepted before. There was a false
positive in https://github.com/pycqa/pylint (encountered in
python/mypy#12321) and I also saw
false positives in an internal codebase.

I suggest not using literal types here, since they can be kind of
awkward to annotate in callers that don't pass a literal string.
Rrequiring callers to write annotations like
`Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="]` is not
very user friendly.
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.

None yet

4 participants