Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a19a2b

Browse files
committed
CR: get rid of TypeType.__new__
1 parent 8d5fc1e commit 2a19a2b

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

mypy/types.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -1185,31 +1185,23 @@ class TypeType(Type):
11851185

11861186
# This class must be created using make method which may return either TypeType or UnionType.
11871187
# This is to ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]].
1188-
def __init__(self, item: Type, *, line: int = -1, column: int = -1) -> None:
1189-
raise NotImplementedError
1190-
1191-
def _init(self, item: Type, *, line: int = -1, column: int = -1) -> None:
1188+
def __init__(self, item: Union[Instance, AnyType, TypeVarType, TupleType, NoneTyp,
1189+
CallableType], *, line: int = -1, column: int = -1) -> None:
11921190
super().__init__(line, column)
11931191
if isinstance(item, CallableType) and item.is_type_obj():
11941192
self.item = item.fallback
11951193
else:
11961194
self.item = item
11971195

1198-
def __new__(cls, *args, **kwargs): # type: ignore
1199-
instance = object.__new__(cls)
1200-
instance._init(*args, **kwargs)
1201-
return instance
1202-
1203-
def __copy__(self) -> 'Type':
1204-
return TypeType.make(self.item)
1205-
12061196
@staticmethod
12071197
def make(item: Type, *, line: int = -1, column: int = -1) -> Type:
12081198
if isinstance(item, UnionType):
12091199
return UnionType.make_union([TypeType.make(union_item) for union_item in item.items],
12101200
line=line, column=column)
1201+
elif isinstance(item, (Instance, AnyType, TypeVarType, TupleType, NoneTyp, CallableType)):
1202+
return TypeType(item, line=line, column=column)
12111203
else:
1212-
return TypeType.__new__(TypeType, item, line=line, column=column)
1204+
raise RuntimeError('Unexpected item type', type(item))
12131205

12141206
def accept(self, visitor: 'TypeVisitor[T]') -> T:
12151207
return visitor.visit_type_type(self)

0 commit comments

Comments
 (0)