Repository navigation
fix special-case NotImplementedType in binop signatures to match runtime semantics #1129 - #5476
asukaminato0721 wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
|
This pull request has been imported. If you are a Meta employee, you can view this in D128884121. (Because this pull request was imported automatically, there will not be any future comments.) |
This comment has been minimized.
This comment has been minimized.
stroxler
left a comment
There was a problem hiding this comment.
Thanks! A fresh round of code review caught a few more concerns (not that surprising, this is a tricky change)
-
Valid SymPy operations gain errors. Bundled stubs incorrectly annotate operations such as
DomainMatrixaddition/subtraction andPolyElementmultiplication as returning onlyNotImplementedType. The PR turns those declarations intounsupported-operationerrors under the default preset. Confirmed absent at the base and valid at runtime. Fix the bundled declarations in a prerequisite change. -
Same-type operands incorrectly reach
__radd__. When__add__declines,Same() + Same()can inferstrfrom__radd__, although Python never calls it for identical runtime classes and raisesTypeError. The corresponding+=path has the same problem. -
Inplace fallback uses the wrong order. After
__iadd__declines, a proper subclass’s overridden__radd__must precede the left operand’s__add__. The current fixed ordering infersintwhere Python producesstr. These dispatch gaps predate the PR but become exposed by its new decline handling.
|
cc @stroxler microsoft/python-type-stubs#407 after some debugging. So this pr kind of "blocked" by upstream now. |
0dd0e0e to
741db26
Compare
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +22 new errors, -10 fixed errors
By preset: +12/-1 (default), +12/-1 (strict)
Projects with changes (9):
openlibrary: +4 -1
manticore: +0 -1
static-frame: +3 -4
pandas-stubs: +8 -0
pandas: +1 -1
trio: +1 -1
dd-trace-py: +1 -0
jinja: +2 -2
xarray: +2 -0
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
openlibrary (https://github.com/internetarchive/openlibrary)
- ERROR openlibrary/book_providers.py:596:92-155: Implicit conversion of `Acquisition | NotImplementedType | Unknown | None` to `bool` is not allowed [implicit-bool]
+ ERROR openlibrary/book_providers.py:596:92-155: Implicit conversion of `Acquisition | Unknown | None` to `bool` is not allowed [implicit-bool]
+ ERROR openlibrary/solr/updater/edition.py:353:16-63: Returning implicit Any from function declared to return "bool" [no-any-return-implicit]
+ ERROR openlibrary/solr/updater/edition.py:526:16-75: Returning implicit Any from function declared to return "bool" [no-any-return-implicit]
+ ERROR openlibrary/solr/updater/edition.py:530:16-78: Returning implicit Any from function declared to return "bool" [no-any-return-implicit]
manticore (https://github.com/trailofbits/manticore)
- ERROR manticore/native/manticore.py:82:24-43: `!=` is not supported between `Module[manticore.platforms]` and `Module[manticore.platforms]` [unsupported-operation]
static-frame (https://github.com/static-frame/static-frame)
- ERROR static_frame/test/unit/test_index.py:527:26-37: The type of this argument is an explicit `Any` [explicit-any-use]
+ ERROR static_frame/test/unit/test_index.py:527:26-37: `@` is not supported between `Index` and `Index` [unsupported-operation]
- ERROR static_frame/test/unit/test_index_hierarchy.py:3172:38-44: The type of attribute `tolist` is an explicit `Any` [explicit-any-use]
+ ERROR static_frame/test/unit/test_index_hierarchy.py:3172:27-36: `@` is not supported between `IndexHierarchy` and `IndexHierarchy` [unsupported-operation]
- ERROR static_frame/test/unit/test_index_hierarchy.py:3212:14-23: The type of `a1` is an explicit `Any` [explicit-any-use]
+ ERROR static_frame/test/unit/test_index_hierarchy.py:3212:14-23: `@` is not supported between `IndexHierarchy` and `IndexHierarchy` [unsupported-operation]
- ERROR static_frame/test/unit/test_index_hierarchy.py:3214:29-35: The type of attribute `tolist` is an explicit `Any` [explicit-any-use]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ ERROR tests/indexes/float/test_floordiv.py:127:22-52: assert_type(Unknown, Index[float]) failed [assert-type]
+ ERROR tests/indexes/float/test_floordiv.py:127:23-32: `//` is not supported between `Index[bool]` and `Index[float]` [unsupported-operation]
+ ERROR tests/indexes/str/test_mul.py:134:22-49: assert_type(Unknown, Index[str]) failed [assert-type]
+ ERROR tests/indexes/str/test_mul.py:134:23-31: `*` is not supported between `Index[int]` and `Index[str]` [unsupported-operation]
+ ERROR tests/series/float/test_floordiv.py:228:22-53: assert_type(Unknown, Series[float]) failed [assert-type]
+ ERROR tests/series/float/test_floordiv.py:228:23-32: `//` is not supported between `Series[bool]` and `Series[float]` [unsupported-operation]
+ ERROR tests/series/str/test_mul.py:234:22-50: assert_type(Unknown, Series[str]) failed [assert-type]
+ ERROR tests/series/str/test_mul.py:234:23-31: `*` is not supported between `Series[int]` and `Series[str]` [unsupported-operation]
pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/arrays/_arrow_string_mixins.py:202:12-33: Implicit conversion of `int` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/arrays/_arrow_string_mixins.py:202:12-33: Implicit conversion of `RegexFlag | int` to `bool` is not allowed [implicit-bool]
trio (https://github.com/python-trio/trio)
- ERROR src/trio/_core/_io_windows.py:685:16-21: Implicit conversion of `int` to `bool` is not allowed [implicit-bool]
+ ERROR src/trio/_core/_io_windows.py:685:16-21: Implicit conversion of `AFDPollFlags | int` to `bool` is not allowed [implicit-bool]
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ERROR ddtrace/vendor/jsonpath/parse.py:746:13-747:48: Fixpoint iteration did not converge. Inferred type `Literal[0] | RegexFlag`. Adding annotations may help. [non-convergent-recursion]
jinja (https://github.com/pallets/jinja)
- ERROR src/jinja2/filters.py:858:12-17: Implicit conversion of `list[str]` to `bool` is not allowed [implicit-bool]
+ ERROR src/jinja2/filters.py:858:12-17: Implicit conversion of `list[Markup] | list[str]` to `bool` is not allowed [implicit-bool]
- ERROR src/jinja2/filters.py:860:37-41: Implicit conversion of `str` to `bool` is not allowed [implicit-bool]
+ ERROR src/jinja2/filters.py:860:37-41: Implicit conversion of `Markup | str` to `bool` is not allowed [implicit-bool]
xarray (https://github.com/pydata/xarray)
+ ERROR xarray/core/resample_cftime.py:459:23-34: The type of `lresult` is unknown because it comes from an error [unknown-from-error]
+ ERROR xarray/tests/test_cftime_offsets.py:558:14-29: The type of `result` is unknown; it is inferred as an implicit `Any` [unknown-variable-type] |
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #1129
continue of #2677
Test Plan