-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix UnionType.__or__
and add UnionType.__getitem__
#14687
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
Open
KotlinIsland
wants to merge
1
commit into
python:main
Choose a base branch
from
KotlinIsland:UnionType
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff from mypy_primer, showing the effect of this PR on open source code: freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/optimize/hyperopt/hyperopt_optimizer.py:405: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
xarray (https://github.com/pydata/xarray)
+ xarray/namedarray/core.py: note: In member "chunk" of class "NamedArray":
+ xarray/namedarray/core.py:813: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/variable.py: note: In member "_in_memory" of class "Variable":
+ xarray/core/variable.py:435: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/variable.py: note: At top level:
+ xarray/structure/alignment.py: note: In function "deep_align":
+ xarray/structure/alignment.py:993: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/structure/merge.py: note: In function "merge":
+ xarray/structure/merge.py:1012: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/resample_cftime.py: note: In member "__init__" of class "CFTimeGrouper":
+ xarray/core/resample_cftime.py:105: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/resample_cftime.py: note: In function "_adjust_bin_edges":
+ xarray/core/resample_cftime.py:286: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/dataset.py: note: In member "_validate_indexers" of class "Dataset":
+ xarray/core/dataset.py:2622: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/dataarray.py: note: In member "chunk" of class "DataArray":
+ xarray/core/dataarray.py:1474: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/core/dataarray.py: note: At top level:
+ xarray/core/dataarray.py: note: In member "_binary_op" of class "DataArray":
+ xarray/core/dataarray.py:4885: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/tests/test_variable.py: note: In function "test_datetime_conversion":
+ xarray/tests/test_variable.py:3131: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/tests/test_cftime_offsets.py: note: In function "test_rollforward":
+ xarray/tests/test_cftime_offsets.py:1004: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/tests/test_cftime_offsets.py:1006: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/tests/test_cftime_offsets.py: note: In function "test_rollback":
+ xarray/tests/test_cftime_offsets.py:1055: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ xarray/tests/test_cftime_offsets.py:1057: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/pycode/ast.py: note: In member "visit_Constant" of class "_UnparseVisitor":
+ sphinx/pycode/ast.py:137:37: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/util/_serialise.py: note: In function "stable_hash":
+ sphinx/util/_serialise.py:22:24: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/util/_serialise.py: note: In function "_stable_str_prep":
+ sphinx/util/_serialise.py:45:24: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/util/nodes.py: note: In function "apply_source_workaround":
+ sphinx/util/nodes.py:201:13: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/util/nodes.py: note: At top level:
+ sphinx/transforms/__init__.py: note: In member "apply" of class "ApplySourceWorkaround":
+ sphinx/transforms/__init__.py:244:33: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/config.py: note: In function "is_serializable":
+ sphinx/config.py:68:26: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/config.py: note: In member "match" of class "ENUM":
+ sphinx/config.py:92:30: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/ext/autodoc/preserve_defaults.py: note: In function "_get_arguments_inner":
+ sphinx/ext/autodoc/preserve_defaults.py:109:22: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/writers/texinfo.py: note: In member "visit_title" of class "TexinfoTranslator":
+ sphinx/writers/texinfo.py:641:31: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ sphinx/ext/apidoc/_extension.py: note: In function "_check_collection_of_strings":
+ sphinx/ext/apidoc/_extension.py:246:37: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
archinstall (https://github.com/archlinux/archinstall)
+ archinstall/lib/general.py:71: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
core (https://github.com/home-assistant/core)
+ homeassistant/components/tplink/sensor.py:322: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
attrs (https://github.com/python-attrs/attrs)
+ tests/typing_example.py:257: error: Argument 1 to "instance_of" has incompatible type "UnionType | <typing special form> | type"; expected "type[Never]" [arg-type]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/commands/slash.py:378: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/slash.py:1642: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/message.py:106: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/message.py:163: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/message.py:234: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/menu.py:173: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/menu.py:300: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ tanjun/commands/menu.py:520: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
egglog-python (https://github.com/egraphs-good/egglog-python)
+ python/egglog/egraph_state.py:643: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ python/egglog/runtime.py:247: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
zulip (https://github.com/zulip/zulip)
+ zerver/lib/validator.py:596: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ zerver/openapi/markdown_extension.py:257: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ zerver/middleware.py:402: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
artigraph (https://github.com/artigraph/artigraph)
+ src/arti/internal/type_hints.py:146: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ src/arti/internal/type_hints.py:148: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ src/arti/internal/type_hints.py:168: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
+ src/arti/types/bigquery.py:266: error: Argument 2 to "isinstance" has incompatible type "UnionType | <typing special form> | type"; expected "_ClassInfo" [arg-type]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
UnionType.__or__
/__ror__
this is rather unfortunate due to
NotImplemented
semantics, which are underspecified at this time, very relevant:Any
in righthand-able operators to beNotImplemented
lenient DetachHead/basedpyright#1465to work around this we add the known case
_SpecialForm
to the return typeand
to work around this we add the special case
type
to the return type, in the case of "unions are invalid as return types", then i would suggestUnionType | Any
UnionType.__getitem__
it has
__getitem__
, the design was inspired by_SpecialForm.__getitem__
but suggestions are appreciated