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"):
|
||||
super().__init__(name)
|
||||
|
||||
class TIndexError(types.TMono):
|
||||
class TIndexError(TException):
|
||||
def __init__(self):
|
||||
super().__init__("IndexError")
|
||||
|
||||
class TValueError(types.TMono):
|
||||
class TValueError(TException):
|
||||
def __init__(self):
|
||||
super().__init__("ValueError")
|
||||
|
||||
|
@ -150,6 +150,9 @@ def is_range(typ, elt=None):
|
|||
else:
|
||||
return types.is_mono(typ, "range")
|
||||
|
||||
def is_exception(typ):
|
||||
return isinstance(typ.find(), TException)
|
||||
|
||||
def is_iterable(typ):
|
||||
typ = typ.find()
|
||||
return isinstance(typ, types.TMono) and \
|
||||
|
@ -157,7 +160,7 @@ def is_iterable(typ):
|
|||
|
||||
def get_iterable_elt(typ):
|
||||
if is_iterable(typ):
|
||||
return typ.find()["elt"]
|
||||
return typ.find()["elt"].find()
|
||||
|
||||
def is_collection(typ):
|
||||
typ = typ.find()
|
||||
|
|
|
@ -827,7 +827,7 @@ class Inferencer(algorithm.Visitor):
|
|||
{"typeb": printer.name(typeb)},
|
||||
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)
|
||||
|
||||
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
|
||||
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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue