Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Description
Bug report
I noticed recently that Setuptools CI started failing for Python 3.12.0a7 with a SystemError that is difficult to understand:
SystemError: <built-in method startswith of str object at 0x7fe399991298> returned a result with an exception set
At a first glance this error does not make much sense because str.startswith is a built-in method in a built-in data structure. I am struggling to see how it can have an exception set attached to the result.
I managed to create the following simplified reproducer:
dockerrun--rm-itpython:3.12.0a7-bullseyePython3.12.0a7 (main, Apr122023, 14:13:09) [GCC10.2.120210110] onlinuxType"help", "copyright", "credits"or"license"formoreinformation. >>>classDistribution: ... @property ... defversion(self): ... try: ... returnself._version ... exceptAttributeErrorase: ... # ... complex code omitted for the sake of simplification ... ... raiseValueError("Missing Version") ... def__getattr__(self, attr): ... ifattr.startswith("_"): ... raiseAttributeError(attr) ... # ... complex code omitted for the sake of simplification ... ... return42 ... >>>dist=Distribution() >>>dist.versionTraceback (mostrecentcalllast): File"<stdin>", line5, inversionFile"<stdin>", line11, in__getattr__AttributeError: _version. Didyoumean: 'version'? Duringhandlingoftheaboveexception, anotherexceptionoccurred: Traceback (mostrecentcalllast): File"<stdin>", line8, inversionValueError: MissingVersionTheaboveexceptionwasthedirectcauseofthefollowingexception: Traceback (mostrecentcalllast): File"<stdin>", line1, in<module>File"<stdin>", line10, in__getattr__SystemError: <method'startswith'of'str'objects>returnedaresultwithanexceptionset>>>The error seems to be related to the combination of the following factors:
- A
propertyis being used1 - The property getter access an undefined attribute and triggers
__getattr__ __getattr__raises anAttributeError- The property getter is supposed to catch the
AttributeErrorexception and raise a different exeception.
My expectation is that the SystemError never gets triggered with the confusing message. Instead the example should end up with a ValueError.
Please note that the example is very simplified. For the realistic implementation please consider pkg_resources.Distribution.
Your environment
- CPython versions tested on: 3.12.0a7
- Operating system and architecture:
Reproducer tested on both Ubuntu 20.04.6 LTS machine andpython:3.12.0a7-bullseyecontainer
Problem also identified in GitHub Actions runners: ubuntu-latest, macos-latest, windows-latest (see https://github.com/pypa/setuptools/actions/runs/4710601389?pr=3893) for Python 3.12-dev.
Footnotes
If we replace the property with a regular method, the example works as expected. ↩