Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fperrin fix 11899 rebase 2022 06 24 #6

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,12 @@ def [T <: int] f(self, x: int, y: T) -> None
s += ' = ...'

# If we got a "special arg" (i.e: self, cls, etc...), prepend it to the arg list
if isinstance(tp.definition, FuncDef) and tp.definition.name is not None:
if (isinstance(tp.definition, FuncDef) and
tp.definition.name is not None and
tp.definition.arguments):
definition_args = [arg.variable.name for arg in tp.definition.arguments]
if definition_args and tp.arg_names != definition_args \
and len(definition_args) > 0 and definition_args[0]:
if (tp.arg_names != definition_args and
definition_args[0]):
if s:
s = ', ' + s
s = definition_args[0] + s
Expand Down
5 changes: 2 additions & 3 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def set_line(self,
class FuncItem(FuncBase):
"""Base class for nodes usable as overloaded function items."""

__slots__ = ('arguments', # Note that can be None if deserialized (type is a lie!)
__slots__ = ('arguments', # Note that can be empty if deserialized
'arg_names', # Names of arguments
'arg_kinds', # Kinds of arguments
'min_args', # Minimum number of arguments
Expand All @@ -665,7 +665,7 @@ class FuncItem(FuncBase):
'expanded', # Variants of function with type variables with values expanded
)

__deletable__ = ('arguments', 'max_pos', 'min_args')
__deletable__ = ('max_pos', 'min_args')

def __init__(self,
arguments: Optional[List[Argument]] = None,
Expand Down Expand Up @@ -780,7 +780,6 @@ def deserialize(cls, data: JsonDict) -> 'FuncDef':
ret.arg_names = data['arg_names']
ret.arg_kinds = [ArgKind(x) for x in data['arg_kinds']]
# Leave these uninitialized so that future uses will trigger an error
del ret.arguments
del ret.max_pos
del ret.min_args
return ret
Expand Down
17 changes: 7 additions & 10 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,16 +1524,13 @@ def __init__(self,
# after serialization, but it is useful in error messages.
# TODO: decide how to add more info here (file, line, column)
# without changing interface hash.
self.def_extras = {
'first_arg': (
definition.arguments[0].variable.name
if (getattr(definition, 'arguments', None)
and definition.arg_names
and definition.info
and not definition.is_static)
else None
),
}
first_arg: Optional[str] = None
if definition.info and not definition.is_static:
if definition.arguments:
first_arg = definition.arguments[0].variable.name
elif definition.arg_names:
first_arg = definition.arg_names[0]
self.def_extras = {'first_arg': first_arg}
else:
self.def_extras = {}
self.type_guard = type_guard
Expand Down
8 changes: 4 additions & 4 deletions mypyc/irbuild/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def fdef_to_sig(self, fdef: FuncDef) -> FuncSignature:
# the sole way that FuncDecl arguments are tracked. This is
# generally fine except in some cases (like for computing
# init_sig) we need to produce FuncSignatures from a
# deserialized FuncDef that lacks arguments. We won't ever
# need to use those inside of a FuncIR, so we just make up
# some crap.
if hasattr(fdef, 'arguments'):
# deserialized FuncDef where arguments is the empty list. We
# won't ever need to use those inside of a FuncIR, so we just
# make up some crap.
if fdef.arguments:
arg_names = [arg.variable.name for arg in fdef.arguments]
else:
arg_names = [name or '' for name in fdef.arg_names]
Expand Down
32 changes: 32 additions & 0 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -3190,3 +3190,35 @@ from dir1 import *
from .test2 import *
[file dir1/test2.py]
from test1 import aaaa # E: Module "test1" has no attribute "aaaa"

[case testIncompatibleOverrideFromCachedModuleIncremental]
import b
[file a.py]
class Foo:
def frobnicate(self, *args, **kwargs): pass
[file b.py]
from a import Foo
class Bar(Foo):
def frobnicate(self) -> None: pass
[file b.py.2]
from a import Foo
class Bar(Foo):
def frobnicate(self, *args) -> None: pass
[file b.py.3]
from a import Foo
class Bar(Foo):
def frobnicate(self, *args) -> None: pass # type: ignore[override] # I know
[builtins fixtures/tuple.pyi]
[builtins fixtures/dict.pyi]
[out1]
tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo"
tmp/b.py:3: note: Superclass:
tmp/b.py:3: note: def frobnicate(self, *args: Any, **kwargs: Any) -> Any
tmp/b.py:3: note: Subclass:
tmp/b.py:3: note: def frobnicate(self) -> None
[out2]
tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo"
tmp/b.py:3: note: Superclass:
tmp/b.py:3: note: def frobnicate(self, *args: Any, **kwargs: Any) -> Any
tmp/b.py:3: note: Subclass:
tmp/b.py:3: note: def frobnicate(self, *args: Any) -> None