Open PC-Killer opened 3 months ago
This is intended behaviour. Explanation: https://docs.python.org/3.12/faq/programming.html#i-try-to-use-spam-and-i-get-an-error-about-someclassname-spam.
Hmm...... But I'm trying to call a function outside the class. Why should it "mangled"? Shouldn't it happen only I am trying to get a class method?
Anonymous @.***
------------------ 原始邮件 ------------------ 发件人: "Kirill @.>; 发送时间: 2024年6月1日(星期六) 晚上7:19 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [python/cpython] Unexpected NameError (Issue #119901)
This is intended behaviour. Explanation: https://docs.python.org/3.12/faq/programming.html#i-try-to-use-spam-and-i-get-an-error-about-someclassname-spam.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Hmm...... But I'm trying to call a function outside the class. Why should it "mangled"? Shouldn't it happen only I am trying to get a class method?
In an ideal world, yes. But how do we determine that some lookups inside the class body are class-specific? These slow down performance due to additional lookups and just slightly increase user experience. To summarize, just don't name your functions with double leading underscores. :)
That's perhaps the best solution:) But, could the interpreter tell the user the problem when it show the error? I don't think showing error needs to be as fast as possible :)
Anonymous @.***
------------------ 原始邮件 ------------------ 发件人: "Kirill @.>; 发送时间: 2024年6月1日(星期六) 晚上7:31 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [python/cpython] Unexpected NameError (Issue #119901)
Hmm...... But I'm trying to call a function outside the class. Why should it "mangled"? Shouldn't it happen only I am trying to get a class method?
In an ideal world, yes. But how do we determine that some lookups inside the class body are class-specific? These slow down performance due to additional lookups and just slightly increase user experience. To summarize, just don't name your functions with double leading underscores. :)
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
That's perhaps the best solution:) But, could the interpreter tell the user the problem when it show the error? I don't think showing error needs to be as fast as possible :)
Yes, that's sounds reasonable for me.
cc @pablogsal Do you think it's worth improving the error message for "NameError" in such cases?
I can take a look this weekend 👍
I want to extend this issue. This code:
def __a():
print("A")
class A:
def b(self):
self.__a()
a = A()
a.b()
throws another error:
AttributeError: 'A' object has no attribute '_A__a'
If NameError
is planning to be improved, this should be also fixed
Yeah they normally go in tandem. I will let you know what we decide here once I have some time to play with this
Bug report
Bug description:
Here is the code:
It was expected to show a short message "A". However, I got a NameError:
It seems that the name had been translated in an unexpected way.
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux