forked from M-Labs/artiq
Add builtins.is_exception.
This commit is contained in:
parent
3b661b2b65
commit
f28549a11a
|
@ -71,11 +71,11 @@ class TException(types.TMono):
|
||||||
def __init__(self, name="Exception"):
|
def __init__(self, name="Exception"):
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
|
|
||||||
class TIndexError(types.TMono):
|
class TIndexError(TException):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("IndexError")
|
super().__init__("IndexError")
|
||||||
|
|
||||||
class TValueError(types.TMono):
|
class TValueError(TException):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("ValueError")
|
super().__init__("ValueError")
|
||||||
|
|
||||||
|
@ -150,6 +150,9 @@ def is_range(typ, elt=None):
|
||||||
else:
|
else:
|
||||||
return types.is_mono(typ, "range")
|
return types.is_mono(typ, "range")
|
||||||
|
|
||||||
|
def is_exception(typ):
|
||||||
|
return isinstance(typ.find(), TException)
|
||||||
|
|
||||||
def is_iterable(typ):
|
def is_iterable(typ):
|
||||||
typ = typ.find()
|
typ = typ.find()
|
||||||
return isinstance(typ, types.TMono) and \
|
return isinstance(typ, types.TMono) and \
|
||||||
|
@ -157,7 +160,7 @@ def is_iterable(typ):
|
||||||
|
|
||||||
def get_iterable_elt(typ):
|
def get_iterable_elt(typ):
|
||||||
if is_iterable(typ):
|
if is_iterable(typ):
|
||||||
return typ.find()["elt"]
|
return typ.find()["elt"].find()
|
||||||
|
|
||||||
def is_collection(typ):
|
def is_collection(typ):
|
||||||
typ = typ.find()
|
typ = typ.find()
|
||||||
|
|
|
@ -827,7 +827,7 @@ class Inferencer(algorithm.Visitor):
|
||||||
{"typeb": printer.name(typeb)},
|
{"typeb": printer.name(typeb)},
|
||||||
locb)
|
locb)
|
||||||
]
|
]
|
||||||
self._unify(node.name_type, node.filter.type.to_exception_type(),
|
self._unify(node.name_type, builtins.TException(node.filter.type.name),
|
||||||
node.name_loc, node.filter.loc, makenotes)
|
node.name_loc, node.filter.loc, makenotes)
|
||||||
|
|
||||||
def _type_from_arguments(self, node, ret):
|
def _type_from_arguments(self, node, ret):
|
||||||
|
|
|
@ -268,9 +268,6 @@ class TExceptionConstructor(TBuiltin):
|
||||||
Note that this is not the same as the type of an instance of
|
Note that this is not the same as the type of an instance of
|
||||||
the class, which is ``TMono("Exception", ...)``.
|
the class, which is ``TMono("Exception", ...)``.
|
||||||
"""
|
"""
|
||||||
def to_exception_type(self):
|
|
||||||
# Exceptions currently can't have type parameters
|
|
||||||
return TMono(self.name, {})
|
|
||||||
|
|
||||||
class TValue(Type):
|
class TValue(Type):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue