Skip to content

Commit 95cafcd

Browse files
author
root
committed
Fix broken tests, add new tests, and remove things added for debugging
1 parent c845501 commit 95cafcd

12 files changed

+60
-17
lines changed

mypy/checker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,13 +3024,15 @@ def visit_decorator(self, e: Decorator) -> None:
30243024
self.check_untyped_after_decorator(sig, e.func)
30253025
sig = set_callable_name(sig, e.func)
30263026
if e.func.is_property:
3027-
assert isinstance(sig, CallableType)
3028-
sig = sig.ret_type
30293027
self.check_incompatible_property_override(e)
30303028
e.var.type = sig
30313029
e.var.is_ready = True
30323030
if isinstance(sig, CallableType):
3033-
e.is_callable = True
3031+
if e.func.is_property:
3032+
assert isinstance(sig, CallableType)
3033+
e.is_callable = isinstance(sig.ret_type, CallableType)
3034+
else:
3035+
e.is_callable = True
30343036
if e.func.info and not e.func.is_dynamic():
30353037
self.check_method_override(e)
30363038

mypy/checkmember.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def analyze_member_access(name: str,
7777

7878
# Look up the member. First look up the method dictionary.
7979
method = info.get_method(name)
80-
if method:
80+
if method and not method.is_class:
8181
if method.is_property:
8282
assert isinstance(method, OverloadedFuncDef)
8383
first_item = cast(Decorator, method.items[0])

mypy/errors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,6 @@ 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
599597
if not options.show_traceback:
600598
if not options.pdb:
601599
print('{}: note: please use --show-traceback to print a traceback '

mypy/fastparse.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,7 @@ 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-
expr = self.visit(n.func)
875-
return CallExpr(expr,
874+
return CallExpr(self.visit(n.func),
876875
arg_types,
877876
arg_kinds,
878877
cast(List[Optional[str]], [None] * len(n.args)) +

mypy/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ 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-
)
624621
internals_group.add_argument(
625622
'--custom-typing', metavar='MODULE', dest='custom_typing_module',
626623
help="Use a custom typing module")

mypy/options.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ 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
200199
self.dump_type_stats = False
201200
self.dump_inference_stats = False
202201

mypy/subtypes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,10 @@ def get_member_flags(name: str, info: TypeInfo) -> Set[int]:
572572
assert isinstance(dec, Decorator)
573573
if dec.var.is_settable_property or setattr_meth:
574574
return {IS_SETTABLE}
575-
return set()
575+
if method.is_static or method.is_class:
576+
return {IS_CLASS_OR_STATIC}
577+
else:
578+
return set()
576579
node = info.get(name)
577580
if not node:
578581
if setattr_meth:
@@ -604,7 +607,12 @@ def find_node_type(node: Union[Var, FuncBase], itype: Instance, subtype: Type) -
604607
if typ is None:
605608
return AnyType(TypeOfAny.from_error)
606609
# We don't need to bind 'self' for static methods, since there is no 'self'.
607-
if isinstance(node, FuncBase) or isinstance(typ, FunctionLike) and not node.is_staticmethod:
610+
need_bind = False
611+
if isinstance(node, FuncBase):
612+
need_bind = not node.is_static
613+
elif isinstance(typ, FunctionLike):
614+
need_bind = not node.is_staticmethod
615+
if need_bind:
608616
assert isinstance(typ, FunctionLike)
609617
signature = bind_self(typ, subtype)
610618
if node.is_property:

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-
raise_exceptions = True
11+
show_traceback = True
1212

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

test-data/unit/check-abstract.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class A(metaclass=ABCMeta):
749749
def x(self) -> int: pass
750750
class B(A):
751751
@property
752-
def x(self) -> str: pass # E: Signature of "x" incompatible with supertype "A"
752+
def x(self) -> str: pass # E: Return type of "x" incompatible with supertype "A"
753753
b = B()
754754
b.x() # E: "str" not callable
755755
[builtins fixtures/property.pyi]

test-data/unit/check-classes.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,3 +5501,29 @@ from typing import TypeVar, Tuple, Callable
55015501
T = TypeVar('T')
55025502
def deco(f: Callable[..., T]) -> Callable[..., Tuple[T, int]]: ...
55035503
[out]
5504+
5505+
[case testDecoratedInit]
5506+
from typing import Callable, Any
5507+
def dec(func: Callable[[Any], None]) -> Callable[[Any], None]:
5508+
return func
5509+
5510+
class A:
5511+
@dec
5512+
def __init__(self):
5513+
pass
5514+
5515+
reveal_type(A()) # E: Revealed type is '__main__.A'
5516+
[out]
5517+
5518+
[case testAbstractInit]
5519+
from abc import abstractmethod
5520+
class A:
5521+
@abstractmethod
5522+
def __init__(self): ...
5523+
5524+
class B(A):
5525+
def __init__(self):
5526+
pass
5527+
5528+
reveal_type(B()) # E: Revealed type is '__main__.B'
5529+
[out]

0 commit comments

Comments
 (0)