da-woods schrieb am 23.04.20 um 20:47: > On closer inspection I believe both are following Python behaviour (and > thus behaving correctly). In Python any > `__name_preceded_by_double_underscores` used within a class ends up looking > up `_Classname__name_preceded_by_double_underscores`. Therefore in case 1 > it's looking up `_Bar__foo` and not finding it.
Hmm, right. Py3.6 gives me this: >>> class T: ... def f(self): return __xyz ... >>> __xyz = 2 >>> T().f() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in f NameError: name '_T__xyz' is not defined > Therefore, I think it is the "correct" thing to do. > > This proved a pain with the `__pyx_unpickle` functions that Cython > generates. In the end I just disabled it for `__pyx_` names, which I guess > could be called hypocrisy . Yeah, it seems correct then. Meaning, new code will benefit from the lack of differences with normal Python behaviour. The question is: how bad is it for existing code, and how can we either keep things working or make it easy for users to adapt? Should we implement some kind of fallback lookup that still finds unmangled global names if they exist? I mean, double-underscore names are not entirely unheard of in C code and C libraries. The Python behaviour redners their usage from within classes more difficult. Stefan _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel