[ty] Validate annotated assignments to declared attributes#25191
[ty] Validate annotated assignments to declared attributes#25191snoopuppy582 wants to merge 1 commit into
Conversation
Typing conformance resultsThe percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134. SummaryHow are test cases classified?Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (
True positives changed (2)2 diagnostics
|
Memory usage reportSummary
Significant changesClick to expand detailed breakdownsphinx
prefect
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-assignment |
13 | 0 | 0 |
unused-type-ignore-comment |
0 | 5 | 0 |
| Total | 13 | 5 | 0 |
Large timing changes:
| Project | Old Time | New Time | Change |
|---|---|---|---|
pandas-stubs |
9.77s | 15.62s | +60% |
Raw diff (18 changes)
PyGithub (https://github.com/PyGithub/PyGithub)
- github/Requester.py:1441:52 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
core (https://github.com/home-assistant/core)
+ homeassistant/components/switchbot_cloud/light.py:80:9 error[invalid-assignment] Object of type `tuple[int, ...] | None` is not assignable to attribute `_attr_rgb_color` of type `tuple[int, int, int] | None`
discord.py (https://github.com/Rapptz/discord.py)
+ discord/components.py:458:9 error[invalid-assignment] Cannot assign to read-only property `type` on object of type `Self@__init__`: Attempted assignment to `Self@__init__.type` here
isort (https://github.com/pycqa/isort)
+ isort/settings.py:288:9 error[invalid-assignment] Property `_known_patterns` defined in `Self@__init__` is read-only
+ isort/settings.py:289:9 error[invalid-assignment] Property `_section_comments` defined in `Self@__init__` is read-only
+ isort/settings.py:290:9 error[invalid-assignment] Property `_section_comments_end` defined in `Self@__init__` is read-only
+ isort/settings.py:291:9 error[invalid-assignment] Property `_skips` defined in `Self@__init__` is read-only
+ isort/settings.py:292:9 error[invalid-assignment] Property `_skip_globs` defined in `Self@__init__` is read-only
+ isort/settings.py:293:9 error[invalid-assignment] Property `_sorting_function` defined in `Self@__init__` is read-only
pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/common.py:1104:9 error[invalid-assignment] Object of type `ZipFile` is not assignable to attribute `buffer` of type `BytesIO`
pip (https://github.com/pypa/pip)
+ src/pip/_vendor/urllib3/exceptions.py:287:9 error[invalid-assignment] Object of type `int` is not assignable to attribute `partial` of type `bytes`
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/server/utilities/database.py:302:13 error[invalid-assignment] Object of type `type[TypeEngine[Any]] | TypeEngine[Any]` is not assignable to attribute `impl` of type `<class 'JSON'>`
pyppeteer (https://github.com/pyppeteer/pyppeteer)
- pyppeteer/connection.py:99:53 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- pyppeteer/connection.py:100:40 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- pyppeteer/connection.py:228:53 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- pyppeteer/connection.py:229:40 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
tornado (https://github.com/tornadoweb/tornado)
+ tornado/web.py:1957:17 error[invalid-assignment] Object of type `dict[str, UIModule]` is not assignable to attribute `_active_modules` on type `Self@_ui_module & ~<Protocol with members '_active_modules'>`
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/exceptions.py:287:9 error[invalid-assignment] Object of type `int` is not assignable to attribute `partial` of type `bytes`a43f1f9 to
2206589
Compare
|
Pushed a follow-up in The attribute-assignment validation added here now skips the normal attribute assignment path when the inline annotation itself is Verified locally on Windows:
|
Summary
Fixes astral-sh/ty#509.
Test Plan
cargo fmt --checkcargo test -p ty_python_semantic --test mdtest -- diagnostics/attribute_assignment.mdcargo test -p ty_python_semantic --test mdtest -- assignment/annotations.mdcargo test -p ty_python_semantic --lib