r/Python • u/JohnVonachen • Oct 21 '26
Discussion I have found PyCharm lacking
Correct me if I am wrong but a normal thing to do is import a module and possibly create new attributes on an object instantiated from such. For some reason PyCharm recognizes this as a warning. I normally like the JetBrains IDEs because when you get rid of all the static analysis warnings you know you are kosher, to some degree. I can't get rid of this warning. Load up the same code in VS Code and it's no problem.
33
u/wRAR_ Oct 21 '26
a normal thing to do is import a module and possibly create new attributes on an object instantiated from such
No, this makes no sense.
-7
u/JohnVonachen Oct 21 '26
Just like in JavaScript at runtime you can create new attributes on existing objects. This is a vary normal thing to do.
Unresolved attribute reference 'left' for class 'Canvas' def __init__(self): super().__init__() self.canvas = tk.Canvas(self, background="black") self.canvas.left = 08
u/wRAR_ Oct 21 '26
While this is indeed a normal thing to do it's also wrong and you should get a warning from your linter and/or your type checker.
Consider disabling linting if you like writing unidiomatic code.
-6
u/JohnVonachen Oct 21 '26
I don't agree.
5
u/ProsodySpeaks Oct 22 '26
You don't get to have an opinion on what is idiomatic.
You can write whatever code you like, but you are not personally able to define what best practices are.
1
u/JohnVonachen Oct 22 '26
Relax. I’m on board. Other posters have responded and gave good reasons. We’re all good.
2
u/vintergroena Oct 22 '26 •
![]()
This is called monkey patching. It's possible but generally considered an antipattern.
3
u/JohnVonachen Oct 22 '26 edited Oct 22 '26
Good to know. Can be used for stubbing for testing. This has been the most useful reply yet. A google search on python monkey patching told me everything I needed to know. Thanks.
14
u/lolcrunchy Oct 21 '26
Ok what was the code and what was the warning?
1
u/JohnVonachen Oct 21 '26
Unresolved attribute reference 'left' for class 'Canvas' def __init__(self): super().__init__() self.canvas = tk.Canvas(self, background="black") self.canvas.left = 010
u/lolcrunchy Oct 21 '26
That's probably because there is no attribute called 'left' for the 'Canvas' class. Looks like PyCharm is helping you.
-3
u/JohnVonachen Oct 21 '26
I know there's no attribute called 'left'. I declared a new one. Have you never done something like that? People do it all the time in JavaScript. It's a feature of the language, not a problem.
6
u/lolcrunchy Oct 21 '26
Oh then you probably want to store it in self.canvas_left. It's unrecommended to use imported objects that you didn't write outside of their intended API. That's why there's a warning.
Anyways, JUST like vs code and every other IDE, you can customize PyCharm instead of getting mad at the default settings.
Settings -> Editor -> Inspections -> Python -> Unresolved References
0
u/JohnVonachen Oct 21 '26
That turns it off on they whole system for all projects. Not what I wanted.
3
2
u/lolcrunchy Oct 21 '26
Press Ctrl+Alt+S for project settings and change the inspection there to keep it for just that project.
Or put the comment #NOQA on the line to tell all linters and checkers to ignore rules on that line.
2
u/sausix Oct 21 '26
You declared it the wrong way. You will solve with OOP properly while following Python standards.
4
5
4
u/lolcrunchy Oct 21 '26
Fyi all the specifics for how to change PyCharm settings that I've provided in this thread I got by googling...
1
u/JohnVonachen Oct 21 '26
I did all that googling also and none of the suggestions worked. I would not have posted this if I had not done all the homework. It's neither here nor there because many people are telling me this is a poor decision and why. Thanks for the help.
8
18
u/Fartstream Oct 21 '26
stop yelling into the void and actually provide an example. low effort post