fix(checker): handle subscript and error in typevar bound
This commit is contained in:
@@ -1090,10 +1090,13 @@ class PythonTyper(
|
|||||||
bound: Optional[Type] = None
|
bound: Optional[Type] = None
|
||||||
variance: Variance = Variance.INVARIANT
|
variance: Variance = Variance.INVARIANT
|
||||||
if "bound" in call.keywords:
|
if "bound" in call.keywords:
|
||||||
bound_type: p.MidasType = self._parse_type_from_expr(
|
try:
|
||||||
call.keywords["bound"]
|
bound_type: p.MidasType = self._parse_type_from_expr(
|
||||||
)
|
call.keywords["bound"]
|
||||||
bound = self.resolve_type_expr(bound_type)
|
)
|
||||||
|
bound = self.resolve_type_expr(bound_type)
|
||||||
|
except NotImplementedError:
|
||||||
|
bound = UnknownType()
|
||||||
|
|
||||||
if is_kw_true("covariant"):
|
if is_kw_true("covariant"):
|
||||||
variance = Variance.COVARIANT
|
variance = Variance.COVARIANT
|
||||||
@@ -1139,6 +1142,14 @@ class PythonTyper(
|
|||||||
return parser._parse_type(node.body)
|
return parser._parse_type(node.body)
|
||||||
case p.VariableExpr(name=name):
|
case p.VariableExpr(name=name):
|
||||||
return p.BaseType(location=location, base=name, args=())
|
return p.BaseType(location=location, base=name, args=())
|
||||||
|
case p.SubscriptExpr(object=p.VariableExpr(name=name), index=arg):
|
||||||
|
args: tuple[p.MidasType, ...] = (
|
||||||
|
tuple(self._parse_type_from_expr(a) for a in arg.items)
|
||||||
|
if isinstance(arg, p.TupleExpr)
|
||||||
|
else (self._parse_type_from_expr(arg),)
|
||||||
|
)
|
||||||
|
return p.BaseType(location=location, base=name, args=args)
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user