@@ -2205,17 +2205,35 @@ def method(self, arg: type_) -> type_:
22052205 return arg
22062206 MyClass .__annotations__ = {'attribute' : type_ }
22072207
2208- def check_annotations (obj , expected_type ):
2208+ def check_annotations (obj , expected_type , expected_type_str ):
22092209 assert obj .__annotations__ ["attribute" ] == expected_type
2210- assert obj .method .__annotations__ ["arg" ] == expected_type
2211- assert (
2212- obj .method .__annotations__ ["return" ] == expected_type
2213- )
2210+ if sys .version_info >= (3 , 10 ):
2211+ # In Python 3.10, type annotations are stored as strings.
2212+ # See PEP 563 for more details:
2213+ # https://www.python.org/dev/peps/pep-0563/
2214+ assert (
2215+ obj .method .__annotations__ ["arg" ]
2216+ == expected_type_str
2217+ )
2218+ assert (
2219+ obj .method .__annotations__ ["return" ]
2220+ == expected_type_str
2221+ )
2222+ else :
2223+ assert (
2224+ obj .method .__annotations__ ["arg" ] == expected_type
2225+ )
2226+ assert (
2227+ obj .method .__annotations__ ["return" ]
2228+ == expected_type
2229+ )
22142230 return "ok"
22152231
22162232 obj = MyClass ()
2217- assert check_annotations (obj , type_ ) == "ok"
2218- assert worker .run (check_annotations , obj , type_ ) == "ok"
2233+ assert check_annotations (obj , type_ , "type_" ) == "ok"
2234+ assert (
2235+ worker .run (check_annotations , obj , type_ , "type_" ) == "ok"
2236+ )
22192237
22202238 def test_generic_extensions_literal (self ):
22212239 typing_extensions = pytest .importorskip ('typing_extensions' )
0 commit comments