Skip to content

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

@hutsulyk

Description

@hutsulyk

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentduplicate-codeRelated to code duplication checker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions