44
55from typing import (
66 List , Dict , Set , Tuple , Pattern , Match , Any , Callable , Generic ,
7- AbstractGeneric , Protocol , Sized , Iterable , Iterator , Sequence ,
7+ AbstractGeneric , _Protocol , Sized , Iterable , Iterator , Sequence ,
88 AbstractSet , Mapping , BinaryIO , TextIO , SupportsInt , SupportsFloat ,
99 SupportsAbs , Reversible , Undefined , AnyStr , annotations , builtinclass ,
1010 cast , disjointclass , ducktype , forwardref , overload , typevar
@@ -438,7 +438,7 @@ def test_reversible(self):
438438 self .assertNotIsInstance ('' , Reversible )
439439
440440 def test_simple_protocol (self ):
441- class P (Protocol ):
441+ class P (_Protocol ):
442442 def f (self ): pass
443443
444444 class A (object ):
@@ -455,16 +455,16 @@ def g(self): pass
455455
456456 self .assertTrue (issubclass (A , P ))
457457 self .assertFalse (issubclass (B , P ))
458- self .assertTrue (issubclass (P , Protocol ))
459- self .assertTrue (issubclass (Protocol , Protocol ))
460- self .assertTrue (issubclass (A , Protocol ))
458+ self .assertTrue (issubclass (P , _Protocol ))
459+ self .assertTrue (issubclass (_Protocol , _Protocol ))
460+ self .assertTrue (issubclass (A , _Protocol ))
461461
462462 def test_issubclass_of_protocol (self ):
463463 class A (object ): pass
464- self .assertTrue (issubclass (A , Protocol ))
464+ self .assertTrue (issubclass (A , _Protocol ))
465465
466466 def test_protocol_with_two_attrs (self ):
467- class P (Protocol ):
467+ class P (_Protocol ):
468468 def __int__ (self ): pass
469469 x = 0
470470
@@ -486,9 +486,9 @@ class C(object):
486486 self .assertNotIsInstance (C (), P )
487487
488488 def test_protocol_inheritance (self ):
489- class P (Protocol ):
489+ class P (_Protocol ):
490490 def f (self ): pass
491- class PP (P , Protocol ):
491+ class PP (P , _Protocol ):
492492 def g (self ): pass
493493
494494 class A (object ):
@@ -508,18 +508,18 @@ def g(self): pass
508508 self .assertNotIsInstance (A (), PP )
509509 self .assertNotIsInstance (C (), PP )
510510
511- class AA (Protocol ):
511+ class AA (_Protocol ):
512512 def f (self ): return 1
513513 class BB (AA ): pass
514514
515515 self .assertEqual (BB ().f (), 1 )
516516
517517 class CC (AA ): pass
518- # BB is not a protocol since it doesn't explicitly subclass Protocol .
518+ # BB is not a protocol since it doesn't explicitly subclass _Protocol .
519519 self .assertNotIsInstance (CC (), BB )
520520
521521 def test_builtin_class_and_protocol (self ):
522- class P (Protocol ):
522+ class P (_Protocol ):
523523 def __add__ (self ): pass
524524
525525 self .assertIsInstance ('' , P )
@@ -532,14 +532,14 @@ def __add__(self): pass
532532
533533 def test_generic_protocol (self ):
534534 t = typevar ('t' )
535- class P (Protocol [t ]):
535+ class P (_Protocol [t ]):
536536 x = 1
537537 class A (object ):
538538 x = 2
539539 self .assertIsInstance (A (), P )
540540
541541 def test_indexing_in_protocol (self ):
542- class P (Protocol ):
542+ class P (_Protocol ):
543543 def __getitem__ (self ): pass
544544 class A (object ):
545545 def __getitem__ (self ): pass
@@ -609,11 +609,11 @@ class C(A, B): pass
609609 self .assertNotIsInstance (B (), Iterator )
610610
611611 def test_multiple_protocol_inheritance (self ):
612- class P (Protocol ):
612+ class P (_Protocol ):
613613 x = 1
614- class P2 (Protocol ):
614+ class P2 (_Protocol ):
615615 y = 1
616- class P3 (P , P2 , Protocol ): pass
616+ class P3 (P , P2 , _Protocol ): pass
617617
618618 class A (object ):
619619 x = 1
@@ -628,7 +628,7 @@ class C(object):
628628 self .assertNotIsInstance (C (), P3 )
629629
630630 def test_protocol_docstrings (self ):
631- class P (Protocol ):
631+ class P (_Protocol ):
632632 u"""blah"""
633633 def f (self ): pass
634634 class A (object ):
@@ -769,15 +769,15 @@ def f(self): pass
769769 B ()
770770
771771 def test_protocol_with_abstract_method (self ):
772- class A (Protocol ):
772+ class A (_Protocol ):
773773 @abstractmethod
774774 def f (self ): pass
775775
776776 with self .assertRaises (TypeError ):
777777 A () # No implementation for abstract method.
778778
779779 def test_protocol_inheritance_with_abstract_method (self ):
780- class A (Protocol ):
780+ class A (_Protocol ):
781781 @abstractmethod
782782 def f (self ): pass
783783 class B (A ):
0 commit comments