Skip to content

Commit b561d0f

Browse files
committed
test: expect aenum's NameError on _Addendum on GraalPy (#2083)
GraalPy's ImportStarNode.doImport handles an __all__ name missing from the module in the same AttributeError handler as a missing __all__, and that fallback skips _ names. With builtins.NoneType bound, aenum's star import of _common therefore succeeds there without _Addendum, and _constant fails with NameError instead of CPython's AttributeError. The premise test now accepts either exception from the child, and on GraalPy pins the NameError on '_Addendum', so it still notices aenum binding NoneType itself, and notices GraalPy matching CPython.
1 parent 61bb4ba commit b561d0f

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

‎tests/utilities/test_compat_aenum_nonetype_1958_unit.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
:mod:`pcapkit.utilities.compat` binds the name in ``aenum._common`` and imports
1010
aenum again.
1111
12+
GraalPy fails the same import differently (#2083): its ``from ... import *``
13+
treats a name missing from ``__all__`` as if ``__all__`` were absent, so it binds
14+
the module's public names and none of its ``_`` ones, and aenum then fails with
15+
:exc:`NameError` on ``_Addendum`` instead.
16+
1217
Each test runs a fresh interpreter, so that this module's own imports have not
1318
loaded aenum already. :class:`TheAenumPremiseTests` binds the builtin on any
1419
interpreter and shows aenum still fails without the fix, which tells when an
@@ -32,6 +37,9 @@
3237
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
3338
#: Whether the shim in pcapkit/utilities/compat.py runs here.
3439
ON_PYPY = sys.implementation.name == 'pypy'
40+
#: Whether a name missing from ``__all__`` fails a star import with :exc:`NameError`
41+
#: on a later ``_`` name rather than with :exc:`AttributeError` (#2083).
42+
ON_GRAALPY = sys.implementation.name == 'graalpy'
3543

3644

3745
def run_child(code: 'str') -> 'subprocess.CompletedProcess[str]':
@@ -51,16 +59,28 @@ def test_aenum_alone_fails_on_the_builtin(self) -> 'None':
5159
builtins.NoneType = type(None)
5260
try:
5361
import aenum
54-
except AttributeError as error:
55-
print('FAILED', error)
62+
except (AttributeError, NameError) as error:
63+
print('FAILED', type(error).__name__, error)
5664
else:
5765
print('IMPORTED')
5866
''')
5967
self.assertEqual(proc.returncode, 0, proc.stderr)
6068
self.assertEqual(proc.stdout.split()[0], 'FAILED',
6169
'aenum imports with builtins.NoneType bound; the shim in '
6270
'pcapkit/utilities/compat.py may no longer be needed')
63-
self.assertIn("'NoneType'", proc.stdout)
71+
if ON_GRAALPY:
72+
# NOTE: GraalPy's ``ImportStarNode.doImport`` (oracle/graalpython,
73+
# ``graalpython/com.oracle.graal.python/src/com/oracle/graal/python/
74+
# nodes/bytecode/ImportStarNode.java``) catches the AttributeError of
75+
# a missing ``__all__`` name in the handler for a missing ``__all__``,
76+
# whose module-dict fallback skips ``_`` names. So ``_common``'s
77+
# star import binds no ``_Addendum`` and ``_constant`` fails on it
78+
# (#2083). An AttributeError here means GraalPy now matches CPython.
79+
self.assertEqual(proc.stdout.split()[1], 'NameError', proc.stdout)
80+
self.assertIn("'_Addendum'", proc.stdout)
81+
else:
82+
self.assertEqual(proc.stdout.split()[1], 'AttributeError', proc.stdout)
83+
self.assertIn("'NoneType'", proc.stdout)
6484

6585

6686
@unittest.skipUnless(ON_PYPY, 'the shim runs on PyPy alone')

0 commit comments

Comments
 (0)