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

Similarities checker doesn't ignore decorators with "ignore-signatures" option enabled #4839

Closed
mhumetskyi opened this issue Aug 13, 2021 · 1 comment · Fixed by #4840
Closed
Labels
duplicate-code Related to code duplication checker Enhancement ✨ Improvement to a component
Milestone

Comments

@mhumetskyi
Copy link
Contributor

mhumetskyi commented Aug 13, 2021

Bug description

Function decorators are not ignored by the similarities checker when the "ignore-signatures" option is enabled.

For me, it makes sense to ignore them as well as parameterized decorators might be applied to many different functions and look almost the same. For example, some frameworks use decorators to make declare API handlers functions like in the following example:

app = FastAPI()

@app.put(
    "/get-something", 
    status_code=200, 
    responses={
        status.HTTP_400_BAD_REQUEST: {
            "model": HTTPExceptionResponseModel,
        },
        status.HTTP_404_NOT_FOUND: {
            "model": HTTPExceptionResponseModel,
        },
        status.HTTP_409_CONFLICT: {
            "model": HTTPExceptionResponseModel,
        },
    },
)
def get_something(task_id: str, response: Response):
    pass

It should be easy to fix it, I am going to open PR, but the main question is is it a bug or it was intentionally implemented this way?

Steps to reproduce

Given multiple files:

module\
    __init__.py
    a.py
    b.py

a.py:

@decorator1(
    arg1=1,
    arg2="2",
    arg3=True,
    arg4=None,
    arg5="",
)
def func_a():
    """Example func."""

b.py:

@decorator1(
    arg1=1,
    arg2="2",
    arg3=True,
    arg4=None,
    arg5="",
)
def func_b():
    """Example func."""

Command used

pylint --disable=all --enable=similarities --ignore-signatures=yes module

Pylint output

************* Module module.b
module/b.py:1:0: R0801: Similar lines in 2 files
==module.a:0
==module.b:0
@decorator1(
    arg1=1,
    arg2="2",
    arg3=True,
    arg4=None,
    arg5="",
) (duplicate-code)

------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 7.50/10, -2.50)

Expected behavior

duplicate-code error shouldn't be reported in this case.

Pylint version

pylint 2.9.6
astroid 2.6.6
Python 3.8.2 (default, Jun  8 2021, 11:59:35)
@mhumetskyi mhumetskyi added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component duplicate-code Related to code duplication checker and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 13, 2021
@Pierre-Sassoulas
Copy link
Member

It makes sense, thank you for opening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate-code Related to code duplication checker Enhancement ✨ Improvement to a component
Projects
None yet
2 participants