fix Incorrect invalid-type-var check when persisting get method of a fully-annotated dict #2812#2816
fix Incorrect invalid-type-var check when persisting get method of a fully-annotated dict #2812#2816asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Fixes a false-positive invalid-type-var error when persisting a bound overload method (e.g., dict[str, str].get) onto an instance attribute, by ensuring type-variable sanitization treats overload-carried Forall type parameters as locally bound.
Changes:
- Extend
invalid-type-varsanitization to collect type parameters bound byForalloverload signatures (bothType::OverloadandBoundMethodType::Overload). - Add a regression test covering assignment of
dict[str, str].getto an instance attribute and verifying the resulting callable type.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/alt/class/class_field.rs |
Updates type-parameter collection to account for Forall tparams inside overload signatures during attribute type sanitization. |
pyrefly/lib/test/attributes.rs |
Adds regression test for assigning a bound overload (dict.get) to an attribute and asserting its inferred call types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D97669915. |
rchen152
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
Diff from mypy_primer, showing the effect of this PR on open source code: beartype (https://github.com/beartype/beartype)
- ERROR beartype/_util/cache/map/utilmapunbounded.py:113:14-31: Attribute `_key_to_value_get` cannot depend on type variable `_T`, which is not in the scope of class `CacheUnboundedStrong` [invalid-type-var]
scikit-learn (https://github.com/scikit-learn/scikit-learn)
- ERROR sklearn/cluster/_agglomerative.py:1309:14-26: Attribute `pooling_func` cannot depend on type variable `_ArrayT`, which is not in the scope of class `FeatureAgglomeration` [invalid-type-var]
- ERROR sklearn/cluster/_agglomerative.py:1309:14-26: Attribute `pooling_func` cannot depend on type variable `_ScalarT`, which is not in the scope of class `FeatureAgglomeration` [invalid-type-var]
setuptools (https://github.com/pypa/setuptools)
- ERROR setuptools/command/editable_wheel.py:454:14-19: Attribute `_file` cannot depend on type variable `_StrPathT`, which is not in the scope of class `_LinkTree` [invalid-type-var]
- ERROR setuptools/command/editable_wheel.py:454:14-19: Attribute `_file` cannot depend on type variable `_BytesPathT`, which is not in the scope of class `_LinkTree` [invalid-type-var]
pip (https://github.com/pypa/pip)
- ERROR src/pip/_vendor/rich/theme.py:89:14-17: Attribute `get` cannot depend on type variable `_T`, which is not in the scope of class `ThemeStack` [invalid-type-var]
zope.interface (https://github.com/zopefoundation/zope.interface)
- ERROR src/zope/interface/tests/test_adapter.py:95:14-17: Attribute `get` cannot depend on type variable `_T`, which is not in the scope of class `CustomMapping` [invalid-type-var]
rich (https://github.com/Textualize/rich)
- ERROR rich/theme.py:89:14-17: Attribute `get` cannot depend on type variable `_T`, which is not in the scope of class `ThemeStack` [invalid-type-var]
jinja (https://github.com/pallets/jinja)
- ERROR src/jinja2/environment.py:352:14-21: Attribute `filters` cannot depend on type variable `V`, which is not in the scope of class `Environment` [invalid-type-var]
sphinx (https://github.com/sphinx-doc/sphinx)
- ERROR sphinx/domains/__init__.py:134:14-31: Attribute `objtypes_for_role` cannot depend on type variable `_T`, which is not in the scope of class `Domain` [invalid-type-var]
- ERROR sphinx/domains/__init__.py:135:14-30: Attribute `role_for_objtype` cannot depend on type variable `_T`, which is not in the scope of class `Domain` [invalid-type-var]
|
Primer Diff Classification✅ 8 improvement(s) | 8 project(s) total | -9 errors 8 improvement(s) across beartype, scikit-learn, setuptools, pip, zope.interface, rich, jinja, sphinx.
Detailed analysis✅ Improvement (8)beartype (-1)
scikit-learn (-1)
setuptools (-1)
pip (-1)
zope.interface (-1)
rich (-1)
jinja (-1)
sphinx (-2)
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (8 LLM) |
Summary
Fixes #2812
The cause was: invalid-type-var sanitization already exempted generic Forall methods, but it was not exempting generic overload signatures carried inside Overload and bound-method overloads. I added that handling there, so storing
dict[str, str].geton an instance attribute no longer falsely reports leaked_T.Test Plan
add test