Skip to content

[ty] Treat ClassVar-qualified Callables as bound-method descriptors#20861

Closed
sharkdp wants to merge 2 commits intomainfrom
david/treat-classvar-callables-as-bound-method-descriptors
Closed

[ty] Treat ClassVar-qualified Callables as bound-method descriptors#20861
sharkdp wants to merge 2 commits intomainfrom
david/treat-classvar-callables-as-bound-method-descriptors

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Oct 14, 2025

Summary

Test Plan

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Oct 14, 2025
@sharkdp sharkdp changed the title David/treat classvar callables as bound method descriptors [ty] Treat ClassVar-qualified Callables as bound-method descriptors Oct 14, 2025
@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

mypy_primer results

Changes were detected when running on open source projects
pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/dataclasses.py:315:17: error[missing-argument] No argument provided for required parameter 1
- pydantic/v1/dataclasses.py:332:17: error[missing-argument] No argument provided for required parameter 1
- Found 767 diagnostics
+ Found 765 diagnostics

hydpy (https://github.com/hydpy-dev/hydpy)
- hydpy/core/testtools.py:1931:41: error[unresolved-attribute] Type `(...) -> Unknown` has no attribute `__code__`
- hydpy/cythons/modelutils.py:2110:44: error[unresolved-attribute] Type `(...) -> Unknown` has no attribute `__code__`
- Found 611 diagnostics
+ Found 609 diagnostics
No memory usage changes detected ✅

@github-actions
Copy link
Contributor

ecosystem-analyzer results

Lint rule Added Removed Changed
missing-argument 0 2 0
unresolved-attribute 0 2 0
Total 0 4 0

Full report with detailed diff (timing results)

@sharkdp
Copy link
Contributor Author

sharkdp commented Oct 14, 2025

The ecosystem impact is the same as on #20860 (and this PR includes the same changes). So the impact of also treating ClassVars as bound-method descriptors is zero.

@sharkdp sharkdp closed this Oct 14, 2025
sharkdp added a commit that referenced this pull request Oct 14, 2025
)

## Summary

Dunder methods (at least the ones defined in the standard library)
always take an instance of the class as the first parameter. So it seems
reasonable to generally treat them as bound method descriptors if they
are defined via a `Callable` type.

This removes just a few false positives from the ecosystem, but solves
three user-reported issues:

closes astral-sh/ty#908
closes astral-sh/ty#1143
closes astral-sh/ty#1209

In addition to the change here, I also considered [making `ClassVar`s
bound method descriptors](#20861).
However, there was zero ecosystem impact. So I think we can also close
astral-sh/ty#491 with this PR.

closes astral-sh/ty#491

## Test Plan

Added regression test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant