Skip to content

Commit 6963489

Browse files
committed
Some cleanup
1 parent d4a1ddf commit 6963489

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

mypy/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,7 @@ def fix_cross_refs(self) -> None:
28222822
assert fixer_state.node_fixer is not None
28232823
fixer_state.node_fixer.visit_symbol_table(self.tree.names)
28242824
type_fixer = fixer_state.node_fixer.type_fixer
2825+
# Eagerly fix shared instances, before they are used by named_type() calls.
28252826
if instance_cache.str_type is not None:
28262827
instance_cache.str_type.accept(type_fixer)
28272828
if instance_cache.function_type is not None:

mypy/fixup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, modules: dict[str, MypyFile], allow_missing: bool) -> None:
5555
# incremental cache load (since there may be cross-refs into deleted
5656
# modules)
5757
self.allow_missing = allow_missing
58-
self.type_fixer = TypeFixer(modules, allow_missing)
58+
self.type_fixer = TypeFixer(self.modules, allow_missing)
5959

6060
# NOTE: This method isn't (yet) part of the NodeVisitor API.
6161
def visit_type_info(self, info: TypeInfo) -> None:
@@ -123,17 +123,17 @@ def visit_symbol_table(self, symtab: SymbolTable) -> None:
123123
value.cross_ref = None
124124
value.unfixed = False
125125
value._node = self.modules[cross_ref]
126+
# TODO: this should not be needed, looks like a daemon bug.
126127
elif self.allow_missing:
127-
# TODO: this should not be needed, looks like a daemon bug.
128128
self.resolve_cross_ref(value)
129129
# Look at private attribute to avoid triggering fixup eagerly.
130130
elif isinstance(value._node, TypeInfo):
131-
# TypeInfo has no accept().
132131
self.visit_type_info(value._node)
133132
else:
134133
value.stored_info = self.current_info
135134

136135
def resolve_cross_ref(self, value: SymbolTableNode) -> None:
136+
"""Replace cross-reference with an actual referred node."""
137137
assert value.cross_ref is not None
138138
cross_ref = value.cross_ref
139139
value.cross_ref = None

mypy/nodes.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4731,9 +4731,10 @@ class SymbolTableNode:
47314731
they should be correct.
47324732
47334733
Attributes:
4734-
node: AST node of definition. Among others, this can be one of
4734+
_node: AST node of definition. Among others, this can be one of
47354735
FuncDef, Var, TypeInfo, TypeVarExpr or MypyFile -- or None
4736-
for cross_ref that hasn't been fixed up yet.
4736+
for cross_ref that hasn't been fixed up yet. Should not be accessed
4737+
directly, only via the `node` property.
47374738
kind: Kind of node. Possible values:
47384739
- LDEF: local definition
47394740
- GDEF: global (module-level) definition
@@ -4743,25 +4744,20 @@ class SymbolTableNode:
47434744
module_public: If False, this name won't be imported via
47444745
'from <module> import *'. This has no effect on names within
47454746
classes.
4746-
module_hidden: If True, the name will be never exported (needed for
4747+
module_hidden: If True, the name will never be exported (needed for
47474748
stub files)
47484749
cross_ref: For deserialized MypyFile nodes, the referenced module
47494750
name; for other nodes, optionally the name of the referenced object.
47504751
implicit: Was this defined by assignment to self attribute?
47514752
plugin_generated: Was this symbol generated by a plugin?
47524753
(And therefore needs to be removed in aststrip.)
4753-
no_serialize: Do not serialize this node if True. This is used to prevent
4754-
keys in the cache that refer to modules on which this file does not
4755-
depend. Currently this can happen if there is a module not in build
4756-
used e.g. like this:
4757-
import a.b.c # type: ignore
4758-
This will add a submodule symbol to parent module `a` symbol table,
4759-
but `a.b` is _not_ added as its dependency. Therefore, we should
4760-
not serialize these symbols as they may not be found during fixup
4761-
phase, instead they will be re-added during subsequent patch parents
4762-
phase.
4763-
TODO: Refactor build.py to make dependency tracking more transparent
4764-
and/or refactor look-up functions to not require parent patching.
4754+
no_serialize: Do not serialize this node if True. This is used for internal
4755+
and/or temporary symbols such as function redefinitions.
4756+
unfixed: Indicates that this symbol is fresh after deserialization and
4757+
needs fixup, such as resolving cross-references etc.
4758+
stored_info: TypeInfo containing this symbol. Normally code accesses this
4759+
on the `node` attribute, but it may be not ready during deserialization,
4760+
so we temporarily store info on the symbol itself.
47654761
47664762
NOTE: No other attributes should be added to this class unless they
47674763
are shared by all node kinds.
@@ -4831,6 +4827,7 @@ def node(self) -> SymbolNode | None:
48314827
assert node is not None
48324828
if self.stored_info is not None:
48334829
set_info(node, self.stored_info)
4830+
self.stored_info = None
48344831
node.accept(node_fixer)
48354832
self.unfixed = False
48364833
return self._node
@@ -5276,6 +5273,7 @@ def local_definitions(
52765273

52775274

52785275
def set_info(node: SymbolNode, info: TypeInfo) -> None:
5276+
"""Add `info` attribute to all relevant components of the node."""
52795277
if isinstance(node, (FuncDef, Var)):
52805278
node.info = info
52815279
elif isinstance(node, Decorator):

mypy/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def __init__(self) -> None:
299299
# Caching and incremental checking options
300300
self.incremental = True
301301
self.cache_dir = defaults.CACHE_DIR
302-
self.sqlite_cache = False
302+
self.sqlite_cache = True
303303
self.fixed_format_cache = True
304304
self.debug_cache = False
305305
self.skip_version_check = False

mypy/plugins/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ def add_attribute_to_class(
433433
return node
434434

435435

436+
# We keep the unused `api` parameter, to avoid breaking 3rd party dataclass-like plugins.
436437
def deserialize_and_fixup_type(data: str | JsonDict, api: SemanticAnalyzerPluginInterface) -> Type:
437438
typ = deserialize_type(data)
438439
assert fixer_state.node_fixer is not None

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7148,7 +7148,7 @@ def add_redefinition(self, names: SymbolTable, name: str, symbol: SymbolTableNod
71487148
i = 1
71497149
# Don't serialize redefined nodes. They are likely to have
71507150
# busted internal references which can cause problems with
7151-
# serialization and they can't have any external references to
7151+
# serialization, and they can't have any external references to
71527152
# them.
71537153
symbol.no_serialize = True
71547154
while True:

0 commit comments

Comments
 (0)