-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 invalid-name
check for TypeAlias
names
#7116
Conversation
Pull Request Test Coverage Report for Build 3403162957
💛 - Coveralls |
This comment has been minimized.
This comment has been minimized.
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 you've done an excellent job @DanielNoord! Cheers!
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@cdce8p Just checking in. Do you want to review this before we merge this? Or can we merge without a review by you. |
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.
@cdce8p Just checking in. Do you want to review this before we merge this? Or can we merge without a review by you.
I had been away for a while working on other projects. If you want to reach me in these cases it's often best to DM me on Discord.
--
Regarding the PR, I left a few comments. Mostly left over references to Callable
and an optimization suggestion. What we should think a little bit more about is the regex though. I checked the PR against Home Assistant and saw errors for IPAddress
and IPNetwork
. Those should be ok, IMO. Maybe just the T
prefix should be disallowed, e.g. TBadName
?
Edit: For TypeVars we do also allow IPAddressT
so it would make sense to allow IPAddress
for Type aliases.
@@ -4,7 4,7 @@ | |||
|
|||
Use 'typing.Callable' instead. | |||
""" | |||
# pylint: disable=missing-docstring,unsubscriptable-object | |||
# pylint: disable=missing-docstring,unsubscriptable-object, invalid-name |
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.
# pylint: disable=missing-docstring,unsubscriptable-object, invalid-name | |
# pylint: disable=missing-docstring,unsubscriptable-object,invalid-name |
Might be just me, but I always find it irritating to see a space between error codes. Both for pylint and mypy. Similarly in the other test files.
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.
Oh wow, I actually thought the preferred style was to separate them. I'm fine either way but thought that was the style we were going for.
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.
Yeah I try to separate them myself 😄 (like arguments in a function call)
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.
To be fair I've seen (and used) both 😄 For files I write myself, I do prefer without spaces. However if I'm just editing a random test file, I usually continue with the style that is present.
@cdce8p Changed the regex. Let me know what you think. This doesn't allow |
This comment has been minimized.
This comment has been minimized.
After the |
This comment has been minimized.
This comment has been minimized.
@@ -40,7 40,8 @@ | |||
DEFAULT_PATTERNS = { | |||
"typevar": re.compile( | |||
r"^_{0,2}(?:[^\W\da-z_] |(?:[^\W\da-z_] [^\WA-Z_] ) T?(?<!Type))(?:_co(?:ntra)?)?$" | |||
) | |||
), | |||
"typealias": re.compile(r"^_{0,2}[A-Z] [a-z] ([A-Z][a-z] )*$"), |
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.
"typealias": re.compile(r"^_{0,2}[A-Z] [a-z] ([A-Z][a-z] )*$"), | |
"typealias": re.compile(r"^_{0,2}(?!T[A-Z]|Type)[A-Z] [a-z] (?:[A-Z][a-z] )*$"), |
Would this be a solution?
The negative lookahead would prevent cases like TBadName
and TypeTodo
but still allow TodoType
. TodoType
and TypeTodo
could also be added as test cases.
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.
Yeah, although it would still disallow TTCircuit
as in the circuit of a tt race.
That's really far fetched but I don't really like how this is such an arbitrary rule that is really difficult to figure out if you stumble upon it. I don't think TTCircuit
will be used very often but there might be real uses of TT
at the start and I think it would be very frustrating to figure out why pylint
disallows them.
What would you think about using the current pattern as the default value and using your suggestion as our own overwrite? We could potentially even add our own overwrite in the documentation of the message?
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.
Getting the regex 100% correct is pretty difficult. What should we do for the pandas cases then (DatetimeNaTType
, IntervalOrNA
, ...)?
IMO we should try to find something that works for most cases and can prevent common issues. The remaining ones should be handled with pylint: disable[invalid-name]
. In this case I believe it's a much more prevalent error to use a T
or Type
prefix then something like TTCircuit
, so I think it would be worth it.
I just opened #7322 to fix the same issue for the TypeVar
name style as I've seen _TRemote
and _TCommand
in HomeAssistant lately.
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 agree that T
and Type
will be much more prevalent but I feel like flagging a TTCircuit
would be considered a false positive. That's why I think we might want to be a little less strict by default and let users be more strict themselves. For me it falls within the false negatives vs. false positives preference, where I think the former is always more preferable.
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.
For me it falls within the false negatives vs. false positives preference, where I think the former is always more preferable.
Usually I agree here. However, I would consider invalid-name
to be at least somewhat special. It's one of the few checks which creates false-positives in order to highlight certain errors and I would think users might already be aware of that. Just an example, in HomeAssistant about 7-8% of all pylint: disable
comments are for invalid-name
(53 of 697).
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.
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.
Hey here could be an error, please check that. But if that's what you want, it's also fine.
Isn't that "convention" ? It's ok to not follow convention.
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.
Hey here could be an error, please check that. But if that's what you want, it's also fine.
Isn't that "convention" ? It's ok to not follow convention.
True 😄
In that case, we might only need to better explain that it's just a convention and nothing more.
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.
The issue might be that pep8 is wildly adopted (to a point that a lot of junior dev allow more time for PEP8 than to writing code that actually bring value). But PEP8 does not say anything about typevar/typealias yet so we're mixing a very popular convention with one that is less established.
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 have updated to use @cdce8p's suggestion and hope that the additional comments in details.rst
will prevent any issues. I think Marc is right that we should try to enforce good behaviour here rather than prevent 2/3 opened issues about this.
@@ -4,7 4,7 @@ | |||
|
|||
Use 'typing.Callable' instead. | |||
""" | |||
# pylint: disable=missing-docstring,unsubscriptable-object | |||
# pylint: disable=missing-docstring,unsubscriptable-object, invalid-name |
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.
To be fair I've seen (and used) both 😄 For files I write myself, I do prefer without spaces. However if I'm just editing a random test file, I usually continue with the style that is present.
This comment has been minimized.
This comment has been minimized.
Check fail should be fixed by #7321 |
This comment has been minimized.
This comment has been minimized.
Can I help forward this at all? I hate to see all this work go stale for 4 months |
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.
LGTM, thank you for reminding us @jamesbraza. We have a lot going on and some MR that are hard/long to review get lost in the flow.
This comment has been minimized.
This comment has been minimized.
I'll take another look at it soon. |
@cdce8p Do you think you'll be able to have a look at this still? |
@Pierre-Sassoulas I would prefer to merge this even without the final review from Marc. If we get feedback on the regex we can always change it, but the underlying changes seem good to me. Are you okay with this? |
Yeah allright, let's merge. |
We are going ahead with merging this
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #7116 /- ##
=======================================
Coverage 95.47% 95.47%
=======================================
Files 177 178 1
Lines 18726 18776 50
=======================================
Hits 17878 17926 48
- Misses 848 850 2
|
9708f69
to
ea800f4
Compare
Had to completely rebase as I was getting a lot of CI issues. Sorry for the loss of history, but this was the most sane way to do this. |
Also note that the recent PR broke |
ea800f4
to
6419292
Compare
doc/whatsnew/2/2.15/index.rst
(ordoc/whatsnew/2/2.14/full.rst
if the change needs backporting in 2.14). If necessary you can write
details or offer examples on how the new change is supposed to work.
and preferred name in
script/.contributors_aliases.json
Type of Changes
Description
Closes #7081.