Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
Typing the ast.AST subclass constructors #8378
Copy link
Copy link
Closed
Labels
help wantedAn actionable problem of low to medium complexity where a PR would be very welcomeAn actionable problem of low to medium complexity where a PR would be very welcomestubs: improvementImprove/refactor existing annotations, other stubs issuesImprove/refactor existing annotations, other stubs issues
Description
Metadata
Metadata
Assignees
Labels
help wantedAn actionable problem of low to medium complexity where a PR would be very welcomeAn actionable problem of low to medium complexity where a PR would be very welcomestubs: improvementImprove/refactor existing annotations, other stubs issuesImprove/refactor existing annotations, other stubs issues
We currently have static types for the fields of most (all?)
astclasses, but none of these have typed constructors, e.g.:typeshed/stdlib/_ast.pyi
Lines 79 to 86 in 62cde01
I think technically this might be because none of these subclasses actually have a unique constructor, but that shouldn't stop us from typing each of the constructors, since in practise the constructor arguments must correspond to the class fields.
Before I do this, though, I'm firstly wondering if an easy solution here would be to apply the
dataclass_transformdecorator (note: not the same as thedataclassdecorator). This would simply tell the type checker that all the class fields can and should be provided in the constructor, which is broadly correct. However I don't have a deep understanding of how theast.ASTconstructor works, so this might not be the correct behaviour. ForClassDefthis might look like:If this isn't sufficient, I propose that we simply add an
__init__()stub to each subclass. For instance, for theClassDefabove, this might look like: