Should the editor catch this?
First, allow me to begin with saying, I'm a fairly novice Python user. I've been learning over the last year and loving it, but I have no programming background whatsoever. I realize there are (and have been) instances where a CS background really would have helped. I'm hoping this isn't one of those 'obvious' cases.
I was creating a class when I started to write something resembling the following snippet:
I realized that I was referencing self.morestuff before I had instantiated it. To run this results in an AttributeError: test instance has no attribute 'morestuff'.
My question is should the PyCharm editor have caught this? Normally if I refer to a variable before instantiating it, the editor complains but in this case the . Am I correct in assuming this is a bug? If so, I'll submit it to YouTrack.
Attachment(s):
unresolved_reference.jpg
unresolved_reference.jpg
Please sign in to leave a comment.

Hello Marcel,
No, this isn't really a bug. PyCharm's analysis is performed locally for
each method, and while for a regular variable it can detect cases of use
before assignment, for a method it may be possible that the instance variable
is assigned from some other place (another method or code outside of a class),
and there is no 100% reliable way to check that it's not. Because of that,
we don't highlight errors in this case.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thank you! I'm glad I asked before submitting a trac ticket.