When using documentations tests to test a function that uses typing.get_type_hints, an error is thrown. The error is thrown when trying to get the type hints for a class that was defined in a documentation test. I was able to reproduce it both on current and PEP563 type annotations: https://gist.github.com/lovasoa/74ea62a89f5bf073b0e0c2f222008ae3
I think this is related to doc tests being executed in a namespace where the class definition is not available. I am not sure what is the best way here, a workaround is to explicitly pass the namespace, for example this passes: import typing def f(clazz, ns): """ >>> class MyClass: ... my_field: 'MyClass' >>> f(MyClass, globals()) """ typing.get_type_hints(clazz, ns) You can maybe make the ns parameter optional, but it still doesn't look like a good solution.