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

Added deprecated decorators check #4513

Merged
merged 15 commits into from
May 27, 2021

Conversation

matusvalo
Copy link
Collaborator

@matusvalo matusvalo commented May 25, 2021

Steps

  • 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.

Description

This PR introduces new check for deprecated decorators:

$ cat test.py
from abc import abstractproperty

@abstractproperty
def foo():
        pass

$ pylint test.py
************* Module test
test.py:41:0: C0104: Disallowed name "foo" (disallowed-name)
test.py:40:0: W1513: Using deprecated decorator abc.abstractproperty() (deprecated-decorator)

------------------------------------------------------------------
Your code has been rated at 3.33/10 (previous run: 3.33/10, +0.00)

Type of Changes

Type
πŸ› Bug fix
βœ“ ✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Related Issue

Closes #4429

@matusvalo
Copy link
Collaborator Author

Hm checks are failing. I need to investigate. For now I will put MR as draft...

@matusvalo matusvalo marked this pull request as draft May 25, 2021 20:24
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for this ! I nitpicked a little about typing and formatting. Maybe you could add a little functional tests with an @abc.abstractclassmethod too. But mostly worry about your work environment :) So many deprecations to take care of ! Are you okay with the legacy code πŸ˜‰ ?

pylint/checkers/deprecated.py Outdated Show resolved Hide resolved
pylint/checkers/deprecated.py Show resolved Hide resolved
pylint/checkers/stdlib.py Outdated Show resolved Hide resolved
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Thanks for working on that! I did look at the pytest errors. Most fail because they use abc.abstractproperty πŸ˜„ In two cases the decorator is uninferable which cause an error.

class Foo:
    def __init__(self):
        self._baz = 84

    def method(self):
        return self._baz

    @method.setter  # Invalid decorator
    def method(self, value):
        self._baz = value

This isn't valid python as method doesn't have a setter (it would require the @property decorator), but I think that we shouldn't raise an unexpected error for it never the less.

I would appreciate if you could add this as a test case as well.

pylint/checkers/deprecated.py Outdated Show resolved Hide resolved
if isinstance(next(node.get_children()), astroid.Call):
qname = next(node.get_children()).func.inferred()[0].qname()
else:
qname = next(next(node.get_children()).infer()).qname()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure you can be certain that the result will always have a qname() method here.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of .infer() try safe_infer from the pylint/checkers/utils.py module.

pylint/checkers/stdlib.py Outdated Show resolved Hide resolved
matusvalo and others added 9 commits May 26, 2021 06:18
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@coveralls
Copy link

coveralls commented May 26, 2021

Coverage Status

Coverage increased (+0.006%) to 91.847% when pulling 8f2173a on matusvalo:deprecated_decorators into 5805a73 on PyCQA:master.

@matusvalo matusvalo marked this pull request as ready for review May 27, 2021 18:26
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for this checker ! It will be available in 2.9.0 which should release shortly.

@Pierre-Sassoulas Pierre-Sassoulas added Checkers Related to a checker Enhancement ✨ Improvement to a component labels May 27, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.8.3 milestone May 27, 2021
@Pierre-Sassoulas
Copy link
Member

Merging as @cdce8p comments were taken into account.

@Pierre-Sassoulas Pierre-Sassoulas merged commit 6d449f9 into pylint-dev:master May 27, 2021
@matusvalo matusvalo deleted the deprecated_decorators branch May 27, 2021 19:01
@matusvalo
Copy link
Collaborator Author

Thank you @Pierre-Sassoulas !

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.8.3, 2.9.0 May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect deprecated decorators
4 participants