@@ -116,7 +116,12 @@ def restify(cls: Optional[Type]) -> str:
116116 elif cls in INVALID_BUILTIN_CLASSES :
117117 return ':class:`%s`' % INVALID_BUILTIN_CLASSES [cls ]
118118 elif inspect .isNewType (cls ):
119- return ':class:`%s`' % cls .__name__
119+ if sys .version_info > (3 , 10 ):
120+ # newtypes have correct module info since Python 3.10+
121+ print (cls , type (cls ), dir (cls ))
122+ return ':class:`%s.%s`' % (cls .__module__ , cls .__name__ )
123+ else :
124+ return ':class:`%s`' % cls .__name__
120125 elif UnionType and isinstance (cls , UnionType ):
121126 if len (cls .__args__ ) > 1 and None in cls .__args__ :
122127 args = ' | ' .join (restify (a ) for a in cls .__args__ if a )
@@ -307,8 +312,11 @@ def stringify(annotation: Any) -> str:
307312 else :
308313 return '.' .join ([annotation .__module__ , annotation .__name__ ])
309314 elif inspect .isNewType (annotation ):
310- # Could not get the module where it defined
311- return annotation .__name__
315+ if sys .version_info > (3 , 10 ):
316+ # newtypes have correct module info since Python 3.10+
317+ return '%s.%s' % (annotation .__module__ , annotation .__name__ )
318+ else :
319+ return annotation .__name__
312320 elif not annotation :
313321 return repr (annotation )
314322 elif annotation is NoneType :
0 commit comments