[ty] route constructor calls through bindings#22124
Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 82.43% to 82.45%. The percentage of expected errors that received a diagnostic increased from 73.29% to 73.38%. Summary
True positives addedDetails
|
|
CodSpeed Performance ReportMerging this PR will degrade performance by 9.94%Comparing Summary
Performance Changes
Footnotes
|
4767d0c to
f4c53d0
Compare
22c5691 to
ebb4b8b
Compare
|
Hi all ! This should be ready for review, though I have a question concerning the test assertions I modified inside functions.md, the previous TODO mentioned no error but to my knowledge the comment I added is correct and the two errors surfaced should indeed appear, so I'd like your input on which it should be ! Thanks :) |
|
Wow, awesome, thank you for working on this! It looks like the diagnostics that this PR removes on lines 81 and 82 of the conformance suite, in The diagnostic added on line 29 of |
dd376de to
c5f5d23
Compare
| class Builder(Generic[TMsg]): | ||
| def build(self) -> Stream[TMsg]: | ||
| stream: Stream[TMsg] = Stream() | ||
| # TODO: no error |
There was a problem hiding this comment.
the previous TODO mentioned no error but to my knowledge the comment I added is correct and the two errors surfaced should indeed appear, so I'd like your input on which it should be, thanks !
c5f5d23 to
ca77a7d
Compare
Indeed looks like a regression ! That was because I missed updating the TypeVar matching arms, so thanks for catching that, I fixed it to validate params against the bound class and added an mdtest (straight copied from typing conformance) to prevent future regression on that side CI is currently red for reasons that look unrelated to this change: mypy_primer is failing while cloning pypa/twine (git clone … exit 128), and codspeed is panicking. I’ll rerun CI and dig in after Christmas if issues persist :) |
The CodSpeed panic is related to your change but not necessarily a blocker to the change. There is an assertion in each benchmarked library that the number of diagnostics are >0 but less than a per-library upperbound but your change means it is now above this bound. If the new diagnostics are not false-positives then you just increase the number in the relevant file (plus some headroom). The relevant setting is here: |
Thanks for the explanation ! I found the way to run it locally, I'll check the diffs and whether they're regressions/bugs when I get back :) |
ca77a7d to
21d12be
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
389 | 0 | 6 |
unknown-argument |
32 | 0 | 0 |
unused-type-ignore-comment |
0 | 22 | 0 |
missing-argument |
16 | 0 | 0 |
too-many-positional-arguments |
16 | 0 | 0 |
invalid-return-type |
0 | 3 | 6 |
type-assertion-failure |
0 | 3 | 3 |
no-matching-overload |
4 | 0 | 0 |
parameter-already-assigned |
4 | 0 | 0 |
| Total | 461 | 28 | 15 |
1d0e882 to
e32c211
Compare
Thanks a ton for the thorough review! No worries at all about the time to review! I also preserved existing behavior around type[T] constraints and TypedDict/known‑class special cases, and added a couple clarifying comments where behavior could look surprising |
e32c211 to
891c3f5
Compare
|
Hit a merge conflict with #23113 after it merged |
inline `class_like_call_bindings`, make `constructor_bindings` a method again
|
FYI I'm making some updates to this in preparation to merge it. |
* main: (45 commits) [ty] Fix wrong inlay hints for overloaded function arguments (astral-sh#23179) [ty] Respect `@no_type_check` when combined with other decorators (astral-sh#23177) [ty] Use type context when inferring constructor argument types (astral-sh#23139) [`airflow`] Add ruff rules to catch deprecated attribute access from context key for Airflow 3.0 (`AIR301`) (astral-sh#22850) Support formatting `pycon` markdown code blocks (astral-sh#23112) Markdown formatting in LSP (astral-sh#23063) Instruct Claude to use comments more sparingly (astral-sh#23181) [`flake8-gettext`] Fix false negatives for plural argument of ngettext (`INT001`, `INT002`, `INT003`) (astral-sh#21078) [ty] Invoking goto-def on parentheses of a class constructor call takes you too constructor method [ty] Make goto definition on class constructor always go to class definition [ty] Assign lower completions ranking to deprecated functions and classes (astral-sh#23089) [ty] Fix parameter references across files via keyword args (astral-sh#23012) [ty] Exclude enclosing class for base completions (astral-sh#23141) [`pyupgrade`] Fix syntax error on string with newline escape and comment (`UP037`) (astral-sh#22968) [ty] Improve documentation for `expect_single_definition` method (astral-sh#23175) [ty] Configure check mode for all projects Add `home-assistant` to ecosystem projects (astral-sh#23132) Add tabbed shell completion documentation (astral-sh#23169) Bump typing conformance-suite pin (astral-sh#23174) [ty] Fix invalid diagnostic location for a sub-call to a specialized ParamSpec (astral-sh#23036) ...
* main: [ty] Detect flaky projects during ecosystem CI jobs (astral-sh#23178) [ty] Disallow TypeVars within ClassVars (astral-sh#23184)
* main: [ty] Fix Pyright links; use `heterogeneous_tuple` (astral-sh#23193) [ty] Limit fixed-length tuple expansion in overload matching (astral-sh#23190) Fixed import in `runtime-evaluated-decorators` example (astral-sh#23187)
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
prefect
sphinx
trio
|
Summary
fixes astral-sh/ty#2124
Type::bindingsmachinery viaconstructor_bindings(), ensuring constructor return types are instance-typed (not__init__'sNone)__new__/__init__lints remain method-specific and fire once per call site (including the missing-__init__fallback)Test Plan
@staticmethod __new__, conflicting__new__/__init__parameter types,__new__-only fallback (object__init__accepts args), and generic constructor inference.functools.cached_propertyspecifically added to address Supportcached_propertyty#1446C[Unknown]are now correctly revealed asC[int](and constructor specialization uses first matching overload)