Skip to content

Commit d394829

Browse files
committed
Try #2, with less FuncDef
1 parent 66a0b84 commit d394829

File tree

7 files changed

+52
-42
lines changed

7 files changed

+52
-42
lines changed

mypy/nodes.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def __str__(self) -> str:
379379

380380

381381
FUNCBASE_FLAGS = [
382-
'is_property', 'is_class', 'is_static', 'is_final', 'plugin_generated'
382+
'is_property', 'is_class', 'is_static', 'is_final'
383383
] # type: Final
384384

385385

@@ -394,7 +394,6 @@ class FuncBase(Node):
394394
'is_static', # Uses "@staticmethod"
395395
'is_final', # Uses "@final"
396396
'_fullname',
397-
'plugin_generated',
398397
)
399398

400399
def __init__(self) -> None:
@@ -411,7 +410,6 @@ def __init__(self) -> None:
411410
self.is_class = False
412411
self.is_static = False
413412
self.is_final = False
414-
self.plugin_generated = False
415413
# Name with module prefix
416414
# TODO: Type should be Optional[str]
417415
self._fullname = cast(Bogus[str], None)
@@ -2703,6 +2701,7 @@ class SymbolTableNode:
27032701
'module_hidden',
27042702
'cross_ref',
27052703
'implicit',
2704+
'plugin_generated',
27062705
'no_serialize',
27072706
)
27082707

@@ -2721,7 +2720,7 @@ def __init__(self,
27212720
self.implicit = implicit
27222721
self.module_hidden = module_hidden
27232722
self.cross_ref = None # type: Optional[str]
2724-
# self.plugin_generated = plugin_generated
2723+
self.plugin_generated = plugin_generated
27252724
self.no_serialize = no_serialize
27262725

27272726
@property
@@ -2778,8 +2777,8 @@ def serialize(self, prefix: str, name: str) -> JsonDict:
27782777
data['module_public'] = False
27792778
if self.implicit:
27802779
data['implicit'] = True
2781-
# if self.plugin_generated:
2782-
# data['plugin_generated'] = True
2780+
if self.plugin_generated:
2781+
data['plugin_generated'] = True
27832782
if self.kind == MODULE_REF:
27842783
assert self.node is not None, "Missing module cross ref in %s for %s" % (prefix, name)
27852784
data['cross_ref'] = self.node.fullname()
@@ -2813,8 +2812,8 @@ def deserialize(cls, data: JsonDict) -> 'SymbolTableNode':
28132812
stnode.module_public = data['module_public']
28142813
if 'implicit' in data:
28152814
stnode.implicit = data['implicit']
2816-
# if 'plugin_generated' in data:
2817-
# stnode.plugin_generated = data['plugin_generated']
2815+
if 'plugin_generated' in data:
2816+
stnode.plugin_generated = data['plugin_generated']
28182817
return stnode
28192818

28202819

mypy/plugin.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ def lookup_qualified(self, name: str, ctx: Context,
113113
suppress_errors: bool = False) -> Optional[SymbolTableNode]:
114114
raise NotImplementedError
115115

116-
@abstractmethod
117-
def add_symbol_to_type(self, info: TypeInfo, name: str, node: SymbolTableNode) -> None:
118-
raise NotImplementedError
119-
120116

121117
# A context for a function hook that infers the return type of a function with
122118
# a special signature.

mypy/plugins/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def _add_method(
109109
func.type = set_callable_name(signature, func)
110110
func._fullname = info.fullname() + '.' + name
111111
func.line = info.line
112-
func.plugin_generated = True
113112

114-
info.names[name] = SymbolTableNode(MDEF, func)
113+
info.names[name] = SymbolTableNode(MDEF, func, plugin_generated=True)
115114
info.defn.defs.body.append(func)

mypy/semanal.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,9 +3375,6 @@ def create_getattr_var(self, getattr_defn: SymbolTableNode,
33753375
return SymbolTableNode(GDEF, v)
33763376
return None
33773377

3378-
def add_symbol_to_type(self, info: TypeInfo, name: str, node: SymbolTableNode) -> None:
3379-
pass
3380-
33813378
def rebind_symbol_table_node(self, n: SymbolTableNode) -> Optional[SymbolTableNode]:
33823379
"""If node refers to old version of module, return reference to new version.
33833380
@@ -3570,7 +3567,6 @@ def name_already_defined(self, name: str, ctx: Context,
35703567
node = original_ctx.node
35713568
elif isinstance(original_ctx, SymbolNode):
35723569
node = original_ctx
3573-
# import pdb; pdb.set_trace()
35743570

35753571
if isinstance(original_ctx, SymbolTableNode) and original_ctx.kind == MODULE_REF:
35763572
# Since this is an import, original_ctx.node points to the module definition.

mypy/server/aststrip.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
"""
3939

4040
import contextlib
41-
from typing import Union, Iterator, Optional
41+
from typing import Union, Iterator, Optional, List
4242

4343
from mypy.nodes import (
4444
Node, FuncDef, NameExpr, MemberExpr, RefExpr, MypyFile, FuncItem, ClassDef, AssignmentStmt,
4545
ImportFrom, Import, TypeInfo, SymbolTable, Var, CallExpr, Decorator, OverloadedFuncDef,
4646
SuperExpr, UNBOUND_IMPORTED, GDEF, MDEF, IndexExpr, SymbolTableNode, ImportAll, TupleExpr,
47-
ListExpr, ForStmt, Block, FuncBase,
47+
ListExpr, ForStmt, Block, SymbolNode, FuncBase,
4848
)
4949
from mypy.semanal_shared import create_indirect_imported_name
5050
from mypy.traverser import TraverserVisitor
@@ -90,21 +90,17 @@ def visit_block(self, b: Block) -> None:
9090

9191
def visit_class_def(self, node: ClassDef) -> None:
9292
"""Strip class body and type info, but don't strip methods."""
93-
self.strip_type_info(node.info)
93+
to_delete = set(self.strip_type_info(node.info))
9494
node.type_vars = []
9595
node.base_type_exprs.extend(node.removed_base_type_exprs)
9696
node.removed_base_type_exprs = []
97-
print(node.defs.body)
9897
node.defs.body = [s for s in node.defs.body
99-
if not (isinstance(s, FuncBase) and s.plugin_generated)]
100-
print(node.defs.body)
98+
if s not in to_delete]
10199

102100
with self.enter_class(node.info):
103101
super().visit_class_def(node)
104102

105-
def strip_type_info(self, info: TypeInfo) -> None:
106-
print("stripping", info.fullname())
107-
103+
def strip_type_info(self, info: TypeInfo) -> List[SymbolNode]:
108104
info.type_vars = []
109105
info.bases = []
110106
info.is_abstract = False
@@ -118,12 +114,12 @@ def strip_type_info(self, info: TypeInfo) -> None:
118114
info.declared_metaclass = None
119115
info.metaclass_type = None
120116

121-
to_delete = [k for k, v in info.names.items()
122-
if isinstance(v.node, FuncBase) and v.node.plugin_generated]
123-
# print("YO HOW BOUT THIS", to_delete, info.names.items())
124-
for k in to_delete:
117+
# We need to delete any entries that were generated by plugins,
118+
# since they will get regenerated.
119+
to_delete = [(k, v) for k, v in info.names.items() if v.plugin_generated]
120+
for k, _ in to_delete:
125121
del info.names[k]
126-
# import pdb; pdb.set_trace()
122+
return [v.node for k, v in to_delete if v.node]
127123

128124
def visit_func_def(self, node: FuncDef) -> None:
129125
if not self.recurse_into_functions:

mypy/server/update.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,6 @@ def reprocess_nodes(manager: BuildManager,
846846
module_id)
847847
return set()
848848

849-
nodeset_ = set(s for s in nodeset
850-
if not (isinstance(s.node, FuncBase) and s.node.plugin_generated))
851-
print(nodeset_ - nodeset)
852-
nodeset = nodeset_
853-
print(nodeset)
854-
855849
file_node = manager.modules[module_id]
856850
old_symbols = find_symbol_tables_recursive(file_node.fullname(), file_node.names)
857851
old_symbols = {name: names.copy() for name, names in old_symbols.items()}
@@ -891,7 +885,6 @@ def key(node: FineGrainedDeferredNode) -> int:
891885
fnam=file_node.path,
892886
options=options,
893887
active_type=deferred.active_typeinfo):
894-
# import pdb; pdb.set_trace()
895888
manager.semantic_analyzer.refresh_partial(deferred.node, patches)
896889

897890
# Third pass of semantic analysis.
@@ -985,7 +978,9 @@ def update_deps(module_id: str,
985978

986979

987980
def lookup_target(manager: BuildManager,
988-
target: str) -> Tuple[List[FineGrainedDeferredNode], Optional[TypeInfo]]:
981+
target: str,
982+
promote_generated: bool = True,
983+
) -> Tuple[List[FineGrainedDeferredNode], Optional[TypeInfo]]:
989984
"""Look up a target by fully-qualified name.
990985
991986
The first item in the return tuple is a list of deferred nodes that
@@ -1020,6 +1015,11 @@ def not_found() -> None:
10201015
or c not in node.names):
10211016
not_found() # Stale dependency
10221017
return [], None
1018+
if node.names[c].plugin_generated:
1019+
if not promote_generated:
1020+
return [], None
1021+
target = node.fullname()
1022+
break
10231023
node = node.names[c].node
10241024
if isinstance(node, TypeInfo):
10251025
# A ClassDef target covers the body of the class and everything defined
@@ -1040,7 +1040,7 @@ def not_found() -> None:
10401040
for name, symnode in node.names.items():
10411041
node = symnode.node
10421042
if isinstance(node, FuncDef):
1043-
method, _ = lookup_target(manager, target + '.' + name)
1043+
method, _ = lookup_target(manager, target + '.' + name, promote_generated=False)
10441044
result.extend(method)
10451045
return result, stale_info
10461046
if isinstance(node, Decorator):

test-data/unit/fine-grained.test

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,32 @@ B(1, 2)
691691
b.py:8: error: Argument 1 to "B" has incompatible type "int"; expected "str"
692692
[builtins fixtures/list.pyi]
693693

694+
[case testDataclassUpdate3]
695+
# flags: --python-version 3.6
696+
from b import B
697+
B(1, 2)
698+
[file b.py]
699+
from a import A
700+
from dataclasses import dataclass
701+
@dataclass
702+
class B(A):
703+
b: int
704+
[file a.py]
705+
from dataclasses import dataclass
706+
@dataclass
707+
class A:
708+
a: int
694709

695-
710+
[file a.py.2]
711+
from dataclasses import dataclass
712+
@dataclass
713+
class A:
714+
a: int
715+
other: int
716+
[builtins fixtures/list.pyi]
717+
[out]
718+
==
719+
main:3: error: Too few arguments for "B"
696720

697721
[case testAddBaseClassMethodCausingInvalidOverride]
698722
import m

0 commit comments

Comments
 (0)