Skip to content

Commit 78af6f0

Browse files
committed
Intern dataclass field names to improve performance
1 parent 4ed46d2 commit 78af6f0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/dataclasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def _field_init(f, frozen, globals, self_name, slots):
490490
# Return the text of the line in the body of __init__ that will
491491
# initialize this field.
492492

493-
default_name = f'__dataclass_dflt_{f.name}__'
493+
default_name = sys.intern(f'__dataclass_dflt_{f.name}__')
494494
if f.default_factory is not MISSING:
495495
if f.init:
496496
# This field has a default factory. If a parameter is
@@ -775,7 +775,7 @@ def _get_field(cls, a_name, a_type, default_kw_only):
775775
f = field(default=default)
776776

777777
# Only at this point do we know the name and the type. Set them.
778-
f.name = a_name
778+
f.name = sys.intern(a_name)
779779
f.type = a_type
780780

781781
# Assume it's a normal field until proven otherwise. We're next

0 commit comments

Comments
 (0)