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

Merged
merged 4 commits into from
Feb 3, 2023
Merged

Sync typeshed #14598

merged 4 commits into from
Feb 3, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Feb 3, 2023

Source commit: python/typeshed@37a180e

NOTE: "rebase and merge" is much more preferable than "squash and merge" for this PR. These two commits no longer apply cleanly, which caused the automated workflow to fail a few days ago (hence this manual PR):

mypy/misc/sync-typeshed.py

Lines 188 to 189 in 11739e4

"780534b13722b7b0422178c049a1cbbf4ea4255b", # LiteralString reverts
"5319fa34a8004c1568bb6f032a07b8b14cc95bed", # sum reverts

If we use "rebase and merge" for this PR, we will be able to update those lines in the script with the second and third commits from this PR, meaning we can go back to automated typeshed syncs in the future.

AlexWaygood and others added 4 commits February 3, 2023 19:25
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)
Since the plugin provides superior type checking:
python#13987 (comment)
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for doing this!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

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

pip (https://github.com/pypa/pip)
+ src/pip/_internal/metadata/_json.py:67: error: Item "None" of "Optional[List[Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
+ src/pip/_internal/metadata/_json.py:70: error: Argument 1 to "sanitise_header" has incompatible type "Optional[Any]"; expected "Union[Header, str]"  [arg-type]

sympy (https://github.com/sympy/sympy)
+ sympy/parsing/sympy_parser.py:1075: error: Incompatible types in assignment (expression has type "CodeType", variable has type "str")  [assignment]

porcupine (https://github.com/Akuli/porcupine)
+ porcupine/utils.py:408: error: No overload variant of "asdict" matches argument type "EventDataclass"  [call-overload]
+ porcupine/utils.py:408: note: Possible overload variants:
+ porcupine/utils.py:408: note:     def asdict(obj: _DataclassInstance) -> Dict[str, Any]
+ porcupine/utils.py:408: note:     def [_T] asdict(obj: _DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T

jinja (https://github.com/pallets/jinja)
+ src/jinja2/environment.py:706: error: Unused "type: ignore" comment

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:749: error: Value of type "Optional[List[Tuple[str, str]]]" is not indexable  [index]

core (https://github.com/home-assistant/core)
+ homeassistant/components/p1_monitor/diagnostics.py:45: error: Argument 1 to "asdict" has incompatible type "Optional[Any]"; expected "_DataclassInstance"  [arg-type]
+ homeassistant/components/zha/core/gateway.py:505: error: Argument 1 to "addFilter" of "Filterer" has incompatible type "Union[Filter, Callable[[LogRecord], int]]"; expected "Union[Filter, Callable[[LogRecord], bool]]"  [arg-type]
+ homeassistant/components/zha/core/gateway.py:520: error: Argument 1 to "removeFilter" of "Filterer" has incompatible type "Union[Filter, Callable[[LogRecord], int]]"; expected "Union[Filter, Callable[[LogRecord], bool]]"  [arg-type]
+ homeassistant/components/zwave_js/discovery.py:78: error: No overload variant of "asdict" matches argument type "DataclassMustHaveAtLeastOne"  [call-overload]
+ homeassistant/components/zwave_js/discovery.py:78: note: Possible overload variants:
+ homeassistant/components/zwave_js/discovery.py:78: note:     def asdict(obj: _DataclassInstance) -> Dict[str, Any]
+ homeassistant/components/zwave_js/discovery.py:78: note:     def [_T] asdict(obj: _DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T

urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:269: error: Signature of "setdefault" incompatible with supertype "MutableMapping"  [override]
+ src/urllib3/_collections.py:269: note:      Superclass:
+ src/urllib3/_collections.py:269: note:          @overload
+ src/urllib3/_collections.py:269: note:          def setdefault(self, str, None = ..., /) -> Optional[str]
+ src/urllib3/_collections.py:269: note:          @overload
+ src/urllib3/_collections.py:269: note:          def setdefault(self, str, str, /) -> str
+ src/urllib3/_collections.py:269: note:      Subclass:
+ src/urllib3/_collections.py:269: note:          def setdefault(self, key: str, default: str = ...) -> str

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1862: error: Incompatible types in assignment (expression has type "Union[Type[Any], Callable[P, R], Callable[..., Any]]", variable has type overloaded function)  [assignment]
+ src/hydra_zen/structured_configs/_implementations.py:1862: error: Incompatible types in assignment (expression has type "Union[Type[_DataclassInstance], Type[Any], Callable[P, R], Callable[..., Any], DataClass_]", variable has type overloaded function)  [assignment]

@hauntsaninja
Copy link
Collaborator

pip and aiohttp: python/typeshed#9620
jinja and sympy: python/typeshed#9567
porcupine, hydra-zen, xarray-dataclasses, home-assistant: python/typeshed#9362
urllib3: python/typeshed#9612

@hauntsaninja hauntsaninja merged commit fe40f81 into python:master Feb 3, 2023
@AlexWaygood AlexWaygood deleted the mypybot/sync-typeshed branch February 3, 2023 20:38
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

2 participants