Skip to content

Commit a3b68ee

Browse files
committed
Test classmethods and staticmethods as annotate functions
1 parent a43a873 commit a3b68ee

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Lib/test/test_annotationlib.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,44 @@ def __call__(self, format, /, __Format=Format,
16131613

16141614
self.assertEqual(annotations, {"x": str})
16151615

1616+
def test_callable_classmethod_annotate_forwardref_value_fallback(self):
1617+
# If Format.STRING and Format.VALUE_WITH_FAKE_GLOBALS are not
1618+
# supported fall back to Format.VALUE and convert to strings
1619+
class Annotate:
1620+
@classmethod
1621+
def __call__(cls, format, /, __Format=Format,
1622+
__NotImplementedError=NotImplementedError):
1623+
if format == __Format.VALUE:
1624+
return {"x": str}
1625+
else:
1626+
raise __NotImplementedError(format)
1627+
1628+
annotations = annotationlib.call_annotate_function(
1629+
Annotate.__call__,
1630+
Format.FORWARDREF,
1631+
)
1632+
1633+
self.assertEqual(annotations, {"x": str})
1634+
1635+
def test_callable_staticmethod_annotate_forwardref_value_fallback(self):
1636+
# If Format.STRING and Format.VALUE_WITH_FAKE_GLOBALS are not
1637+
# supported fall back to Format.VALUE and convert to strings
1638+
class Annotate:
1639+
@staticmethod
1640+
def __call__(format, /, __Format=Format,
1641+
__NotImplementedError=NotImplementedError):
1642+
if format == __Format.VALUE:
1643+
return {"x": str}
1644+
else:
1645+
raise __NotImplementedError(format)
1646+
1647+
annotations = annotationlib.call_annotate_function(
1648+
Annotate.__call__,
1649+
Format.FORWARDREF,
1650+
)
1651+
1652+
self.assertEqual(annotations, {"x": str})
1653+
16161654
def test_callable_class_annotate_forwardref_value_fallback(self):
16171655
# If Format.STRING and Format.VALUE_WITH_FAKE_GLOBALS are not
16181656
# supported fall back to Format.VALUE and convert to strings

0 commit comments

Comments
 (0)