-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve operator.itemgetter.__call__
generic following mypy 1.11 fix
#13489
base: main
Are you sure you want to change the base?
Improve operator.itemgetter.__call__
generic following mypy 1.11 fix
#13489
Conversation
operator.itemgetter
generic following mypy 1.11 fix
…-fix' of https://github.com/Avasam/typeshed into Improve-operator.itemgetter-generic-following-mypy-1.11-fix
This comment has been minimized.
This comment has been minimized.
There seems to be a variance issue in the interaction with |
This comment has been minimized.
This comment has been minimized.
operator.itemgetter
generic following mypy 1.11 fixoperator.itemgetter.__call__
generic following mypy 1.11 fix
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/builders/gettext.py: note: In member "__iter__" of class "Catalog":
+ sphinx/builders/gettext.py:93:51: error: Argument "locations" to "Message" has incompatible type "list[str | int]"; expected "list[tuple[str, int]]" [arg-type]
+ sphinx/builders/gettext.py:93:68: error: Argument "uuids" to "Message" has incompatible type "list[str | int]"; expected "list[str]" [arg-type]
+ sphinx/ext/intersphinx/_load.py: note: In function "load_mappings":
+ sphinx/ext/intersphinx/_load.py:200:63: error: Argument "key" to "sorted" has incompatible type "itemgetter[tuple[int, int]]"; expected "Callable[[tuple[str, int, dict[str, dict[str, _InventoryItem]]]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ sphinx/ext/intersphinx/_load.py:200:63: note: "itemgetter[tuple[int, int]].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
rich (https://github.com/Textualize/rich)
+ rich/text.py:247: error: Argument "key" to "sort" of "list" has incompatible type "itemgetter[tuple[int, int]]"; expected "Callable[[tuple[int, bool, str | Style]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ rich/text.py:247: note: "itemgetter[tuple[int, int]].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
+ rich/columns.py:153: error: Argument 1 to "Constrain" has incompatible type "int | ConsoleRenderable | RichCast | str"; expected "ConsoleRenderable | RichCast | str" [arg-type]
+ rich/columns.py:160: error: Argument 1 has incompatible type "int | ConsoleRenderable | RichCast | str"; expected "ConsoleRenderable | RichCast | str" [arg-type]
+ rich/columns.py:170: error: Argument 1 has incompatible type "*list[int | ConsoleRenderable | RichCast | str | None]"; expected "ConsoleRenderable | RichCast | str | None" [arg-type]
+ rich/layout.py:362: error: Argument "key" to "sorted" has incompatible type "itemgetter[int]"; expected "Callable[[tuple[Layout, Region]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ rich/layout.py:362: note: "itemgetter[int].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
altair (https://github.com/vega/altair)
+ altair/utils/core.py:950: error: Key expression in dictionary comprehension has incompatible type "type[SchemaBase] | str"; expected type "str" [misc]
graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/type/validate.py:562: error: Argument 1 to "join" of "str" has incompatible type "map[str | GraphQLInputField]"; expected "Iterable[str]" [arg-type]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "inverted":
+ bidict/_iter.py:52:16: error: Argument 1 to "map" has incompatible type "itemgetter[tuple[int, int]]"; expected "Callable[[tuple[KT, VT]], tuple[VT, KT]]" [arg-type]
+ bidict/_iter.py:52:16: note: "itemgetter[tuple[int, int]].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
flake8 (https://github.com/pycqa/flake8)
+ src/flake8/checker.py:186: error: Argument "key" to "sort" of "list" has incompatible type "itemgetter[int]"; expected "Callable[[tuple[str, list[tuple[str, int, int, str, str | None]], dict[str, int]]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ src/flake8/checker.py:186: note: "itemgetter[int].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
+ src/flake8/checker.py:188: error: Argument "key" to "sort" of "list" has incompatible type "itemgetter[tuple[int, int]]"; expected "Callable[[tuple[str, int, int, str, str | None]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ src/flake8/checker.py:188: note: "itemgetter[tuple[int, int]].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
core (https://github.com/home-assistant/core)
+ homeassistant/util/language.py:194: error: Argument "key" to "sorted" has incompatible type "itemgetter[int]"; expected "Callable[[tuple[Dialect, tuple[float, float], str]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
+ homeassistant/util/language.py:194: note: "itemgetter[int].__call__" has type "Callable[[Arg(SupportsGetItem[Any, _T], 'obj')], _T]"
|
I'm also not sure why this doesn't work. Still I think for now it's best to postpone (i.e. close) this PR, until this works better. |
If you close this, please make it an issue. The behaviour here feels unexpected and seems worth investigating. |
python/mypy#14032 has been fixed in mypy 1.11.0 (I didn't go as far as to search for the exact commit).
This updates
operator.itemgetter
to include a change I originally wanted to do in #9117, removes the outdated comment, and adds a regression test.