Skip to content

[ty] Infer class keyword arguments with __init_subclass__ context - #24364

Closed
sharkdp wants to merge 2 commits into
mainfrom
david/fix-3198
Closed

sharkdp wants to merge 2 commits into
mainfrom
david/fix-3198

Conversation

@sharkdp

@sharkdp sharkdp commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

closes astral-sh/ty#3198

Test Plan

@sharkdp sharkdp added the ty The ty type checker label Apr 2, 2026
@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 86.76%. The percentage of expected errors that received a diagnostic held steady at 81.53%. The number of fully passing files held steady at 70/132.

@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 717.05MB 717.08MB +0.00% (29.09kB) ⏫
trio 117.75MB 117.78MB +0.02% (24.14kB) ⏫
sphinx 264.69MB 264.71MB +0.01% (22.68kB) ⏫
flake8 47.99MB 48.00MB +0.02% (9.79kB) ⏫

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
infer_definition_types 90.04MB 90.05MB +0.01% (9.17kB) ⏫
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 455.00kB 460.90kB +1.30% (5.90kB) ⏫
StaticClassLiteral<'db>::explicit_bases_ 585.57kB 590.91kB +0.91% (5.34kB) ⏫
StaticClassLiteral<'db>::try_mro_ 5.87MB 5.88MB +0.09% (5.15kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_ 9.98MB 9.98MB +0.01% (1008.00B) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 5.29MB 5.29MB +0.02% (864.00B) ⏫
code_generator_of_static_class 1.82MB 1.82MB +0.02% (420.00B) ⏫
StaticClassLiteral<'db>::try_metaclass_ 1.21MB 1.21MB +0.03% (416.00B) ⏫
StaticClassLiteral<'db>::is_typed_dict_ 625.39kB 625.64kB +0.04% (264.00B) ⏫
code_generator_of_static_class::interned_arguments 941.41kB 941.62kB +0.02% (216.00B) ⏫
use_def_map 470.45kB 470.62kB +0.04% (180.00B) ⏫
place_table 750.76kB 750.94kB +0.02% (180.00B) ⏫
StaticClassLiteral<'db>::try_mro_::interned_arguments 1.37MB 1.37MB +0.01% (72.00B) ⏫

trio

Name Old New Diff Outcome
infer_definition_types 7.73MB 7.74MB +0.08% (6.54kB) ⏫
StaticClassLiteral<'db>::try_mro_ 822.74kB 827.34kB +0.56% (4.60kB) ⏫
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 45.42kB 49.99kB +10.05% (4.57kB) ⏫
StaticClassLiteral<'db>::explicit_bases_ 68.46kB 72.95kB +6.56% (4.49kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_ 750.76kB 751.96kB +0.16% (1.20kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 599.44kB 600.47kB +0.17% (1.03kB) ⏫
code_generator_of_static_class 209.68kB 210.36kB +0.33% (700.00B) ⏫
StaticClassLiteral<'db>::is_typed_dict_ 67.12kB 67.54kB +0.63% (432.00B) ⏫
code_generator_of_static_class::interned_arguments 103.50kB 103.85kB +0.34% (360.00B) ⏫
Specialization 462.36kB 462.47kB +0.02% (112.00B) ⏫
GenericAlias 193.64kB 193.71kB +0.04% (72.00B) ⏫
StaticClassLiteral<'db>::try_mro_::interned_arguments 191.95kB 192.02kB +0.04% (72.00B) ⏫

sphinx

Name Old New Diff Outcome
infer_definition_types 24.00MB 24.01MB +0.03% (7.83kB) ⏫
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 124.80kB 129.53kB +3.78% (4.72kB) ⏫
StaticClassLiteral<'db>::explicit_bases_ 173.46kB 177.72kB +2.46% (4.27kB) ⏫
StaticClassLiteral<'db>::try_mro_ 2.06MB 2.06MB +0.20% (4.12kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_ 2.40MB 2.40MB +0.03% (784.00B) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 1.93MB 1.93MB +0.03% (672.00B) ⏫
code_generator_of_static_class 528.07kB 528.21kB +0.03% (140.00B) ⏫
StaticClassLiteral<'db>::is_typed_dict_ 183.75kB 183.86kB +0.06% (108.00B) ⏫
code_generator_of_static_class::interned_arguments 263.60kB 263.67kB +0.03% (72.00B) ⏫

flake8

Name Old New Diff Outcome
infer_definition_types 1.87MB 1.88MB +0.13% (2.41kB) ⏫
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 18.09kB 19.50kB +7.80% (1.41kB) ⏫
StaticClassLiteral<'db>::explicit_bases_ 30.10kB 31.38kB +4.24% (1.28kB) ⏫
StaticClassLiteral<'db>::try_mro_ 322.72kB 323.98kB +0.39% (1.27kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_ 313.34kB 314.54kB +0.38% (1.20kB) ⏫
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 255.28kB 256.31kB +0.40% (1.03kB) ⏫
code_generator_of_static_class 60.65kB 61.06kB +0.68% (420.00B) ⏫
StaticClassLiteral<'db>::is_typed_dict_ 28.47kB 28.68kB +0.74% (216.00B) ⏫
code_generator_of_static_class::interned_arguments 30.02kB 30.23kB +0.70% (216.00B) ⏫
use_def_map 19.80kB 19.98kB +0.89% (180.00B) ⏫
place_table 25.20kB 25.37kB +0.70% (180.00B) ⏫

@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 40 0 0
invalid-return-type 1 0 0
Total 41 0 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

@AlexWaygood

Copy link
Copy Markdown
Member

I've had a patch sitting locally for ages improving our handling of class keywords -- they're not necessarily consumed by __init_subclass__. If a class has a custom metaclass and that metaclass has a __new__ method, the keywords will be consumed by the metaclass __new__ method instead of __init_subclass__. We might need to account for that possibility here. My draft patch is at main...alex/metaclass-new-prepare

@sharkdp

sharkdp commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

I've had a patch sitting locally for ages improving our handling of class keywords -- they're not necessarily consumed by __init_subclass__. If a class has a custom metaclass and that metaclass has a __new__ method, the keywords will be consumed by the metaclass __new__ method instead of __init_subclass__. We might need to account for that possibility here. My draft patch is at main...alex/metaclass-new-prepare

That makes sense, thanks! I may pick this up again once #24550 is merged.

@sharkdp sharkdp closed this Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in type inference of arguments to __init_subclass__ in subclass declaration

2 participants