gh-96151: Use a private name for passing builtins to dataclass. This now allows for a field named BUILTIN (gh-98143)

This commit is contained in:
Shantanu 2022-10-31 05:31:01 -07:00 committed by GitHub
parent 87b5fd9d9d
commit 29f98b46b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View file

@ -257,6 +257,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.