-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Support typing.TypeAliasType
#18156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) { | |
| registry.register_lint(&INVALID_EXCEPTION_CAUGHT); | ||
| registry.register_lint(&INVALID_GENERIC_CLASS); | ||
| registry.register_lint(&INVALID_LEGACY_TYPE_VARIABLE); | ||
| registry.register_lint(&INVALID_TYPE_ALIAS_TYPE); | ||
| registry.register_lint(&INVALID_METACLASS); | ||
| registry.register_lint(&INVALID_OVERLOAD); | ||
| registry.register_lint(&INVALID_PARAMETER_DEFAULT); | ||
|
|
@@ -591,6 +592,27 @@ declare_lint! { | |
| } | ||
| } | ||
|
|
||
| declare_lint! { | ||
| /// ## What it does | ||
| /// Checks for the creation of invalid `TypeAliasType`s | ||
| /// | ||
| /// ## Why is this bad? | ||
| /// There are several requirements that you must follow when creating a `TypeAliasType`. | ||
| /// | ||
| /// ## Examples | ||
| /// ```python | ||
| /// from typing import TypeAliasType | ||
| /// | ||
| /// IntOrStr = TypeAliasType("IntOrStr", int | str) # okay | ||
| /// NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name must be a string literal | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if we should have the same strict requirements here as for legacy
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me! |
||
| /// ``` | ||
| pub(crate) static INVALID_TYPE_ALIAS_TYPE = { | ||
| summary: "detects invalid TypeAliasType definitions", | ||
| status: LintStatus::preview("1.0.0"), | ||
| default_level: Level::Error, | ||
| } | ||
| } | ||
|
|
||
| declare_lint! { | ||
| /// ## What it does | ||
| /// Checks for arguments to `metaclass=` that are invalid. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate, but that file could just as easily have been written using PEP 695 type aliases …