mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
[3.11] gh-96151: Use a private name for passing builtins to dataclass. This now allows for a field named BUILTIN (gh-98143) (gh-98900)
gh-96151: Use a private name for passing builtins to dataclass. This now allows for a field named BUILTIN (gh-98143)
(cherry picked from commit 29f98b46b7
)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
parent
57dd11038f
commit
ca24e496ba
3 changed files with 13 additions and 5 deletions
|
@ -231,6 +231,14 @@ class TestCase(unittest.TestCase):
|
|||
c = C('foo')
|
||||
self.assertEqual(c.object, 'foo')
|
||||
|
||||
def test_field_named_BUILTINS_frozen(self):
|
||||
# gh-96151
|
||||
@dataclass(frozen=True)
|
||||
class C:
|
||||
BUILTINS: int
|
||||
c = C(5)
|
||||
self.assertEqual(c.BUILTINS, 5)
|
||||
|
||||
def test_field_named_like_builtin(self):
|
||||
# Attribute names can shadow built-in names
|
||||
# since code generation is used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue