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
Only on the latest Python beta version (11.b5) - found on Github actions.
Description
Disclaimer: This is probably not an actual bug and highly non-important but something which surprised me a bit and I wanted to be sure it was the expected behavior.
I wanted to match a regexp matching the names of attributes in Python(1) and I decided to use introspection to test it: check every attribute name (using "dir") for every classes I could find.
Starting on Python 3.11.0b5, I caught something I did not expect: the _distutils_hack.DistutilsMetaFinder' has an attribute named 'spec_for_test.test_distutils' which is pretty peculiar. This behavior did not exist on Python 3.11.0b4.
(1) I am aware that attribute name can be pretty much anything when someone relies on setattr.
Expected behavior
I would expect most attribute names to match the following regexp: '^[^\\d\\W]\w*$' .
How to Reproduce
None
Output
None
The text was updated successfully, but these errors were encountered:
Hi @SylvainDe , _distutils_hack relies on both setattr and getattr, so unless the interpreter spontaneously throws an error, I would not be concerned...
You mentioned that in Python 3.11.0b5 you see an error. Is this error something your code is throwing, or something that just happens without any intervention?
BTW, in other contexts you can also use the str.isidentifier function instead of creating a regex.
Hello @abravalheri , thanks for your feedback! I was just surprised by the usage of such an attribute name but it does not cause any exception to be thrown anywhere by the interpreter. The only error comes from a wrong assumption in my code parsing attribute name.
As for the str.isidentifier function, this is an excellent suggestion but my use case is slightly more tricky: I actually try to parse exception messages such as AttributeError and as such, I include the regexp for attribute name in another bigger regexp.
If having an unusual name is fine for you, it is fine for me as well and the issue can be closed.
The reason why these attributes exist is more apparent when looking at the implementation. DistutilsMetaFinder uses methods named spec_for_{name} to handle a module indicated by {name}. In order to provide special handling for tests.test_distutils, the DistutilsMetaFinder has a method spec_for_test.test_distutils (motivation in #3383). Yes, that method is abnormal, and yes, that method would be unreachable through the normal Python accessor syntax, but it works for its purposes, and it should go away when Python removes test.test_distutils.
This behavior did not exist on Python 3.11.0b4.
I suspect this change is due to a later version of Setuptools being bundled with Python, or possibly just a later version of Setuptools being loaded in your environment.
Thanks for reporting, but I believe this is working as intended (despite the smell).
setuptools version
63.2.0
Python version
Python 3.11.0b5
OS
Linux
Additional environment information
Only on the latest Python beta version (11.b5) - found on Github actions.
Description
Disclaimer: This is probably not an actual bug and highly non-important but something which surprised me a bit and I wanted to be sure it was the expected behavior.
I wanted to match a regexp matching the names of attributes in Python(1) and I decided to use introspection to test it: check every attribute name (using "dir") for every classes I could find.
Starting on Python 3.11.0b5, I caught something I did not expect: the _distutils_hack.DistutilsMetaFinder' has an attribute named 'spec_for_test.test_distutils' which is pretty peculiar. This behavior did not exist on Python 3.11.0b4.
(1) I am aware that attribute name can be pretty much anything when someone relies on setattr.
Expected behavior
I would expect most attribute names to match the following regexp: '^[^\\d\\W]\w*$' .
How to Reproduce
None
Output
None
The text was updated successfully, but these errors were encountered: