-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
TypeAlias not conforming to PascalCase to throw invalid-name #7081
Comments
I agree. TypeAlias names should be PascalCase. We could even argue that its good practice to suffix them with @DanielNoord Would you like to take a look at this one? I suspect it will be quite similar to the name check for TypeVars. |
Based on previous experiences I think narrowing down the tests are very important here. An initial draft: """Test cases for invalid-name for TypeAlias with default settings"""
# pylint: disable=too-few-public-methods,line-too-long
from typing import Callable, TypeAlias, Union
# PascalCase names
GoodName: TypeAlias = int
_GoodName: TypeAlias = int
__GoodName: TypeAlias = int
AnotherGoodName = Union[int, str]
AlsoGoodName = Callable
# Non-PascalCase names
BADName: TypeAlias = int # [invalid-name]
BadNAME: TypeAlias = int # [invalid-name]
badName: TypeAlias = int # [invalid-name]
BADNAMEType: TypeAlias = int # [invalid-name]
ANOTHERBADNAME = Union[int,str] # [invalid-name]
AlsoBADNAME = Callable # [invalid-name] Please tell me if you have any test cases that are missing. |
👍🏻 That's about what I had in mind. Maybe we can make also make sure that the name isn't suffixed with just BadNameT: TypeAlias = int # [invalid-name] I'll also test the PR against Home Assistant once it's ready, just to make sure we don't miss anything else. |
Thank you all for adding color! @DanielNoord I agree with all your I would like to include two more bad names:
|
I have decided to leave do_something: Callable[[], int]
def do_something() -> int:
return 1 Submitting the PR in a couple of minutes. Let me know if you want me to re-add it. |
Current problem
Python
typing.TypeAlias
are an alias to a type (as we all know). Thus, I thinkTypeAlias
should have to follow type naming conventions (e.g. PascalCase for classes, unless a primitive).In other words, we should see
TypeAlias
really as not much different from a novelclass
in regards to naming conventions. I think pylint is the tool to help enforce this!Desired solution
Please see the below code snippet
To restate, I think pylint should error on
CLASS_NAME_ALIAS
withinvalid-name
.Additional context
See the TypeAlias PEP: https://peps.python.org/pep-0613/#error-messaging
They use
ClassName
, notCLASS_NAME
.The text was updated successfully, but these errors were encountered: