sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.5k stars 65 forks source link

raise 'instance-method-first-arg-name' by mistake on inner functions #370

Closed makpia closed 5 months ago

makpia commented 11 months ago

Checklist

Description

if

then all functions defined inside the method will be treated as instance method by mistake, so sourcery will check if the first parameter name is 'self'

in the following code example, sourcery reports 'instance-method-first-arg-name' error on function 'inner_func'

Code snippet that reproduces issue

from typing import Callable

class C:
    def f(self,
        func: Callable[[int], int] = lambda x: x if x > 1 else 0
    ) -> None:
        def inner_func(a: int) -> int:
            return a
        return 

Debug Information

IDE Version:

vs code 1.80.0

Sourcery Version:

1.6.0

Operating system and Version:

windows 11

Hellebore commented 11 months ago

Thanks for raising this - have reproduced it

ruancomelli commented 6 months ago

Hello, @makpia!

I believe this has been fixed with recent changes in how we analyze nested functions. Can you please upgrade Sourcery to the latest version (v1.15.0) and test this again?

ruancomelli commented 5 months ago

Closing this issue since this issue was fixed in the latest Sourcery releases - please reopen it in case it happens again for you :smile: