-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathabstractClass12.py
More file actions
40 lines (25 loc) · 1.23 KB
/
abstractClass12.py
File metadata and controls
40 lines (25 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# this sample tests the type analyzer's ability to flag attempts
# to instantiate abstract base classes that have no abstract methods
from abc import ABC, ABCMeta
class ExplicitlyAbstract(ABC):
"""an abstract class with no abstract methods"""
# this should generate an error because `AbstractFoo`
# is an abstract class even though it has no abstract methods
a = ExplicitlyAbstract()
class IndirectlyAbstract(ExplicitlyAbstract):
"""inherits from an explicitly abstract class"""
# this should not generate an error because IndirectlyAbstract
# doesn't directly inherit from ABC (only through AbstractFoo)
f = IndirectlyAbstract()
class NotAbstract:
"""a regular class that doesn't derive from ABC"""
# This should not generate an error because NotAbstract is not abstract
e = NotAbstract()
class AbstractWithMetaclass(metaclass=ABCMeta):
"""abstract class using ABCMeta metaclass with no abstract methods"""
class ConcreteWithMetaclass(AbstractWithMetaclass):
"""concrete subclass of AbstractWithMetaclass"""
# this should generate an error because AbstractWithMetaclass uses ABCMeta
i = AbstractWithMetaclass() # pyright: ignore[reportExplicitAbstractUsage]
# this should not generate an error
j = ConcreteWithMetaclass()