Skip to content

Type alias defined in parent seems to be lost in children? #10757

Discussion options

You must be logged in to vote

The cast in this case does nothing because the type of the expression "camenbert" is already Literal["camenbert"]. Casting it to the same type is therefore a no-op.

You haven't provided a type declaration for the cheese instance variable, so its type is inferred based on the values assigned to it within the Parent class. The sole assignment is assigning a value of type Literal["camenbert"], but literals are widened to their non-literal counterpart when inferring types. After all, you would not generally expect the statement self.foo = 1 to imply that foo is limited to just 1; you'd expect that foo would accept any int.

For more details about inference, refer to this documentation.

If your…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@guillaume-alliander
Comment options

Answer selected by guillaume-alliander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants