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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
[case testAbstractMethods]
from abc import abstractmethod, ABCMeta
import typing
class A(metaclass=ABCMeta):
@abstractmethod
def g(self) -> 'A': pass
@abstractmethod
def f(self) -> 'A': return self
[out]
MypyFile:1(
ImportFrom:1(abc, [abstractmethod, ABCMeta])
Import:2(typing)
ClassDef:4(
A
Metaclass(NameExpr(ABCMeta [abc.ABCMeta]))
Decorator:5(
Var(g)
FuncDef:6(
g
Args(
Var(self))
def (self: __main__.A) -> __main__.A
Abstract
Block:6(
PassStmt:6())))
Decorator:7(
Var(f)
FuncDef:8(
f
Args(
Var(self))
def (self: __main__.A) -> __main__.A
Abstract
Block:8(
ReturnStmt:8(
NameExpr(self [l])))))))
[case testClassInheritingTwoAbstractClasses]
from abc import abstractmethod, ABCMeta
import typing
class A(metaclass=ABCMeta): pass
class B(metaclass=ABCMeta): pass
class C(A, B): pass
[out]
MypyFile:1(
ImportFrom:1(abc, [abstractmethod, ABCMeta])
Import:2(typing)
ClassDef:4(
A
Metaclass(NameExpr(ABCMeta [abc.ABCMeta]))
PassStmt:4())
ClassDef:5(
B
Metaclass(NameExpr(ABCMeta [abc.ABCMeta]))
PassStmt:5())
ClassDef:6(
C
BaseType(
__main__.A
__main__.B)
PassStmt:6()))
[case testAbstractGenericClass]
from abc import abstractmethod
from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T]):
@abstractmethod
def f(self) -> 'A[T]': pass
[out]
MypyFile:1(
ImportFrom:1(abc, [abstractmethod])
ImportFrom:2(typing, [Generic, TypeVar])
AssignmentStmt:3(
NameExpr(T* [__main__.T])
TypeVarExpr:3())
ClassDef:4(
A
TypeVars(
T`1)
Decorator:5(
Var(f)
FuncDef:6(
f
Args(
Var(self))
def (self: __main__.A[T`1]) -> __main__.A[T`1]
Abstract
Block:6(
PassStmt:6())))))
[case testFullyQualifiedAbstractMethodDecl]
import abc
from abc import ABCMeta
import typing
class A(metaclass=ABCMeta):
@abc.abstractmethod
def g(self) -> 'A': pass
[out]
MypyFile:1(
Import:1(abc)
ImportFrom:2(abc, [ABCMeta])
Import:3(typing)
ClassDef:5(
A
Metaclass(NameExpr(ABCMeta [abc.ABCMeta]))
Decorator:6(
Var(g)
FuncDef:7(
g
Args(
Var(self))
def (self: __main__.A) -> __main__.A
Abstract
Block:7(
PassStmt:7())))))
|