@@ -391,10 +391,16 @@ def from_typing_type(thing):
391391 for k , v in _global_type_lookup .items ()
392392 if is_generic_type (k ) and try_issubclass (k , thing )
393393 }
394- # Drop some unusual cases for simplicity
395- for weird in (tuple , getattr (os , "_Environ" , None )):
396- if len (mapping ) > 1 :
397- mapping .pop (weird , None )
394+ # Drop some unusual cases for simplicity, including tuples or its
395+ # subclasses (e.g. namedtuple)
396+ if len (mapping ) > 1 :
397+ _Environ = getattr (os , "_Environ" , None )
398+ mapping .pop (_Environ , None )
399+ tuple_types = [t for t in mapping if isinstance (t , type ) and issubclass (t , tuple )]
400+ if len (mapping ) > len (tuple_types ):
401+ for tuple_type in tuple_types :
402+ mapping .pop (tuple_type )
403+
398404 # After we drop Python 3.8 and can rely on having generic builtin types, we'll
399405 # be able to simplify this logic by dropping the typing-module handling.
400406 if {dict , set , typing .Dict , typing .Set }.intersection (mapping ):
@@ -407,6 +413,7 @@ def from_typing_type(thing):
407413 # the ghostwriter than it's worth, via undefined names in the repr.
408414 mapping .pop (collections .deque , None )
409415 mapping .pop (typing .Deque , None )
416+
410417 if len (mapping ) > 1 :
411418 # issubclass treats bytestring as a kind of sequence, which it is,
412419 # but treating it as such breaks everything else when it is presumed
0 commit comments