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

added hashability requirement to set/frozenset typevar #11854

Closed

Conversation

randolf-scholz
Copy link
Contributor

@randolf-scholz randolf-scholz commented May 2, 2024

Previous attempts were deferred because they caused a lot of noise in 3rd party libraries. But they often attempted to also add the hashability requirement to mapping types such as dict.

This patch only affects the built-in set and frozenset to keep the amount of possible conflicts minimal.

Partial fix for #9571

Related: microsoft/pyright#7824

The standard mypy test suite only reports 6 errors for requests-oauthlib, all other libraries pass.

This comment has been minimized.

@randolf-scholz
Copy link
Contributor Author

Blocker: type not hashable: python/mypy#11470, #4638

Copy link
Contributor

github-actions bot commented May 2, 2024

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

pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/v1/typing.py:558: error: Value of type variable "_H" of "set" cannot be "type[Any] | str | ForwardRef"  [type-var]
+ pydantic/v1/utils.py:86: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ pydantic/v1/utils.py:109: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ pydantic/_internal/_utils.py:28: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ pydantic/_internal/_utils.py:51: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]

manticore (https://github.com/trailofbits/manticore)
+ tests/other/test_smtlibv2.py:243: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ tests/other/test_smtlibv2.py:244: error: Value of type variable "_H2" of "union" of "set" cannot be "Any | type[Any]"  [type-var]
+ tests/other/test_smtlibv2.py:245: error: Value of type variable "_H2" of "union" of "set" cannot be "type[Any]"  [type-var]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/computation/expr.py:182: error: Value of type variable "_H_co" of "frozenset" cannot be "type[AST]"  [type-var]
+ pandas/core/arraylike.py:308: error: Value of type variable "_H" of "set" cannot be "type[Any]"  [type-var]

pandera (https://github.com/pandera-dev/pandera)
+ pandera/typing/__init__.py:53: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ pandera/typing/__init__.py:54: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ pandera/typing/__init__.py:55: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/addnodes.py:300:15: error: Type argument "type[desc_sig_element]" of "set" must be a subtype of "Hashable"  [type-var]
+ sphinx/util/docutils.py:42:19: error: Type argument "type[Element]" of "set" must be a subtype of "Hashable"  [type-var]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/typing/_implementations.py:229: error: Type argument "SupportedPrimitive" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ src/hydra_zen/typing/_builds_overloads.py:53: error: Type argument "SupportedPrimitive" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ src/hydra_zen/structured_configs/_implementations.py:218: error: Type argument "SupportedPrimitive" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ src/hydra_zen/structured_configs/_implementations.py:3151: error: Value of type variable "_H" of "set" cannot be "str | type[NOTHING]"  [type-var]
+ src/hydra_zen/structured_configs/_make_config.py:37: error: Type argument "SupportedPrimitive" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ tests/annotations/mypy_checks.py:34: error: Type argument "SupportedPrimitive" of "frozenset" must be a subtype of "Hashable"  [type-var]

trio (https://github.com/python-trio/trio)
+ src/trio/_core/_run.py:356: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_core/_run.py:389: error: Type argument "Task" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ src/trio/_core/_run.py:390: error: Value of type variable "_H_co" of "frozenset" cannot be "Task"  [type-var]
+ src/trio/_core/_run.py:902: error: Value of type variable "_H" of "set" cannot be "Task"  [type-var]
+ src/trio/_core/_run.py:1062: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_core/_run.py:1073: error: Type argument "Task" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ src/trio/_core/_run.py:1076: error: Value of type variable "_H_co" of "frozenset" cannot be "Task"  [type-var]
+ src/trio/_core/_run.py:1596: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_core/_run.py:1596: error: Argument 1 to "Factory" has incompatible type "Type[Set[Any]]"; expected "Callable[[], Set[Task]]"  [arg-type]
+ src/trio/_sync.py:63: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_sync.py:218: error: Type argument "Union[Task, object]" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_channel.py:153: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_channel.py:153: error: Argument 1 to "Factory" has incompatible type "Type[Set[Any]]"; expected "Callable[[], Set[Task]]"  [arg-type]
+ src/trio/_channel.py:293: error: Type argument "Task" of "set" must be a subtype of "Hashable"  [type-var]
+ src/trio/_channel.py:293: error: Argument 1 to "Factory" has incompatible type "Type[Set[Any]]"; expected "Callable[[], Set[Task]]"  [arg-type]
+ src/trio/_core/_tests/test_run.py:1558: error: Value of type variable "_H_co" of "frozenset" cannot be "Task"  [type-var]
+ src/trio/_core/_tests/test_run.py:1560: error: Value of type variable "_H_co" of "frozenset" cannot be "Task"  [type-var]

CPython (Argument Clinic) (https://github.com/python/cpython)
+ Tools/clinic/libclinic/converters.py:17: error: Type argument "type[object]" of "set" must be a subtype of "Hashable"  [type-var]
+ Tools/clinic/libclinic/converters.py:17: error: Value of type variable "_H" of "set" cannot be "type[object]"  [type-var]
+ Tools/clinic/libclinic/converters.py:26: error: Type argument "type[object]" of "set" must be a subtype of "Hashable"  [type-var]
+ Tools/clinic/libclinic/converters.py:732: error: Type argument "type[object]" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ Tools/clinic/libclinic/converters.py:736: error: Type argument "type[object]" of "frozenset" must be a subtype of "Hashable"  [type-var]
+ Tools/clinic/libclinic/converters.py:737: error: Value of type variable "_H_co" of "frozenset" cannot be "type[object]"  [type-var]

psycopg (https://github.com/psycopg/psycopg)
+ tests/test_adapt.py:418: error: "Hashable" has no attribute "__name__"  [attr-defined]
+ tests/test_adapt.py:419: error: "Hashable" has no attribute "__name__"  [attr-defined]

spark (https://github.com/apache/spark)
+ python/pyspark/core/rdd.py:2325: error: Value of type variable "_H" of "set" cannot be "S"  [type-var]
+ python/pyspark/pandas/frame.py:11631: error: Value of type variable "_H" of "set" cannot be "type[Any]"  [type-var]
+ python/pyspark/pandas/indexes/base.py:590: error: Value of type variable "_H" of "set" cannot be "type[Any]"  [type-var]

graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/execution/incremental_publisher.py:332: error: Type argument "AsyncIterator[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ src/graphql/execution/execute.py:390: error: Type argument "AsyncIterator[Any]" of "set" must be a subtype of "Hashable"  [type-var]

jinja (https://github.com/pallets/jinja)
+ src/jinja2/environment.py:1202: error: Value of type variable "_H_co" of "frozenset" cannot be "Union[str, Type[Extension]]"  [type-var]

flake8-pyi (https://github.com/PyCQA/flake8-pyi)
+ pyi.py:1420: error: Type argument "type[object]" of "set" must be a subtype of "Hashable"  [type-var]

jax (https://github.com/google/jax)
+ jax/_src/effects.py:92: error: Type argument "type[Effect]" of "set" must be a subtype of "Hashable"  [type-var]
+ jax/_src/api_util.py:718: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ jax/_src/checkify.py:1069: error: Type argument "type[JaxException]" of "frozenset" must be a subtype of "Hashable"  [type-var]

check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
+ src/check_jsonschema/parsers/__init__.py:12: error: Type argument "type[Exception]" of "set" must be a subtype of "Hashable"  [type-var]

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/coerce.py:15: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]
+ koda_validate/coerce.py:38: error: Value of type variable "_H" of "set" cannot be "type[Any]"  [type-var]
+ koda_validate/errors.py:30: error: Type argument "type[Any]" of "set" must be a subtype of "Hashable"  [type-var]

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.

1 participant