Skip to content

Commit f1e8732

Browse files
committed
Enable tests in test_c_struct_sequence.py for Python 3.11, 3.12. Add note about unnamed fields failure in Python 3.9, 3.10.
1 parent d840569 commit f1e8732

3 files changed

Lines changed: 61 additions & 50 deletions

File tree

doc/sphinx/source/struct_sequence.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ These are fields unavailable to Python code but available to C code.
666666
The rules using these are quite involved and the Python documentation is poor at describing them so I'll do my best
667667
here.
668668

669+
.. note::
670+
671+
Unnamed fields doe not appear to work in Python versions prior to 3.11 with the following compile time error:
672+
673+
``E ImportError: dlopen(... cStructSequence.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_PyStructSequence_UnnamedField'``
674+
669675
The rules appear to be:
670676

671677
* Unnamed fields in the `PyStructSequence_Field`_ *must* follow named fields.

src/cpy/StructSequence/cStructSequence.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ ExcessNT_create(PyObject *Py_UNUSED(module), PyObject *args, PyObject *kwds) {
383383
* Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ...
384384
*
385385
* This is Python 3.11+ specific code.
386+
* Earlier versions give this compile time error:
387+
* E ImportError: dlopen(...cStructSequence.cpython-310-darwin.so, 0x0002): \
388+
* symbol not found in flat namespace '_PyStructSequence_UnnamedField'
386389
*/
387390
#if PY_VERSION_HEX >= 0x030B0000
388391

@@ -481,8 +484,10 @@ static PyMethodDef cStructSequence_methods[] = {
481484
"Example of getting a transaction."},
482485
{"ExcessNT_create", (PyCFunction) ExcessNT_create, METH_VARARGS | METH_KEYWORDS,
483486
"Create a ExcessNT from the given values."},
484-
/* Python 3.11 specific code. Earlier versions have a problem with:
485-
* symbol not found in flat namespace '_PyStructSequence_UnnamedField'
487+
/* Python 3.11+ specific code.
488+
* Earlier versions give this compile time error:
489+
* E ImportError: dlopen(...cStructSequence.cpython-310-darwin.so, 0x0002): \
490+
* symbol not found in flat namespace '_PyStructSequence_UnnamedField'
486491
*/
487492
#if PY_VERSION_HEX >= 0x030B0000
488493
{"NTWithUnnamedField_create", (PyCFunction) NTWithUnnamedField_create, METH_VARARGS | METH_KEYWORDS,

tests/unit/test_c_struct_sequence.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -613,54 +613,54 @@ def test_excess_nt_field_three_index_missing():
613613
assert err.value.args[0] == 'tuple index out of range'
614614

615615

616-
# @pytest.mark.skipif(not (sys.version_info.minor <= 11), reason='Python <= 3.11')
617-
# def test_nt_with_unnamed_field_create_dir_3_11_and_before():
618-
# ntuf = cStructSequence.NTWithUnnamedField_create('foo', 'bar', 'baz')
619-
# print()
620-
# pprint.pprint(dir(ntuf))
621-
# assert dir(ntuf) == [
622-
# '__add__',
623-
# '__class__',
624-
# '__class_getitem__',
625-
# '__contains__',
626-
# '__delattr__',
627-
# '__dir__',
628-
# '__doc__',
629-
# '__eq__',
630-
# '__format__',
631-
# '__ge__',
632-
# '__getattribute__',
633-
# '__getitem__',
634-
# '__getnewargs__',
635-
# '__getstate__',
636-
# '__gt__',
637-
# '__hash__',
638-
# '__init__',
639-
# '__init_subclass__',
640-
# '__iter__',
641-
# '__le__',
642-
# '__len__',
643-
# '__lt__',
644-
# '__match_args__',
645-
# '__module__',
646-
# '__mul__',
647-
# '__ne__',
648-
# '__new__',
649-
# '__reduce__',
650-
# '__reduce_ex__',
651-
# '__repr__',
652-
# '__rmul__',
653-
# '__setattr__',
654-
# '__sizeof__',
655-
# '__str__',
656-
# '__subclasshook__',
657-
# 'count',
658-
# 'field_one',
659-
# 'index',
660-
# 'n_fields',
661-
# 'n_sequence_fields',
662-
# 'n_unnamed_fields'
663-
# ]
616+
@pytest.mark.skipif(not (11 <= sys.version_info.minor <= 12), reason='Python 3.11, 3.12')
617+
def test_nt_with_unnamed_field_create_dir_3_11_and_before():
618+
ntuf = cStructSequence.NTWithUnnamedField_create('foo', 'bar', 'baz')
619+
print()
620+
pprint.pprint(dir(ntuf))
621+
assert dir(ntuf) == [
622+
'__add__',
623+
'__class__',
624+
'__class_getitem__',
625+
'__contains__',
626+
'__delattr__',
627+
'__dir__',
628+
'__doc__',
629+
'__eq__',
630+
'__format__',
631+
'__ge__',
632+
'__getattribute__',
633+
'__getitem__',
634+
'__getnewargs__',
635+
'__getstate__',
636+
'__gt__',
637+
'__hash__',
638+
'__init__',
639+
'__init_subclass__',
640+
'__iter__',
641+
'__le__',
642+
'__len__',
643+
'__lt__',
644+
'__match_args__',
645+
'__module__',
646+
'__mul__',
647+
'__ne__',
648+
'__new__',
649+
'__reduce__',
650+
'__reduce_ex__',
651+
'__repr__',
652+
'__rmul__',
653+
'__setattr__',
654+
'__sizeof__',
655+
'__str__',
656+
'__subclasshook__',
657+
'count',
658+
'field_one',
659+
'index',
660+
'n_fields',
661+
'n_sequence_fields',
662+
'n_unnamed_fields',
663+
]
664664

665665

666666
@pytest.mark.skipif(not (sys.version_info.minor >= 13), reason='Python 3.13+')

0 commit comments

Comments
 (0)