You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve NameError error suggestion for instances #99139
If we are in a method and a NameError is raised for the name X, first check if X is an attribute of the instance as self.X is likely more common than whatever closest match we find in the scope.
Looks awesome! Lots of begginers going to love that!
What about a case like:
classSome:
x=1@classmethoddefmethod(cls):
x+2# Should be cls.x
Do we care to support it? 🤔
Thanks for the proposal!
I will consider it but is unlikely that will happen as we are not interested in supporting all possible variations of this, specially since the name of the variable here (cls) is less standardised than "self" and is less common.
Also, this will force us to distinguish the type of function to avoid inspecting random variables called "cls".
Activity
pythongh-99139: Improve NameError error suggestion for instances
hauntsaninja commentedon Nov 6, 2022
This is great! I learnt C++ before Python so I used to forget self all the time when I first started programming in Python. Thank you!
gh-99139: Improve NameError error suggestion for instances (#99140)
sobolevn commentedon Nov 6, 2022
Looks awesome! Lots of begginers going to love that!
What about a case like:
Do we care to support it? 🤔
pablogsal commentedon Nov 6, 2022
Thanks for the proposal!
I will consider it but is unlikely that will happen as we are not interested in supporting all possible variations of this, specially since the name of the variable here (cls) is less standardised than "self" and is less common.
Also, this will force us to distinguish the type of function to avoid inspecting random variables called "cls".
EwoutH commentedon Nov 7, 2022
Thanks for this, and improving error messages in general!