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
First of all, I'm sorry if this already exists and I'm just unaware of it.
Feature
Add some command-line argument to mypy to prevent the expansion/resolution of aliases of types (such as large type Unions; large chains of Literals; or heavily nested aliases) to their underlying type.
Pitch
Often, when running mypy, a type alias is "resolved" to its underlying type, which can sometimes severely impede legibility. This tends to happen a lot with Unions and Literals, as well as general chains of aliases.
Say I have an AlphabetDuos enum containing the 26^2 values "AA", "AB", ..., "ZY", "ZZ", and an accompanying literals list (with an alias) Literals_AlphabetDuos = Literal["AA", ..., "ZZ"] (because I need to serialize/deserialize those cleanly, for example). I've typed my input with Literals_AlphabetDuos, but MyPy will often correct you with a massivevalue of type 'str' cannot be assigned to type Literal["AA", ..., "ZZ"], expanding the 26^2 values and making the terminal output quickly illegible; when it could much more cleanly answer you with value of type 'str' cannot be assigned to type Literals_AlphabetDuos.
A similar issue happens with large Unions, and nesting of types. It's also easy to see how this automatic resolution gets unwieldy when you have things like Alias3 = Dict[AliasB, AliasD] throughout your code, and AliasB and AliasD are large literals or unions etc. Finding the right comma between parentheses or brackets (in a non-prettified string) is an excruciatingly annoying endeavor (copy-paste from the terminal, then regex, is the best I've found...).
Using such a feature could be as simple as:
python3 -m mypy --keep-aliases my_test_file.py
I hope you'll see the value of this feature.
In any case, thanks for the great work; mypy is very useful and appreciated :)
The text was updated successfully, but these errors were encountered:
First of all, I'm sorry if this already exists and I'm just unaware of it.
Feature
Add some command-line argument to mypy to prevent the expansion/resolution of aliases of types (such as large type Unions; large chains of Literals; or heavily nested aliases) to their underlying type.
Pitch
Often, when running mypy, a type alias is "resolved" to its underlying type, which can sometimes severely impede legibility. This tends to happen a lot with Unions and Literals, as well as general chains of aliases.
Say I have an
AlphabetDuos
enum containing the 26^2 values"AA", "AB", ..., "ZY", "ZZ"
, and an accompanying literals list (with an alias)Literals_AlphabetDuos = Literal["AA", ..., "ZZ"]
(because I need to serialize/deserialize those cleanly, for example). I've typed my input with Literals_AlphabetDuos, but MyPy will often correct you with a massivevalue of type 'str' cannot be assigned to type Literal["AA", ..., "ZZ"]
, expanding the 26^2 values and making the terminal output quickly illegible; when it could much more cleanly answer you withvalue of type 'str' cannot be assigned to type Literals_AlphabetDuos
.A similar issue happens with large Unions, and nesting of types. It's also easy to see how this automatic resolution gets unwieldy when you have things like
Alias3 = Dict[AliasB, AliasD]
throughout your code, and AliasB and AliasD are large literals or unions etc. Finding the right comma between parentheses or brackets (in a non-prettified string) is an excruciatingly annoying endeavor (copy-paste from the terminal, then regex, is the best I've found...).Using such a feature could be as simple as:
I hope you'll see the value of this feature.
In any case, thanks for the great work; mypy is very useful and appreciated :)
The text was updated successfully, but these errors were encountered: