Skip to content

Commit 33b279d

Browse files
committed
Introduce _ANY_MARKER
1 parent 43caa3f commit 33b279d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/dataclasses.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ def __repr__(self):
244244
property,
245245
})
246246

247+
# Any marker is used in `make_dataclass` to mark unannotated fields as `Any`
248+
# without importing `typing` module.
249+
_ANY_MARKER = object()
250+
247251

248252
class InitVar:
249253
__slots__ = ('type', )
@@ -1527,11 +1531,10 @@ class C(Base):
15271531
seen = set()
15281532
annotations = {}
15291533
defaults = {}
1530-
any_marker = object()
15311534
for item in fields:
15321535
if isinstance(item, str):
15331536
name = item
1534-
tp = any_marker
1537+
tp = _ANY_MARKER
15351538
elif len(item) == 2:
15361539
name, tp, = item
15371540
elif len(item) == 3:
@@ -1555,13 +1558,13 @@ def annotate_method(format):
15551558
if typing is None and format == annotationlib.Format.FORWARDREF:
15561559
typing_any = annotationlib.ForwardRef("Any", module="typing")
15571560
return {
1558-
ann: typing_any if t is any_marker else t
1561+
ann: typing_any if t is _ANY_MARKER else t
15591562
for ann, t in annotations.items()
15601563
}
15611564

15621565
from typing import Any, _convert_to_source
15631566
ann_dict = {
1564-
ann: Any if t is any_marker else t
1567+
ann: Any if t is _ANY_MARKER else t
15651568
for ann, t in annotations.items()
15661569
}
15671570
if format == annotationlib.Format.SOURCE:

0 commit comments

Comments
 (0)