4
4
5
5
from typing import (
6
6
List , Dict , Set , Tuple , Pattern , Match , Any , Callable , Generic ,
7
- AbstractGeneric , Protocol , Sized , Iterable , Iterator , Sequence ,
7
+ AbstractGeneric , _Protocol , Sized , Iterable , Iterator , Sequence ,
8
8
AbstractSet , Mapping , BinaryIO , TextIO , SupportsInt , SupportsFloat ,
9
9
SupportsAbs , Reversible , Undefined , AnyStr , annotations , builtinclass ,
10
10
cast , disjointclass , ducktype , forwardref , overload , typevar
@@ -438,7 +438,7 @@ def test_reversible(self):
438
438
self .assertNotIsInstance ('' , Reversible )
439
439
440
440
def test_simple_protocol (self ):
441
- class P (Protocol ):
441
+ class P (_Protocol ):
442
442
def f (self ): pass
443
443
444
444
class A (object ):
@@ -455,16 +455,16 @@ def g(self): pass
455
455
456
456
self .assertTrue (issubclass (A , P ))
457
457
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 ))
461
461
462
462
def test_issubclass_of_protocol (self ):
463
463
class A (object ): pass
464
- self .assertTrue (issubclass (A , Protocol ))
464
+ self .assertTrue (issubclass (A , _Protocol ))
465
465
466
466
def test_protocol_with_two_attrs (self ):
467
- class P (Protocol ):
467
+ class P (_Protocol ):
468
468
def __int__ (self ): pass
469
469
x = 0
470
470
@@ -486,9 +486,9 @@ class C(object):
486
486
self .assertNotIsInstance (C (), P )
487
487
488
488
def test_protocol_inheritance (self ):
489
- class P (Protocol ):
489
+ class P (_Protocol ):
490
490
def f (self ): pass
491
- class PP (P , Protocol ):
491
+ class PP (P , _Protocol ):
492
492
def g (self ): pass
493
493
494
494
class A (object ):
@@ -508,18 +508,18 @@ def g(self): pass
508
508
self .assertNotIsInstance (A (), PP )
509
509
self .assertNotIsInstance (C (), PP )
510
510
511
- class AA (Protocol ):
511
+ class AA (_Protocol ):
512
512
def f (self ): return 1
513
513
class BB (AA ): pass
514
514
515
515
self .assertEqual (BB ().f (), 1 )
516
516
517
517
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 .
519
519
self .assertNotIsInstance (CC (), BB )
520
520
521
521
def test_builtin_class_and_protocol (self ):
522
- class P (Protocol ):
522
+ class P (_Protocol ):
523
523
def __add__ (self ): pass
524
524
525
525
self .assertIsInstance ('' , P )
@@ -532,14 +532,14 @@ def __add__(self): pass
532
532
533
533
def test_generic_protocol (self ):
534
534
t = typevar ('t' )
535
- class P (Protocol [t ]):
535
+ class P (_Protocol [t ]):
536
536
x = 1
537
537
class A (object ):
538
538
x = 2
539
539
self .assertIsInstance (A (), P )
540
540
541
541
def test_indexing_in_protocol (self ):
542
- class P (Protocol ):
542
+ class P (_Protocol ):
543
543
def __getitem__ (self ): pass
544
544
class A (object ):
545
545
def __getitem__ (self ): pass
@@ -609,11 +609,11 @@ class C(A, B): pass
609
609
self .assertNotIsInstance (B (), Iterator )
610
610
611
611
def test_multiple_protocol_inheritance (self ):
612
- class P (Protocol ):
612
+ class P (_Protocol ):
613
613
x = 1
614
- class P2 (Protocol ):
614
+ class P2 (_Protocol ):
615
615
y = 1
616
- class P3 (P , P2 , Protocol ): pass
616
+ class P3 (P , P2 , _Protocol ): pass
617
617
618
618
class A (object ):
619
619
x = 1
@@ -628,7 +628,7 @@ class C(object):
628
628
self .assertNotIsInstance (C (), P3 )
629
629
630
630
def test_protocol_docstrings (self ):
631
- class P (Protocol ):
631
+ class P (_Protocol ):
632
632
u"""blah"""
633
633
def f (self ): pass
634
634
class A (object ):
@@ -769,15 +769,15 @@ def f(self): pass
769
769
B ()
770
770
771
771
def test_protocol_with_abstract_method (self ):
772
- class A (Protocol ):
772
+ class A (_Protocol ):
773
773
@abstractmethod
774
774
def f (self ): pass
775
775
776
776
with self .assertRaises (TypeError ):
777
777
A () # No implementation for abstract method.
778
778
779
779
def test_protocol_inheritance_with_abstract_method (self ):
780
- class A (Protocol ):
780
+ class A (_Protocol ):
781
781
@abstractmethod
782
782
def f (self ): pass
783
783
class B (A ):
0 commit comments