Skip to content

Remove type aliases that are long supported #16039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 4, 2023
Merged

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 4, 2023

Some builtin aliases are available for all python versions that we support. So, there's no need to check them in semanal:

mypy/mypy/semanal.py

Lines 673 to 689 in 8738886

def add_builtin_aliases(self, tree: MypyFile) -> None:
"""Add builtin type aliases to typing module.
For historical reasons, the aliases like `List = list` are not defined
in typeshed stubs for typing module. Instead we need to manually add the
corresponding nodes on the fly. We explicitly mark these aliases as normalized,
so that a user can write `typing.List[int]`.
"""
assert tree.fullname == "typing"
for alias, target_name in type_aliases.items():
if type_aliases_source_versions[alias] > self.options.python_version:
# This alias is not available on this Python version.
continue
name = alias.split(".")[-1]
if name in tree.names and not isinstance(tree.names[name].node, PlaceholderNode):
continue
self.create_alias(tree, target_name, alias, name)

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

vision (https://github.com/pytorch/vision): typechecking got 1.28x slower (44.0s -> 56.3s)
(Performance measurements are based on a single noisy sample)

"typing.OrderedDict": (3, 7),
"typing.LiteralString": (3, 11),
}
type_aliases_source_versions: Final = {"typing.LiteralString": (3, 11)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, wish we had magic trailing comma on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a @hauntsaninja's preference :)
I prefer , everywhere.

@sobolevn sobolevn merged commit bd212bc into master Sep 4, 2023
@sobolevn sobolevn deleted the remove-support-aliases branch September 4, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants