-
Notifications
You must be signed in to change notification settings - Fork 221
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
Add support for type variable name convention check #235
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for the contribution!
Do you think we should consider the TypeVar
's arguments? Otherwise, we can only check if the given name matches one of the allowed conventions, but we can't check if the name matches the TypeVar
's specific values.
For example, would we want these mismatched forms to raise warnings?
Var = TypeVar("Var", covariant=True)
Var_co = TypeVar("Var", contravariant=True)
Var_contra = TypeVar("Var", covariant=True)
except AttributeError: | ||
continue | ||
|
||
if _ignored(name, ignore) or func_name != "TypeVar": |
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.
As a small optimization, let's check the cheaper expression first:
if _ignored(name, ignore) or func_name != "TypeVar": | |
if func_name != "TypeVar" or _ignored(name, ignore): |
underscore_split = name.split('_') | ||
suffix = underscore_split[-1] | ||
if len(underscore_split) > 2 or (suffix != 'co' and suffix != 'contra'): |
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.
I think this might be a little clearer if it focuses on a single suffix
value:
underscore_split = name.split('_') | |
suffix = underscore_split[-1] | |
if len(underscore_split) > 2 or (suffix != 'co' and suffix != 'contra'): | |
parts = name.split('_') | |
suffix = parts[-1] if len(parts) > 2 else '' | |
if suffix and suffix != 'co' and suffix != 'contra': |
Proposed implementation for #163.
Adds support for type variable name convention check, as mentioned in PEP8:
Proposed name is N808 due to the relationship with the class name convention.
It's my first time contributing, so please let me know if anything needs to be done differently!
Thank you