Skip to content
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

useless-super-delegation when overriding Exception to have different default argument #7319

Closed
jace opened this issue Aug 18, 2022 · 6 comments · Fixed by #7329
Closed

useless-super-delegation when overriding Exception to have different default argument #7319

jace opened this issue Aug 18, 2022 · 6 comments · Fixed by #7329
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@jace
Copy link

jace commented Aug 18, 2022

Bug description

# pylint: disable=missing-module-docstring,missing-class-docstring
class CustomError(Exception):
    def __init__(self, message="default"):
        super().__init__(message)

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:3:4: W0235: Useless super delegation in method '__init__' (useless-super-delegation)

Expected behavior

No error, because this is not a useless super delegation. The method signature is different. A default value has been introduced. (Also discussed in #839 from which the rule was introduced).

Pylint version

pylint 2.14.5
astroid 2.11.7
Python 3.9.13 (main, Aug 11 2022, 13:40:36)
[Clang 13.1.6 (clang-1316.0.21.2.5)]

OS / Environment

macOS 12.4

Additional dependencies

No response

@jace jace added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 18, 2022
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue. I'm going to close as a duplicate of #7287

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 18, 2022
@mbyrnepr2
Copy link
Member

Perhaps this one should be treated separately/re-opened because the behaviour looks different to #7287.
I think it should be ok for the subclass to pass its instance variables to the Exception since they are added to the args variable in the parent:

(venv310) Marks-MacBook-Air-2:programming markbyrne$ cat ex1.py 
class CustomError(Exception):
    def __init__(self, a="aa", b="bb", c="cc"):
        super().__init__(a, b, c)


print(CustomError().args)
raise CustomError()
(venv310) Marks-MacBook-Air-2:programming markbyrne$ python ex1.py 
('aa', 'bb', 'cc')
Traceback (most recent call last):
  File "/Users/markbyrne/programming/ex1.py", line 7, in <module>
    raise CustomError()
__main__.CustomError: ('aa', 'bb', 'cc')

Let me know if any disagreement on re-opening!

@mbyrnepr2 mbyrnepr2 reopened this Aug 20, 2022
@jacobtylerwalls
Copy link
Member

@mbyrnepr2 would you happen to have capacity to have a look if this depends on Exception e.g. on built-ins? If so it might be an astroid brain problem for those specific builtins.

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) and removed Duplicate 🐫 Duplicate of an already existing issue labels Aug 21, 2022
@jacobtylerwalls jacobtylerwalls changed the title "Useless super delegation" rule is not thorough useless-super-delegation when overriding Exception to have different default argument Aug 21, 2022
@mbyrnepr2
Copy link
Member

Sure! I should have time later in the day. However if you have an itch to look into it please feel free.

@jacobtylerwalls
Copy link
Member

(Sorry, I was just on a laptop where I didn't feel like cloning astroid to poke around.)

I think this explains why builtins like Exception are causing issues:
https://github.com/PyCQA/astroid/blob/16530f78c13863f584abcd874de9070d6f275072/astroid/nodes/node_classes.py#L625-L631

I can pick it up.

@mbyrnepr2
Copy link
Member

Fab @jacobtylerwalls!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants