Content-Length: 296683 | pFad | http://github.com/astral-sh/ruff/pull/16748

71 [red-knot] Add custom `__setattr__` support by sharkdp · Pull Request #16748 · astral-sh/ruff · GitHub
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

[red-knot] Add custom __setattr__ support #16748

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Mar 14, 2025

Summary

I tried to implement this today, but I believe we need a similar approach as in #16512 where dunder lookups should skip symbols on object.

Test Plan

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 10 diagnostics
+ Found 8 diagnostics

packaging (https://github.com/pypa/packaging)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/packaging/tests/test_tags.py:149:9: Unresolved attribute `name` on type `MockImplementation`.
- Found 141 diagnostics
+ Found 140 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 278 diagnostics
+ Found 277 diagnostics

rich (https://github.com/Textualize/rich)
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/rich/tests/test_console.py:880:5: Unresolved attribute `isatty` on type `<bound method `file` of `Console`>`.
+ warning[lint:unused-ignore-comment] /tmp/mypy_primer/projects/rich/rich/repr.py:144:39: Unused blanket `type: ignore` directive
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/rich/tests/test_inspect.py:385:5: Unresolved attribute `SomeClass` on type `ModuleType`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/rich/tests/test_inspect.py:386:5: Unresolved attribute `function` on type `ModuleType`.
- error[lint:unresolved-attribute] /tmp/mypy_primer/projects/rich/tests/test_repr.py:57:5: Unresolved attribute `angular` on type `Literal[__rich_repr__]`.
- Found 604 diagnostics
+ Found 601 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 300 diagnostics
+ Found 299 diagnostics

@AlexWaygood
Copy link
Member

where dunder lookups should skip symbols on object.

I wonder if it's actually helpful to any type checkers for that definition to exist in typeshed? Sure, it exists at runtime, so we'd have to add an allowlist entry in typeshed's tests if we omitted it in the stubs (or typeshed's tests would complain that there was a method at runtime that was missed in the stubs). But it's okay to add allowlist entries like that if the costs of including the method definition in the stubs outweigh the benefits — that may be the case here.

It might be worth sending an experimental PR to typeshed seeing what happens on mypy_primer if it's removed?

@AlexWaygood
Copy link
Member

Following up: we discussed this on Discord and realised that removing object.__setattr__ from typeshed would be a pretty bad idea, since it would mean that a type checker would emit an error if you tried to call it manually (e.g. object.__setattr__(x, "foo", 42). There are use cases for doing this.

@sharkdp
Copy link
Contributor Author

sharkdp commented Mar 14, 2025

I'm going to leave this open for now, because I think it makes sense to wait for #16521. But if someone wants to pick this up, please go ahead.

@sharkdp sharkdp force-pushed the david/setattr-support branch from 0d99e37 to 4bd3c2b Compare March 14, 2025 20:51
@sharkdp sharkdp force-pushed the david/setattr-support branch from 4bd3c2b to a21e1d1 Compare March 14, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/astral-sh/ruff/pull/16748

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy