Skip to content

[red-knot] Add custom __setattr__ support #16748

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Mar 14, 2025

Summary

Add support for classes with a custom __setattr__ method.

Test Plan

New Markdown tests, ecosystem checks.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Mar 14, 2025
Copy link
Contributor

github-actions bot commented Mar 14, 2025

mypy_primer results

Changes were detected when running on open source projects
zipp (https://github.com/jaraco/zipp)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/zipp/zipp/compat/overlay.py:34:1: Unresolved attribute `Path` on type `HashableNamespace`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/zipp/zipp/compat/overlay.py:35:1: Unresolved attribute `_path` on type `HashableNamespace`.
- Found 4 diagnostics
+ Found 2 diagnostics

pyinstrument (https://github.com/joerick/pyinstrument)
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/pyinstrument/pyinstrument/stack_sampler.py:282:9: Object of type `StackSampler` is not assignable to attribute `stack_sampler` on type `Unknown | _local`
- Found 291 diagnostics
+ Found 290 diagnostics

werkzeug (https://github.com/pallets/werkzeug)
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/coolmagic/utils.py:67:9: Object of type `Unknown` is not assignable to attribute `request` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/couchy/application.py:18:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/couchy/application.py:30:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/couchy/application.py:32:9: Object of type `Unknown | MapAdapter` is not assignable to attribute `url_adapter` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/simplewiki/application.py:52:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/simplewiki/utils.py:79:9: Object of type `Unknown` is not assignable to attribute `request` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/plnt/webapp.py:32:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/plnt/webapp.py:36:9: Object of type `Request` is not assignable to attribute `request` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/plnt/webapp.py:37:9: Object of type `Unknown | MapAdapter` is not assignable to attribute `url_adapter` on type `Unknown | Local`
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_wrappers.py:685:5: Unresolved attribute `realm` on type `WWWAuthenticate`.
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/shorty/application.py:19:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/shorty/application.py:28:9: Object of type `Unknown` is not assignable to attribute `application` on type `Unknown | Local`
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/examples/shorty/application.py:30:9: Object of type `Unknown | MapAdapter` is not assignable to attribute `url_adapter` on type `Unknown | Local`
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:31:5: Unresolved attribute `foo` on type `Local`.
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:36:9: Object of type `Unknown` is not assignable to attribute `foo` on type `Unknown | Local`
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:59:5: Unresolved attribute `foo` on type `Local`.
- error[lint:invalid-assignment] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:64:9: Object of type `Unknown` is not assignable to attribute `foo` on type `Unknown | Local`
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:87:5: Unresolved attribute `foo` on type `Local`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:138:5: Unresolved attribute `foo` on type `Local`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:176:5: Unresolved attribute `foo` on type `Local`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:177:5: Unresolved attribute `bar` on type `Local`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/werkzeug/tests/test_local.py:221:5: Unresolved attribute `value` on type `Local`.
- Found 801 diagnostics
+ Found 779 diagnostics

pybind11 (https://github.com/pybind/pybind11)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/pybind11/tests/test_class_sh_property.py:150:5: Unresolved attribute `num` on type `unique_ptr_field_proxy_poc`.
- Found 288 diagnostics
+ Found 287 diagnostics

typeshed-stats (https://github.com/AlexWaygood/typeshed-stats)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/typeshed-stats/scripts/regenerate.py:40:13: Unresolved attribute `typeshed_dir` on type `Namespace`.
- Found 177 diagnostics
+ Found 176 diagnostics

scrapy (https://github.com/scrapy/scrapy)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/scrapy/scrapy/commands/parse.py:379:17: Unresolved attribute `meta` on type `Namespace`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/scrapy/scrapy/commands/parse.py:390:17: Unresolved attribute `cbkwargs` on type `Namespace`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/scrapy/scrapy/commands/__init__.py:169:13: Unresolved attribute `spargs` on type `Namespace`.
- Found 1591 diagnostics
+ Found 1588 diagnostics

@AlexWaygood

This comment was marked as resolved.

@AlexWaygood

This comment was marked as resolved.

@sharkdp

This comment was marked as resolved.

@sharkdp sharkdp force-pushed the david/setattr-support branch 2 times, most recently from 4bd3c2b to a21e1d1 Compare March 14, 2025 21:17
@sharkdp sharkdp force-pushed the david/setattr-support branch 2 times, most recently from 51951db to 6e63fc1 Compare April 8, 2025 21:05
Copy link

codspeed-hq bot commented Apr 8, 2025

CodSpeed Performance Report

Merging #16748 will not alter performance

Comparing david/setattr-support (ac68c23) with main (fab7d82)

Summary

✅ 32 untouched benchmarks

@sharkdp sharkdp force-pushed the david/setattr-support branch from 6e63fc1 to aebb682 Compare April 8, 2025 21:36
@sharkdp sharkdp force-pushed the david/setattr-support branch from aebb682 to ac68c23 Compare April 8, 2025 21:40
@sharkdp sharkdp marked this pull request as ready for review April 8, 2025 21:47
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@sharkdp sharkdp merged commit 2cee86d into main Apr 9, 2025
23 checks passed
@sharkdp sharkdp deleted the david/setattr-support branch April 9, 2025 06:04
dcreager added a commit that referenced this pull request Apr 9, 2025
* origin/main:
  [red-knot] Default `python-platform` to current platform (#17183)
  [red-knot] Add new 'unreachable code' test case (#17306)
  [red-knot] mypy_primer: Run on `async-utils` (#17303)
  [red-knot] Add custom `__setattr__` support (#16748)
  [red-knot] Add `__init__` arguments check when doing `try_call` on a class literal (#16512)
  [`flake8-pie`] Avoid false positive for multiple assignment with `auto()` (`PIE796`) (#17274)
  [syntax-errors] Async comprehension in sync comprehension (#17177)
  [`airflow`] Expand module path check to individual symbols (`AIR302`) (#17278)
  [syntax-errors] Check annotations in annotated assignments (#17283)
  [syntax-errors] Extend annotation checks to `await` (#17282)
  [red-knot] Add support for `assert_never` (#17287)
  [`flake8-pytest-style`] Avoid false positive for legacy form of `pytest.raises` (`PT011`) (#17231)
  [red-knot] Do not show types for literal expressions on hover (#17290)
  [red-knot] Fix dead-code clippy warning (#17291)
  [red-knot] Reachability analysis (#17199)
  [red-knot] Don't use latency-sensitive for handlers (#17227)
dcreager added a commit that referenced this pull request Apr 9, 2025
* dcreager/special-class: (26 commits)
  lint
  Add TODO about property test data
  Better todos
  Narrow type(generic) better
  More Python-like displays for specializations
  Add xfail for generic method inside generic class
  Comment other non-specializations
  Explain self_instance not being specialized
  Generic aliases are literals in type display
  Better TODO fallback type
  [red-knot] Default `python-platform` to current platform (#17183)
  [red-knot] Add new 'unreachable code' test case (#17306)
  [red-knot] mypy_primer: Run on `async-utils` (#17303)
  [red-knot] Add custom `__setattr__` support (#16748)
  [red-knot] Add `__init__` arguments check when doing `try_call` on a class literal (#16512)
  [`flake8-pie`] Avoid false positive for multiple assignment with `auto()` (`PIE796`) (#17274)
  [syntax-errors] Async comprehension in sync comprehension (#17177)
  [`airflow`] Expand module path check to individual symbols (`AIR302`) (#17278)
  [syntax-errors] Check annotations in annotated assignments (#17283)
  [syntax-errors] Extend annotation checks to `await` (#17282)
  ...
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 9, 2025
## Summary

Add support for classes with a custom `__setattr__` method.

## Test Plan

New Markdown tests, ecosystem checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants