-
Notifications
You must be signed in to change notification settings - Fork 78
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
instance-method-first-arg-name triggers on unrelated global funcs #328
Comments
Hi @amogorkon , Thanks a lot for reporting this issue. Unfortunately, I haven't managed to reproduce it yet. Do you have an idea what might influence this? Which IDE are you using? Thanks for your help. Reka |
Weird.
Nothing. It's remarkably unremarkable. Here it is:
Maybe sourcery is confused by its placement directly below a class with the first parameter not being annotated?
VSC.
I haven't tried that. I turned off the sourcery suggestion for this error after reporting the issue.. if you tell me how to re-enable it, I can do more experiments to help you out. |
I'm also using VSCode and get the same issue. It must be related to previous code, as I copied my class and the global function below it into a new file but the error is now gone. I can't work it out. It seems to appear if I keep all my imports at the top but when I delete one, it goes away. There's a mix of standard. 3rd party, and local imports. No idea ... It does not occur if I use |
I've had another look at this and I can't reproduce it. If someone has a complete |
I have found a simple way to perfectly reproduce the issue on my setup, without failure. Steps to reproduce: Create a new text file in Visual Studio Code. Select Python as the language. Add a dummy function to the empty text file, like the following:
Add a dummy class before the function, like so:
And the bug will be triggered. Please fix this stupid bug. It is very annoying. |
This is a bit more complicated example, I have defined a function first, and added a dummy class before it, the function has its parameters annotated, but the bug still triggers. This would rule out that annotations are related in anyway.
Closing the editor and reopening it, the bug goes away. Note to reproduce the issue, you can't just copy paste the full code, or paste the function first and the class second, that won't trigger the bug. You have to type the class definition by hand above the definition of an existing function in a script, in order to trigger the bug. If you paste a function, and then type a class definition with a method above the function definition in a script, the bug will be triggered. |
Thanks @Estrangeling, with that I've been able to reproduce and track it down. There are two issues working in tandem here: first, the refactoring is triggered specifically when this code is written (note the syntax error) class Example:
def
def something(a):
... So something about the parser is misattributing the function when it sees this syntax error. The second problem is that we cache refactorings to avoid re-computing them, and in this case the cached refactoring persists until you restart the IDE. Thanks for your help, and I'll take a look at this today - look out for a fix in the next release. |
A quick update - I'm still working on this (turns out to be quite a low-level bug) so unfortunately it didn't make it into yesterday's release. |
Checklist
Description
In some cases when a global function follows a class with methods, sourcery suggests to add
self
to the arg or change the first parameter to "self", although it's not a method. I attached a screenshot with the issue.Code snippet that reproduces issue
Debug Information
IDE Version:
Version: 1.76.2 (user setup)
Commit: ee2b180d582a7f601fa6ecfdad8d9fd269ab1884
Datum: 2023-03-14T17:55:54.936Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
Betriebssystem: Windows_NT x64 10.0.19045
Sandkasten: No
Sourcery Version:
v1.0.9
Operating system and Version:
Windows 10
The text was updated successfully, but these errors were encountered: