mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
exception elements are always instances
This commit is contained in:
@@ -12,6 +12,7 @@ Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
|
|||||||
check for -> a is a string). There's big potential in these checks.
|
check for -> a is a string). There's big potential in these checks.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import hasattr, unicode, u, reraise
|
from jedi._compatibility import hasattr, unicode, u, reraise
|
||||||
from jedi.parser import representation as pr, tokenize
|
from jedi.parser import representation as pr, tokenize
|
||||||
@@ -231,7 +232,7 @@ class NameFinder(object):
|
|||||||
# global keyword handling.
|
# global keyword handling.
|
||||||
types += evaluator.find_types(typ.parent.parent, str(name))
|
types += evaluator.find_types(typ.parent.parent, str(name))
|
||||||
else:
|
else:
|
||||||
types += self._remove_statements(typ)
|
types += self._remove_statements(typ, name)
|
||||||
else:
|
else:
|
||||||
if isinstance(typ, pr.Class):
|
if isinstance(typ, pr.Class):
|
||||||
typ = er.Class(evaluator, typ)
|
typ = er.Class(evaluator, typ)
|
||||||
@@ -239,6 +240,7 @@ class NameFinder(object):
|
|||||||
typ = er.Function(evaluator, typ)
|
typ = er.Function(evaluator, typ)
|
||||||
elif isinstance(typ, pr.Module):
|
elif isinstance(typ, pr.Module):
|
||||||
typ = er.ModuleWrapper(evaluator, typ)
|
typ = er.ModuleWrapper(evaluator, typ)
|
||||||
|
|
||||||
if typ.isinstance(er.Function) and resolve_decorator:
|
if typ.isinstance(er.Function) and resolve_decorator:
|
||||||
typ = typ.get_decorated_func()
|
typ = typ.get_decorated_func()
|
||||||
types.append(typ)
|
types.append(typ)
|
||||||
@@ -249,7 +251,7 @@ class NameFinder(object):
|
|||||||
|
|
||||||
return types
|
return types
|
||||||
|
|
||||||
def _remove_statements(self, stmt):
|
def _remove_statements(self, stmt, name):
|
||||||
"""
|
"""
|
||||||
This is the part where statements are being stripped.
|
This is the part where statements are being stripped.
|
||||||
|
|
||||||
@@ -270,6 +272,15 @@ class NameFinder(object):
|
|||||||
|
|
||||||
types += evaluator.eval_statement(stmt, seek_name=unicode(self.name_str))
|
types += evaluator.eval_statement(stmt, seek_name=unicode(self.name_str))
|
||||||
|
|
||||||
|
# check for `except X as y` usages, because y needs to be instantiated.
|
||||||
|
p = stmt.parent
|
||||||
|
if isinstance(p, pr.Flow) and p.command == 'except' \
|
||||||
|
and p.get_defined_names(is_internal_call=True) == [name]:
|
||||||
|
# TODO check for types that are not classes and add it to the
|
||||||
|
# static analysis report.
|
||||||
|
types = list(chain.from_iterable(
|
||||||
|
evaluator.execute(t) for t in types))
|
||||||
|
|
||||||
if check_instance is not None:
|
if check_instance is not None:
|
||||||
# class renames
|
# class renames
|
||||||
types = [er.InstanceElement(evaluator, check_instance, a, True)
|
types = [er.InstanceElement(evaluator, check_instance, a, True)
|
||||||
|
|||||||
@@ -332,6 +332,17 @@ except ImportError, i_b:
|
|||||||
#? ImportError()
|
#? ImportError()
|
||||||
i_b
|
i_b
|
||||||
|
|
||||||
|
|
||||||
|
class MyException(Exception):
|
||||||
|
def __init__(self, my_attr):
|
||||||
|
self.my_attr = my_attr
|
||||||
|
|
||||||
|
try:
|
||||||
|
raise MyException(1)
|
||||||
|
except MyException as e:
|
||||||
|
#? ['my_attr']
|
||||||
|
e.my_attr
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# continuations
|
# continuations
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user