|
71 | 71 | from mypy.errors import Errors, report_internal_error
|
72 | 72 | from mypy.types import (
|
73 | 73 | NoneTyp, CallableType, Overloaded, Instance, Type, TypeVarType, AnyType,
|
74 |
| - FunctionLike, UnboundType, TypeList, TypeVarDef, TypeType, |
| 74 | + FunctionLike, UnboundType, TypeList, TypeVarDef, |
75 | 75 | TupleType, UnionType, StarType, EllipsisType, function_type)
|
76 | 76 | from mypy.nodes import implicit_module_attrs
|
77 | 77 | from mypy.typeanal import TypeAnalyser, TypeAnalyserPass3, analyze_type_alias
|
@@ -1803,41 +1803,31 @@ def add_field(var: Var, is_initialized_in_class: bool = False,
|
1803 | 1803 | add_field(Var('_field_types', dictype), is_initialized_in_class=True)
|
1804 | 1804 | add_field(Var('_source', strtype), is_initialized_in_class=True)
|
1805 | 1805 |
|
1806 |
| - tvd = TypeVarDef('NT', 1, [], fill_typevars(info)) |
1807 |
| - selftype = TypeVarType(tvd) |
| 1806 | + # TODO: SelfType should be bind to actual 'self' |
| 1807 | + this_type = fill_typevars(info) |
1808 | 1808 |
|
1809 | 1809 | def add_method(funcname: str, ret: Type, args: List[Argument], name=None,
|
1810 | 1810 | is_classmethod=False) -> None:
|
1811 |
| - if is_classmethod: |
1812 |
| - first = [Argument(Var('cls'), TypeType(selftype), None, ARG_POS)] |
1813 |
| - else: |
1814 |
| - first = [Argument(Var('self'), selftype, None, ARG_POS)] |
1815 |
| - args = first + args |
1816 |
| - |
| 1811 | + if not is_classmethod: |
| 1812 | + args = [Argument(Var('self'), this_type, None, ARG_POS)] + args |
1817 | 1813 | types = [arg.type_annotation for arg in args]
|
1818 | 1814 | items = [arg.variable.name() for arg in args]
|
1819 | 1815 | arg_kinds = [arg.kind for arg in args]
|
1820 | 1816 | signature = CallableType(types, arg_kinds, items, ret, function_type,
|
1821 | 1817 | name=name or info.name() + '.' + funcname)
|
1822 |
| - signature.variables = [tvd] |
| 1818 | + signature.is_classmethod_class = is_classmethod |
1823 | 1819 | func = FuncDef(funcname, args, Block([]), typ=signature)
|
1824 | 1820 | func.info = info
|
1825 | 1821 | func.is_class = is_classmethod
|
1826 |
| - if is_classmethod: |
1827 |
| - v = Var(funcname, signature) |
1828 |
| - v.is_classmethod = True |
1829 |
| - v.info = info |
1830 |
| - dec = Decorator(func, [NameExpr('classmethod')], v) |
1831 |
| - info.names[funcname] = SymbolTableNode(MDEF, dec) |
1832 |
| - else: |
1833 |
| - info.names[funcname] = SymbolTableNode(MDEF, func) |
| 1822 | + info.names[funcname] = SymbolTableNode(MDEF, func) |
1834 | 1823 |
|
1835 |
| - add_method('_replace', ret=selftype, |
| 1824 | + add_method('_replace', ret=this_type, |
1836 | 1825 | args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED) for var in vars])
|
1837 | 1826 | add_method('__init__', ret=NoneTyp(), name=info.name(),
|
1838 | 1827 | args=[Argument(var, var.type, None, ARG_POS) for var in vars])
|
1839 | 1828 | add_method('_asdict', args=[], ret=ordereddictype)
|
1840 |
| - add_method('_make', ret=selftype, is_classmethod=True, |
| 1829 | + # FIX: make it actual class method |
| 1830 | + add_method('_make', ret=this_type, is_classmethod=True, |
1841 | 1831 | args=[Argument(Var('iterable', iterable_type), iterable_type, None, ARG_POS),
|
1842 | 1832 | Argument(Var('new'), AnyType(), EllipsisExpr(), ARG_NAMED),
|
1843 | 1833 | Argument(Var('len'), AnyType(), EllipsisExpr(), ARG_NAMED)])
|
|
0 commit comments