GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ignore promotions when simplifying unions by ilevkivskyi · Pull Request #13781 · python/mypy

Conversation

@ilevkivskyi

@ilevkivskyi ilevkivskyi commented Sep 30, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes #13760
Fixes #6060
Fixes #12824

This is a right thing to do, but let's what mypy_primer will be. This also required re-applying #6181 (which is also a right thing to do) otherwise some tests fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ilevkivskyi
Ignore promotions when simplifying unions
525f050
@ilevkivskyi
ilevkivskyi requested review from JukkaL and hauntsaninja September 30, 2022 16:58
@github-actions

github-actions Bot commented Sep 30, 2022

Copy link
Copy Markdown
Contributor

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

operator (https://github.com/canonical/operator)
- ops/model.py:2198: error: Incompatible types in assignment (expression has type "Iterable[str]", variable has type "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2198: error: Incompatible types in assignment (expression has type "Iterable[str]", variable has type "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2199: error: Item "int" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2199: error: Item "float" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2199: error: Item "float" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2199: error: Item "Dict[str, JsonObject]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2199: error: Item "Dict[str, JsonObject]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2199: error: Item "List[JsonObject]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2199: error: Item "List[JsonObject]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2199: error: Item "Tuple[JsonObject, ...]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2199: error: Item "Tuple[JsonObject, ...]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2199: error: Item "int" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2199: error: Item "float" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
+ ops/model.py:2199: error: Item "float" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2199: error: Item "None" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
+ ops/model.py:2199: error: Item "None" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2354: error: Incompatible types in assignment (expression has type "Dict[str, Dict[str, str]]", variable has type "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2354: error: Incompatible types in assignment (expression has type "Dict[str, Dict[str, str]]", variable has type "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
- ops/model.py:2355: error: Value of type "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" is not indexable  [index]
+ ops/model.py:2355: error: Value of type "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" is not indexable  [index]
- ops/model.py:2355: error: Invalid index type "str" for "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]"; expected type "Union[SupportsIndex, slice]"  [index]
+ ops/model.py:2355: error: Invalid index type "str" for "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]"; expected type "Union[SupportsIndex, slice]"  [index]
- ops/model.py:2356: error: Value of type "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" is not indexable  [index]
+ ops/model.py:2356: error: Value of type "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" is not indexable  [index]
- ops/model.py:2356: error: Incompatible types (expression has type "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]", TypedDict item "status" has type "str")  [typeddict-item]
+ ops/model.py:2356: error: Incompatible types (expression has type "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]", TypedDict item "status" has type "str")  [typeddict-item]
- ops/model.py:2356: error: Invalid index type "str" for "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]"; expected type "Union[SupportsIndex, slice]"  [index]
+ ops/model.py:2356: error: Invalid index type "str" for "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]"; expected type "Union[SupportsIndex, slice]"  [index]
- ops/model.py:2357: error: Value of type "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" is not indexable  [index]
+ ops/model.py:2357: error: Value of type "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" is not indexable  [index]
- ops/model.py:2357: error: Incompatible types (expression has type "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]", TypedDict item "message" has type "str")  [typeddict-item]
+ ops/model.py:2357: error: Incompatible types (expression has type "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]", TypedDict item "message" has type "str")  [typeddict-item]
- ops/model.py:2357: error: Invalid index type "str" for "Union[str, Any, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]"; expected type "Union[SupportsIndex, slice]"  [index]
+ ops/model.py:2357: error: Invalid index type "str" for "Union[str, Any, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]"; expected type "Union[SupportsIndex, slice]"  [index]
- ops/model.py:2376: error: Incompatible types in assignment (expression has type "List[str]", variable has type "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2376: error: Incompatible types in assignment (expression has type "List[str]", variable has type "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2377: error: Item "int" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2377: error: Item "float" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2377: error: Item "float" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2377: error: Item "Dict[str, JsonObject]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2377: error: Item "Dict[str, JsonObject]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2377: error: Item "List[JsonObject]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2377: error: Item "List[JsonObject]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
- ops/model.py:2377: error: Item "Tuple[JsonObject, ...]" of "Union[Any, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2377: error: Item "Tuple[JsonObject, ...]" of "Union[Any, int, float, str, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...]]" has no attribute "split"  [union-attr]
+ ops/model.py:2377: error: Item "int" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2377: error: Item "float" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
+ ops/model.py:2377: error: Item "float" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2377: error: Item "None" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
+ ops/model.py:2377: error: Item "None" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "__iter__" (not iterable)  [union-attr]
- ops/model.py:2491: error: Incompatible types in assignment (expression has type "Dict[str, List[str]]", variable has type "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
+ ops/model.py:2491: error: Incompatible types in assignment (expression has type "Dict[str, List[str]]", variable has type "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]")  [assignment]
- ops/model.py:2493: error: Item "str" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "str" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "int" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
- ops/model.py:2493: error: Item "float" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "float" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
- ops/model.py:2493: error: Item "List[JsonObject]" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "List[JsonObject]" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
- ops/model.py:2493: error: Item "Tuple[JsonObject, ...]" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "Tuple[JsonObject, ...]" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
- ops/model.py:2493: error: Item "None" of "Union[str, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
+ ops/model.py:2493: error: Item "None" of "Union[str, int, float, Dict[str, JsonObject], List[JsonObject], Tuple[JsonObject, ...], None]" has no attribute "get"  [union-attr]
- ops/model.py:2493: error: Argument 1 to "len" has incompatible type "Union[Any, float, Sized]"; expected "Sized"  [arg-type]
+ ops/model.py:2493: error: Argument 1 to "len" has incompatible type "Union[Any, int, float, Sized]"; expected "Sized"  [arg-type]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
- tests/test_resampler.py:277: error: Expression is of type "Union[str, bytes, date, timedelta, complex]", not "Union[str, bytes, date, datetime, timedelta, bool, int, float, complex, Timestamp, Timedelta]"  [assert-type]

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/types/enum.py:40: error: Unused "type: ignore" comment

discord.py (https://github.com/Rapptz/discord.py)
- discord/backoff.py:75: error: Incompatible types in assignment (expression has type "function", variable has type "Callable[..., float]")  [assignment]
+ discord/backoff.py:75: error: Incompatible types in assignment (expression has type "function", variable has type "Callable[..., Union[int, float]]")  [assignment]
- discord/scheduled_event.py:160: note:     def __new__(cls, Union[str, bytes, array[Any], mmap, _CData, PickleBuffer, SupportsInt, SupportsIndex, SupportsTrunc] = ..., /) -> int
+ discord/scheduled_event.py:160: note:     def __new__(cls, Union[str, bytes, bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer, SupportsInt, SupportsIndex, SupportsTrunc] = ..., /) -> int
- discord/scheduled_event.py:160: note:     def __new__(cls, Union[str, bytes], /, base: SupportsIndex) -> int
+ discord/scheduled_event.py:160: note:     def __new__(cls, Union[str, bytes, bytearray], /, base: SupportsIndex) -> int
- discord/app_commands/models.py:205: note:     def __new__(cls, Union[str, bytes, array[Any], mmap, _CData, PickleBuffer, SupportsInt, SupportsIndex, SupportsTrunc] = ..., /) -> int
+ discord/app_commands/models.py:205: note:     def __new__(cls, Union[str, bytes, bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer, SupportsInt, SupportsIndex, SupportsTrunc] = ..., /) -> int
- discord/app_commands/models.py:205: note:     def __new__(cls, Union[str, bytes], /, base: SupportsIndex) -> int
+ discord/app_commands/models.py:205: note:     def __new__(cls, Union[str, bytes, bytearray], /, base: SupportsIndex) -> int
- discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, float]", variable has type "str")  [assignment]
+ discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, int, float]", variable has type "str")  [assignment]
- discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, float]", variable has type "int")  [assignment]
+ discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, int, float]", variable has type "int")  [assignment]
- discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, float]", variable has type "float")  [assignment]
+ discord/app_commands/models.py:448: error: Incompatible types in assignment (expression has type "Union[str, int, float]", variable has type "float")  [assignment]
- discord/app_commands/models.py:505: error: Incompatible types in assignment (expression has type "Dict[str, str]", target has type "Union[str, float]")  [assignment]
+ discord/app_commands/models.py:505: error: Incompatible types in assignment (expression has type "Dict[str, str]", target has type "Union[str, int, float]")  [assignment]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "str"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "str"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Iterable[str]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Iterable[str]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "float"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "float"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[float]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[float]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "bool"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "bool"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[BasicAuth]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[BasicAuth]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[str]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[str]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[Mapping[str, str]]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[Mapping[str, str]]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[str, URL, None]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Union[str, URL, None]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[SSLContext, bool, None, Fingerprint]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Union[SSLContext, bool, None, Fingerprint]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bool]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[bool]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bytes]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[bytes]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[SSLContext]"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "Optional[SSLContext]"  [arg-type]
- discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "int"  [arg-type]
+ discord/http.py:536: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, int, BasicAuth, None, str]]"; expected "int"  [arg-type]
- discord/app_commands/transformers.py:147: error: Incompatible types in assignment (expression has type "float", target has type "Union[str, int]")  [assignment]
+ discord/app_commands/transformers.py:147: error: Incompatible types in assignment (expression has type "Union[int, float]", target has type "Union[str, int]")  [assignment]
- discord/app_commands/transformers.py:149: error: Incompatible types in assignment (expression has type "float", target has type "Union[str, int]")  [assignment]
+ discord/app_commands/transformers.py:149: error: Incompatible types in assignment (expression has type "Union[int, float]", target has type "Union[str, int]")  [assignment]

streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/metric.py: note: In member "parse_delta" of class "MetricMixin":
+ lib/streamlit/elements/metric.py:163:25: error: Subclass of "float" and "int" cannot exist: would have incompatible method signatures  [unreachable]

pylint (https://github.com/pycqa/pylint)
+ pylint/checkers/__init__.py:130: error: Argument 1 to "extend" of "list" has incompatible type "Tuple[str, str, str, Union[str, int]]"; expected "Iterable[str]"  [arg-type]

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

core (https://github.com/home-assistant/core)
- homeassistant/components/deconz/sensor.py:110: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:110: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:117: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:117: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:128: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:128: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:137: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:137: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:145: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:145: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:151: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:151: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:160: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:160: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:169: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:169: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:178: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:178: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:187: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:187: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:204: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:204: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
- homeassistant/components/deconz/sensor.py:215: error: Returning Any from function declared to return "Union[datetime, None, str, float]"  [no-any-return]
+ homeassistant/components/deconz/sensor.py:215: error: Returning Any from function declared to return "Union[datetime, None, str, int, float]"  [no-any-return]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi

ilevkivskyi commented Sep 30, 2022

Copy link
Copy Markdown
Member Author

Few new errors are actually valid (and maybe actually catching actual bugs), except the one in streamlit. I will check if this is something new, or it was exposed by this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi

ilevkivskyi commented Sep 30, 2022

Copy link
Copy Markdown
Member Author

Yes, it looks like it is caused by this PR, a simple repro:

x: float
if isinstance(x, int) or isinstance(x, float):
    pass

it worked before, but fails with this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi

ilevkivskyi commented Sep 30, 2022

Copy link
Copy Markdown
Member Author

Oh wait, it only happens with a --warn-unreachable flag. So it is in some sense correct, it warns that the first isinstance() will be always false.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi

ilevkivskyi commented Sep 30, 2022

Copy link
Copy Markdown
Member Author

This is ready for review then.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi ilevkivskyi mentioned this pull request Sep 30, 2022
mypy 0.981 does not simplify unions for assert_type #13760
Closed
hauntsaninja
hauntsaninja approved these changes Sep 30, 2022
View reviewed changes
@ilevkivskyi

ilevkivskyi commented Oct 2, 2022

Copy link
Copy Markdown
Member Author

@JukkaL if you have no objections, I will merge this latter today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi
ilevkivskyi merged commit 08c566c into python:master Oct 3, 2022
@ilevkivskyi
ilevkivskyi deleted the try-no-promote-union branch October 3, 2022 11:57
@Dr-Irv Dr-Irv mentioned this pull request Oct 3, 2022
mypy 0.981 compatibility pandas-dev/pandas-stubs#336
Closed
@Dr-Irv

Dr-Irv commented Oct 3, 2022

Copy link
Copy Markdown

@ilevkivskyi Any sense as to when this fix will be released?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja

hauntsaninja commented Oct 3, 2022

Copy link
Copy Markdown
Collaborator

As part of 0.990, probably in a month or so

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Dr-Irv Dr-Irv mentioned this pull request Nov 2, 2022
(🎁) update mypy to 0.982 pandas-dev/pandas-stubs#406
Closed
@hauntsaninja hauntsaninja mentioned this pull request Nov 7, 2022
0.990 regression with implicit complex/int promotion #14030
Closed
@AlexWaygood AlexWaygood mentioned this pull request Nov 8, 2022
Add flake8-pyi hauntsaninja/mypy_primer#52
Merged
@hauntsaninja hauntsaninja mentioned this pull request Dec 22, 2022
Improve duck type compatibility of int with float python/cpython#100268
Closed
@hauntsaninja hauntsaninja mentioned this pull request Aug 13, 2023
Type narrowing fails when narrowing Optional NewType #11995
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja approved these changes
@JukkaL JukkaL Awaiting requested review from JukkaL

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

mypy 0.981 does not simplify unions for assert_type Invalid handling type narrowing with inf/float due to duck typing mypy fails to narrow Union[float,int] to float after isinstance(x, float)

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@ilevkivskyi @Dr-Irv @hauntsaninja
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.