Skip to content

Consider property access from class objects (now for real) #18969

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Collaborator

Supersedes #18504. Fixes #16090. Fixes #8085.

This PR extracts first subset of changes initially submitted in #18504. It is known to make handling of unsupported constructs (property setter overrides and non-adjacent property components handling) worse, those problems will be addressed in a follow-up PR to make this one better scoped.

Please DO NOT MERGE if a release is planned soon, override regressions may be problematic for some users.

Copy link
Contributor

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

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/groupby/indexing.py:248: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/series.py:361: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/indexing.py:1219: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexing.py:1570: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexing.py:2526: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexing.py:2570: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexes/datetimelike.py:138: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexes/datetimelike.py:155: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexes/datetimelike.py:526: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]
+ pandas/core/indexes/base.py:4963: error: Argument 1 to "doc" has incompatible type "property"; expected "str | Callable[..., Any] | None"  [arg-type]

xarray (https://github.com/pydata/xarray)
+ xarray/core/variable.py:2658: error: Unused "type: ignore" comment  [unused-ignore]
+ xarray/core/variable.py:2665: error: Unused "type: ignore" comment  [unused-ignore]

spark (https://github.com/apache/spark)
+ python/pyspark/instrumentation_utils.py:83: error: Unused "type: ignore" comment  [unused-ignore]

ppb-vector (https://github.com/ppb/ppb-vector)
+ tests/utils.py:86: error: Unused "type: ignore" comment  [unused-ignore]

pwndbg (https://github.com/pwndbg/pwndbg)
- pwndbg/aglib/heap/structs.py:175: error: Invalid index type "Any | type[Any] | _CField[Any, Any, Any] | overloaded function" for "dict[type[object], Type]"; expected type "type[object]"  [index]
+ pwndbg/aglib/heap/structs.py:175: error: Invalid index type "Any | type[Any] | _CField[Any, Any, Any] | property" for "dict[type[object], Type]"; expected type "type[object]"  [index]
- pwndbg/aglib/heap/structs.py:177: error: Argument 1 to "array" of "Type" has incompatible type "Any | _CField[Any, Any, Any] | overloaded function"; expected "int"  [arg-type]
+ pwndbg/aglib/heap/structs.py:177: error: Argument 1 to "array" of "Type" has incompatible type "Any | _CField[Any, Any, Any] | property"; expected "int"  [arg-type]
- pwndbg/aglib/heap/structs.py:206: error: Invalid index type "Any | type[Any] | _CField[Any, Any, Any] | overloaded function" for "dict[type[object], Type]"; expected type "type[object]"  [index]
+ pwndbg/aglib/heap/structs.py:206: error: Invalid index type "Any | type[Any] | _CField[Any, Any, Any] | property" for "dict[type[object], Type]"; expected type "type[object]"  [index]
- pwndbg/aglib/heap/structs.py:207: error: Argument 1 to "array" of "Type" has incompatible type "Any | _CField[Any, Any, Any] | overloaded function"; expected "int"  [arg-type]
+ pwndbg/aglib/heap/structs.py:207: error: Argument 1 to "array" of "Type" has incompatible type "Any | _CField[Any, Any, Any] | property"; expected "int"  [arg-type]

core (https://github.com/home-assistant/core)
+ homeassistant/components/mqtt/sensor.py:411: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/mqtt/sensor.py:411: error: "None" not callable  [misc]
+ homeassistant/components/mqtt/sensor.py:411: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/mqtt/binary_sensor.py:257: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/mqtt/binary_sensor.py:257: error: "None" not callable  [misc]
+ homeassistant/components/mqtt/binary_sensor.py:257: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/template/image.py:140: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/template/image.py:140: error: "None" not callable  [misc]
+ homeassistant/components/template/image.py:140: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/template/image.py:181: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/template/image.py:181: error: "None" not callable  [misc]
+ homeassistant/components/template/image.py:181: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/template/image.py:182: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/template/image.py:182: error: "None" not callable  [misc]
+ homeassistant/components/template/image.py:182: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/rest/sensor.py:150: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/rest/sensor.py:150: error: "None" not callable  [misc]
+ homeassistant/components/rest/sensor.py:150: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/rest/sensor.py:151: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/rest/sensor.py:151: error: "None" not callable  [misc]
+ homeassistant/components/rest/sensor.py:151: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/rest/binary_sensor.py:141: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/rest/binary_sensor.py:141: error: "None" not callable  [misc]
+ homeassistant/components/rest/binary_sensor.py:141: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/rest/binary_sensor.py:142: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/rest/binary_sensor.py:142: error: "None" not callable  [misc]
+ homeassistant/components/rest/binary_sensor.py:142: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/scrape/sensor.py:237: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/scrape/sensor.py:237: error: "None" not callable  [misc]
+ homeassistant/components/scrape/sensor.py:237: note: Error code "misc" not covered by "type: ignore" comment
+ homeassistant/components/scrape/sensor.py:238: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/components/scrape/sensor.py:238: error: "None" not callable  [misc]
+ homeassistant/components/scrape/sensor.py:238: note: Error code "misc" not covered by "type: ignore" comment

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/operations/udf.py:155: error: Argument 2 to "type" has incompatible type "tuple[Callable[[_UDF], type[B]]]"; expected "tuple[type, ...]"  [arg-type]
+ ibis/expr/operations/udf.py:155: error: Argument 2 to "type" has incompatible type "tuple[property]"; expected "tuple[type, ...]"  [arg-type]
- ibis/backends/tests/base.py:186: error: "Callable[[BackendTest], Iterable[str]]" has no attribute "__iter__" (not iterable)  [attr-defined]
+ ibis/backends/tests/base.py:186: error: "property" has no attribute "__iter__" (not iterable)  [attr-defined]

discord.py (https://github.com/Rapptz/discord.py)
- discord/member.py:492: error: "Callable[[Member], Status]" has no attribute "setter"  [attr-defined]

@sterliakov
Copy link
Collaborator Author

OK, the primer matches what I saw in the original PR modulo disappeared errors related to non-adjacent property setters and property setter overrides.

@sterliakov sterliakov marked this pull request as ready for review April 26, 2025 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant