Skip to content

Commit cbaab5b

Browse files
author
root
committed
Here, have some code
1 parent fe6fd1a commit cbaab5b

File tree

9 files changed

+43
-8
lines changed

9 files changed

+43
-8
lines changed

mypy/checker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,10 +3023,14 @@ def visit_decorator(self, e: Decorator) -> None:
30233023
callable_name=fullname)
30243024
self.check_untyped_after_decorator(sig, e.func)
30253025
sig = set_callable_name(sig, e.func)
3026-
e.var.type = sig
3027-
e.var.is_ready = True
30283026
if e.func.is_property:
3027+
assert isinstance(sig, CallableType)
3028+
sig = sig.ret_type
30293029
self.check_incompatible_property_override(e)
3030+
e.var.type = sig
3031+
e.var.is_ready = True
3032+
if isinstance(sig, CallableType):
3033+
e.is_callable = True
30303034
if e.func.info and not e.func.is_dynamic():
30313035
self.check_method_override(e)
30323036

mypy/checkmember.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ def analyze_class_attribute_access(itype: Instance,
557557
return chk.handle_partial_var_type(t, is_lvalue, symnode, context)
558558
if not is_method and (isinstance(t, TypeVarType) or get_type_vars(t)):
559559
msg.fail(messages.GENERIC_INSTANCE_VAR_CLASS_ACCESS, context)
560-
is_classmethod = ((is_decorated and cast(Decorator, node.node).func.is_class)
561-
or (isinstance(node.node, FuncBase) and node.node.is_class))
560+
is_classmethod = isinstance(node.node, FuncBase) and node.node.is_class
562561
result = add_class_tvars(t, itype, is_classmethod, builtin_type, original_type)
563562
if not is_lvalue:
564563
result = analyze_descriptor_access(original_type, result, builtin_type,

mypy/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ def report_internal_error(err: Exception, file: Optional[str], line: int,
594594
pdb.post_mortem(sys.exc_info()[2])
595595

596596
# If requested, print traceback, else print note explaining how to get one.
597+
if options.raise_exceptions:
598+
raise err
597599
if not options.show_traceback:
598600
if not options.pdb:
599601
print('{}: note: please use --show-traceback to print a traceback '

mypy/fastparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ def is_star2arg(k: ast3.keyword) -> bool:
871871
[k.value for k in n.keywords])
872872
arg_kinds = ([ARG_STAR if isinstance(a, ast3.Starred) else ARG_POS for a in n.args] +
873873
[ARG_STAR2 if is_star2arg(k) else ARG_NAMED for k in n.keywords])
874-
return CallExpr(self.visit(n.func),
874+
expr = self.visit(n.func)
875+
return CallExpr(expr,
875876
arg_types,
876877
arg_kinds,
877878
cast(List[Optional[str]], [None] * len(n.args)) +

mypy/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ def add_invertible_flag(flag: str,
618618
internals_group.add_argument(
619619
'--show-traceback', '--tb', action='store_true',
620620
help="Show traceback on fatal error")
621+
internals_group.add_argument(
622+
'--raise-exceptions', action='store_true', help="Raise exception on fatal error"
623+
)
621624
internals_group.add_argument(
622625
'--custom-typing', metavar='MODULE', dest='custom_typing_module',
623626
help="Use a custom typing module")

mypy/nodes.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,18 @@ def __str__(self) -> str:
383383
] # type: Final
384384

385385

386-
class FuncBase(Node):
386+
class FuncBaseMeta(type):
387+
def __instancecheck__(self, instance):
388+
if isinstance(instance, Decorator):
389+
if instance.is_overload:
390+
return issubclass(OverloadedFuncDef, self) and instance.is_callable
391+
else:
392+
return issubclass(FuncBase, self) and instance.is_callable
393+
else:
394+
return super().__instancecheck__(instance)
395+
396+
397+
class FuncBase(Node, metaclass=FuncBaseMeta):
387398
"""Abstract base class for function-like nodes"""
388399

389400
__slots__ = ('type',
@@ -657,6 +668,7 @@ class Decorator(SymbolNode, Statement):
657668
# TODO: This is mostly used for the type; consider replacing with a 'type' attribute
658669
var = None # type: Var # Represents the decorated function obj
659670
is_overload = False
671+
is_callable = False
660672

661673
def __init__(self, func: FuncDef, decorators: List[Expression],
662674
var: 'Var') -> None:
@@ -672,6 +684,18 @@ def name(self) -> str:
672684
def fullname(self) -> Bogus[str]:
673685
return self.func.fullname()
674686

687+
@property
688+
def items(self):
689+
return self.func.items
690+
691+
@property
692+
def is_property(self) -> bool:
693+
return self.func.is_property
694+
695+
@property
696+
def is_class(self) -> bool:
697+
return self.func.is_class
698+
675699
@property
676700
def is_final(self) -> bool:
677701
return self.func.is_final
@@ -2299,7 +2323,7 @@ def __repr__(self) -> str:
22992323
def has_readable_member(self, name: str) -> bool:
23002324
return self.get(name) is not None
23012325

2302-
def get_method(self, name: str) -> Optional[FuncBase]:
2326+
def get_method(self, name: str) -> Union[FuncBase, Decorator, None]:
23032327
for cls in self.mro:
23042328
if name in cls.names:
23052329
node = cls.names[name].node

mypy/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def __init__(self) -> None:
196196
self.verbosity = 0 # More verbose messages (for troubleshooting)
197197
self.pdb = False
198198
self.show_traceback = False
199+
self.raise_exceptions = False
199200
self.dump_type_stats = False
200201
self.dump_inference_stats = False
201202

mypy/semanal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,7 @@ def visit_decorator(self, dec: Decorator) -> None:
25142514
self.check_decorated_function_is_method('classmethod', dec)
25152515
elif (refers_to_fullname(d, 'builtins.property') or
25162516
refers_to_fullname(d, 'abc.abstractproperty')):
2517+
# TODO: Stop treating properties as special cases and treat as generalized descriptors
25172518
removed.append(i)
25182519
dec.func.is_property = True
25192520
dec.var.is_property = True

mypy_self_check.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ disallow_any_generics = True
88
disallow_any_unimported = True
99
warn_redundant_casts = True
1010
warn_unused_configs = True
11-
show_traceback = True
11+
raise_exceptions = True
1212

1313
# needs py2 compatibility
1414
[mypy-mypy.test.testextensions]

0 commit comments

Comments
 (0)