File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -1527,10 +1527,11 @@ class C(Base):
1527
1527
seen = set ()
1528
1528
annotations = {}
1529
1529
defaults = {}
1530
+ any_marker = object ()
1530
1531
for item in fields :
1531
1532
if isinstance (item , str ):
1532
1533
name = item
1533
- tp = 'typing.Any'
1534
+ tp = any_marker
1534
1535
elif len (item ) == 2 :
1535
1536
name , tp , = item
1536
1537
elif len (item ) == 3 :
@@ -1549,11 +1550,20 @@ class C(Base):
1549
1550
seen .add (name )
1550
1551
annotations [name ] = tp
1551
1552
1553
+ def annotate_method (format ):
1554
+ if format != 1 :
1555
+ raise NotImplementedError
1556
+ from typing import Any
1557
+ return {
1558
+ ann : Any if t is any_marker else t
1559
+ for ann , t in annotations .items ()
1560
+ }
1561
+
1552
1562
# Update 'ns' with the user-supplied namespace plus our calculated values.
1553
1563
def exec_body_callback (ns ):
1564
+ ns ['__annotate__' ] = annotate_method
1554
1565
ns .update (namespace )
1555
1566
ns .update (defaults )
1556
- ns ['__annotations__' ] = annotations
1557
1567
1558
1568
# We use `types.new_class()` instead of simply `type()` to allow dynamic creation
1559
1569
# of generic dataclasses.
You can’t perform that action at this time.
0 commit comments