-
-
Notifications
You must be signed in to change notification settings - Fork 276
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 typing to NodeNG.statement
#1217
Conversation
We're actually catching the This does seem like something we want to fix, or at least document better. Using the However, how do we go about fixing a bug simultaneously in |
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 is a really strange fail in the pre-commit continuous integration. Maybe we need to not use the current astroid with pylint's in pre-commit ?
@Pierre-Sassoulas No the
We will thus need to change However, @cdce8p also mentioned that he wondered if it is correct 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.
Technically, you are correct that statement
can return nodes.Statement
or nodes.Module
. I was just wondering if it's of any use for us to return Module
or if we should raise an exception instead. Module
itself isn't a Statement
so from that perspective I would imaging it's special cased in pylint already.
In that sense, a general StatementMissing
, or similar, error might make sense. This could also be raised if a node doesn't have a parent (instead of ParentMissingError
).
Wouldn't using a |
Not really sure we need more information. It works just fine with the |
I do think we should at least show that this is expected behaviour of the method. The fact that we are actually handling
I'm not sure if I agree with I think raising more specific errors in the long run will be better as it makes the code more maintainable/readable. Not only can we give |
I agree with that. Just not sure At the moment, I just find |
Do you then want to raise
|
I would recommend to raise |
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 more information, see https://pre-commit.ci
2 questions:
|
Co-authored-by: Marc Mueller <[email protected]>
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've seen that pytest
will emit DeprecationWarnings
for astroid
itself. Could you add future=True
to existing statement in astroid
, too?
https://github.com/PyCQA/astroid/runs/4126645345?check_suite_focus=true#step:6:81
Co-authored-by: Marc Mueller <[email protected]>
This started to fail some of the tests. I wanted to do this in a separate PR because I wondered if some of the functions/methods calling |
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.
Overall, LGTM! Thanks @DanielNoord 🚀
A bit unfortunate, that we came across multiple false-positives in the process.
@Pierre-Sassoulas Do you want to take a final look at it? Maybe with focus on the Exception and deprecation message?
Co-authored-by: Marc Mueller <[email protected]>
Thanks for all of your help here @cdce8p! Indeed a bit unfortunate, but I learned a lot from this PR and it should help with some of the future PR's and issues we might come across. |
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 only have a small remark regarding the "bad super call" but I don't see anything wrong with the MR otherwise. To be fair I did not find the time to read the whole conversation and this seem really polished :) Look like you took care of a lot of problems, thanks a lot for handling this !
|
||
def __init__(self, target: "nodes.NodeNG") -> None: | ||
# pylint: disable-next=bad-super-call | ||
# https://github.com/PyCQA/pylint/issues/2903 |
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 the spirit of the check is to signal the problem to people that don't really know how to use super(). Here it's a false positive because calling the father's function is what you really want to do, but maybe in most case and especially for beginner the check is right. If we remove this "false positive" the check will only have really obvious cases where the class called is not even an ancestor ?
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.
🤔 Not sure about that. What it comes done to is if we want to emit errors for valid Python code. Even if it's probably not what was intended, there are still situations where it's useful and has it's place, especially with multi-inheritance.
The check also emits errors in cases that could cause recursion loops:
class SuperWithType(object):
"""type(self) may lead to recursion loop in derived classes"""
def __init__(self):
super(type(self), self).__init__() # [bad-super-call]
class SuperWithSelfClass(object):
"""self.__class__ may lead to recursion loop in derived classes"""
def __init__(self):
super(self.__class__, self).__init__() # [bad-super-call]
Any modifications should also make sure to still emit errors if the class is not part of the MRO.
class Getattr(object):
""" crash """
name = NewAaaa
class CrashSuper(object):
""" test a crash with this checker """
def __init__(self):
super(Getattr.name, self).__init__() # [bad-super-call]
Test cases taken from the pylint
testsuit: super_checks.py
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.
OK, I was trying to search for the initial issue where this was implemented for the rational but I can't find it. It makes sense to not warn for valid code, and the check has a lot of valid test cases, so let's fix this false positive.
astroid/nodes/scoped_nodes.py
Outdated
# pylint: disable-next=signature-differs | ||
# https://github.com/PyCQA/pylint/issues/5264 |
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-next=signature-differs | |
# https://github.com/PyCQA/pylint/issues/5264 |
It seems like our luck didn't outran us yet. This actual now triggers a useless-suppression
message. Guess we found a false-negative
by adding *
😅 pylint-dev/pylint#5270
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.
Is useless-suppression
not enabled for astroid
? CI is passing.
We might want to enable that in another PR.
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.
It's enabled, but not a failure condition! I don't think we should change that.
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.
Sure? Seems like something that will be easily missed in review
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 also think we should make it a failure condition so it's handled in the proper MR each time.
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.
We might want to enable that in another PR.
It would be as easy as adding --fail-on=useless-suppression
to the pylint
command.
The issue is that some errors might be Python version specific. It could create a situation where only one, pre-commit
or CI
, will succeed when tested with different versions. The py-version
option should help, but I don't know if it's enough.
Additionally, this would prevent us from having the latest pylint
version installed in a local env as this is likely to have fixed some false-positives. -> Which would then trigger useless-suppression
.
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.
That last point will indeed be difficult to avoid. I'll try and think of something to fix that, but in the meantime let's let this rest!
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.
Do you maybe want to track this as issue in pylint
?
in the meantime let's let this rest!
I completely agree!
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.
Shouldn't this be tracked in astroid
? pylint
has its own issues with useless-suppression
(pylint-dev/pylint#5040) 😄
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.
😂 Though if we enable it, we'll likely want to do it for pylint
too. Tbh I don't really care about it due to the issues mentioned earlier.
Co-authored-by: Marc Mueller <[email protected]>
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.
Let's (squash) merge it!
Steps
Description
statement()
is only defined twice. Once onNodeNG
and once onModule
. The one onNodeNG
refers toself.is_statement
which is only set toTrue
onStatement
. As a resultstatement()
can either returnModule
orStatement
.Added because of comment by @cdce8p here:
pylint-dev/pylint#5163 (review)
I think I will not wait for this version to be added to
pylint
to update the typing there.Type of Changes
Related Issue