You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 595760f
Browse filesBrowse the repository at this point in the historyBrowse files
This diff changes how we track raw literal types in the semantic
analysis phase. It makes the following changes:
1. Removes the `RawLiteralType` synthetic type.
2. Adds a new `TypeOfAny`: `TypeOfAny.invalid_type` as suggested
in python#4030.
3. Modifies `AnyType` so it can optionally contain a new
`RawLiteral` class. This class contains information
about the underlying literal that produced that particular
`TypeOfAny`.
4. Adjusts mypy to stop recommending using `Literal[...]` when
doing `A = NewType('A', 4)` or `T = TypeVar('T', bound=4)`.
(The former suggestion is a bad one: you can't create a NewType of a
Literal[...] type. The latter suggestion is a valid but stupid one:
`T = TypeVar('T', bound=Literal[4])` is basically the same thing as
`T = Literal[4]`.)
This resolvespython#5989.
The net effect of this diff is that:
1. RawLiteralTypes no longer leak during fine-grained mode,
which should partially help unblock
python#6075.
2. The way mypy handles literal expressions in types is "inverted".
Previously, we by default assumed literal expressions would belong
inside `Literal[...]` and tacked on some logic to make them convert
into error `AnyTypes`. Now, we do the reverse: we start with an
error `AnyType` and convert those into `Literal[...]`s as needed.
This more closely mirrors the way mypy *used* to work before we
started work on Literal types. It should also hopefully help reduce
some of the cognitive burden of working on other parts of the
semantic analysis code, since we no longer need to worry about the
`RawLiteralType` synthetic type.
3. We now have more flexibility in how we choose to handle invalid
types: since they're just `Anys`, we have more opportunities to
intercept and customize the exact way in which we handle errors.
Also see python#4030 for additional
context. (This diff lays out some of the foundation work for that
diff).
0 commit comments