[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:
Miss Islington (bot) 2022-10-31 07:59:00 -07:00 committed by GitHub
parent 57dd11038f
commit ca24e496ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View file

@ -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.