Skip to content

Don't emit super-init-not-called for abstract __init__ methods #7227

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

Merged
merged 1 commit into from
Jul 31, 2022

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
🐛 Bug fix

Description

Closes #3975.

@DanielNoord DanielNoord added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 25, 2022
@DanielNoord DanielNoord added this to the 2.15.0 milestone Jul 25, 2022
@coveralls
Copy link

coveralls commented Jul 25, 2022

Pull Request Test Coverage Report for Build 2770142168

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 95.244%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/classes/class_checker.py 2 94.61%
Totals Coverage Status
Change from base Build 2770034625: -0.01%
Covered Lines: 16822
Relevant Lines: 17662

💛 - Coveralls

@Pierre-Sassoulas
Copy link
Member

I have no idea why the coverage went down on the three lines that are not covered anymore. coverall issue ?

@github-actions

This comment has been minimized.

@vivi90
Copy link

vivi90 commented Jul 25, 2022

#3975 (comment)

@DanielNoord
Copy link
Collaborator Author

I think this is because "living" objects don't have a body and thus are considered abstract.
This prevents them from raising inference errors later on.

See also change to the ctypes test

@DanielNoord
Copy link
Collaborator Author

@Pierre-Sassoulas can this be merged with the decreased coverage?

@Pierre-Sassoulas
Copy link
Member

Maybe it's possible to cleanup or to add a test that cover this ? If it's too complicated I'm ok with merging as is, the primer indicate the change will remove a lot of false positives.

@vivi90
Copy link

vivi90 commented Jul 27, 2022

I think, it might be an very bad idea to change pylints current behaviour for this case, because of: #3975 (comment)

@Pierre-Sassoulas
Copy link
Member

Look like the fail is genuine and was hidden by the broken main before.

@github-actions

This comment has been minimized.

@@ -2061,9 +2061,6 @@ def _check_init(self, node: nodes.FunctionDef, klass_node: nodes.ClassDef) -> No

if decorated_with(node, ["typing.overload"]):
continue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines below are no longer necessary now that we skip object.__init__ because of its abstractness.

return "Implemented"


class DerivedFrom(UnknownParent): # [undefined-variable]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a regression test for the coverage that dropped. We try to infer bases which fails here.

@github-actions
Copy link
Contributor

🤖 Effect of this PR on checked open source code: 🤖

Effect on django:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'UploadFileException' is not called
    https://github.com/django/django/blob/main/django/core/files/uploadhandler.py#L36
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/core/serializers/base.py#L66
  3. super-init-not-called:
    init method from base class 'TextIOBase' is not called
    https://github.com/django/django/blob/main/django/core/management/base.py#L150
  4. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/middleware/csrf.py#L132
  5. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/middleware/csrf.py#L167
  6. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/template/base.py#L102
  7. super-init-not-called:
    init method from base class 'LookupError' is not called
    https://github.com/django/django/blob/main/django/db/migrations/exceptions.py#L43
  8. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/db/models/sql/datastructures.py#L15
  9. super-init-not-called:
    init method from base class 'str' is not called
    https://github.com/django/django/blob/main/django/conf/__init__.py#L52

Effect on flask:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'KeyError' is not called
    https://github.com/pallets/flask/blob/main/src/flask/debughelpers.py#L19
  2. super-init-not-called:
    init method from base class 'AssertionError' is not called
    https://github.com/pallets/flask/blob/main/src/flask/debughelpers.py#L19

Effect on pandas:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'BaseBlockManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/managers.py#L888
  2. super-init-not-called:
    init method from base class 'BaseBlockManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/managers.py#L1694
  3. super-init-not-called:
    init method from base class 'BaseArrayManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/array_manager.py#L712
  4. super-init-not-called:
    init method from base class 'BaseArrayManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/array_manager.py#L1201
  5. super-init-not-called:
    init method from base class 'set' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/methods/test_set_index.py#L676
  6. super-init-not-called:
    init method from base class 'NotImplementedError' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/errors/__init__.py#L188
  7. super-init-not-called:
    init method from base class 'dict' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/plotting/_misc.py#L558

Effect on psycopg:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/transaction.py#L40

Effect on pytest:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'LookupError' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/fixtures.py#L792
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/mark/expression.py#L61
  3. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/argparsing.py#L207

Effect on sentry:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'InvalidRequest' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/exceptions.py#L17
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/coreapi.py#L24
  3. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/incidents/logic.py#L850
  4. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/api/client.py#L11
  5. super-init-not-called:
    init method from base class 'NodeStorage' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/nodestore/bigtable/backend.py#L33
  6. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/metrics/base.py#L10
  7. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/cache/base.py#L22
  8. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/tasks/symbolication.py#L43
  9. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/sms.py#L13
  10. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/auth.py#L79
  11. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/services.py#L251
  12. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/performance/sqlquerycount.py#L12

This comment was generated for commit 03dd537

@Pierre-Sassoulas Pierre-Sassoulas merged commit 397c170 into pylint-dev:main Jul 31, 2022
@DanielNoord DanielNoord deleted the init branch July 31, 2022 22:30
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
Projects
None yet
4 participants