mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (#3615)
This commit is contained in:
parent
a6bb313c70
commit
30b61b51e0
3 changed files with 25 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
import test.support
|
||||
from ctypes import *
|
||||
|
||||
class AnonTest(unittest.TestCase):
|
||||
|
|
@ -35,6 +36,18 @@ class AnonTest(unittest.TestCase):
|
|||
{"_fields_": [],
|
||||
"_anonymous_": ["x"]}))
|
||||
|
||||
@test.support.cpython_only
|
||||
def test_issue31490(self):
|
||||
# There shouldn't be an assertion failure in case the class has an
|
||||
# attribute whose name is specified in _anonymous_ but not in _fields_.
|
||||
|
||||
# AttributeError: 'x' is specified in _anonymous_ but not in _fields_
|
||||
with self.assertRaises(AttributeError):
|
||||
class Name(Structure):
|
||||
_fields_ = []
|
||||
_anonymous_ = ["x"]
|
||||
x = 42
|
||||
|
||||
def test_nested(self):
|
||||
class ANON_S(Structure):
|
||||
_fields_ = [("a", c_int)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue