@@ -2233,19 +2233,53 @@ def __getattribute__(self, attr: str) -> None:
2233
2233
2234
2234
2235
2235
class SymbolTableNode :
2236
+ """Description of a name binding in a symbol table.
2237
+
2238
+ These are only used as values in module (global), function (local)
2239
+ and class symbol tables (see SymbolTable). The name that is bound is
2240
+ the key in SymbolTable.
2241
+
2242
+ Symbol tables don't contain direct references to AST nodes primarily
2243
+ because there can be multiple symbol table references to a single
2244
+ AST node (due to imports and aliases), and different references can
2245
+ behave differently. This class describes the unique properties of
2246
+ each reference.
2247
+
2248
+ The most fundamental attributes are 'kind' and 'node'. The 'node'
2249
+ attribute defines the AST node that the name refers to.
2250
+
2251
+ For many bindings, including those targeting variables, functions
2252
+ and classes, the kind is one of LDEF, GDEF or MDEF, depending on the
2253
+ scope of the definition. These three kinds can usually be used
2254
+ interchangeably and the difference between local, global and class
2255
+ scopes is mostly descriptive, with no semantic significance.
2256
+ However, some tools that consume mypy ASTs may care about these so
2257
+ they should be correct.
2258
+
2259
+ A few definitions get special kinds, including type variables (TVAR),
2260
+ imported modules and module aliases (MODULE_REF), and type aliases
2261
+ (TYPE_ALIAS).
2262
+
2263
+ Type aliases are very special and have additional attributes that
2264
+ are only used for them ('type_override', 'alias_tvars' at least).
2265
+ """
2266
+ # TODO: This is a mess. Refactor!
2267
+ # TODO: Describe how type aliases work.
2268
+
2236
2269
# Kind of node. Possible values:
2237
- # - LDEF: local definition (of any kind)
2270
+ # - LDEF: local definition
2238
2271
# - GDEF: global (module-level) definition
2239
2272
# - MDEF: class member definition
2240
- # - TVAR: TypeVar(...) definition
2273
+ # - TVAR: TypeVar(...) definition in any scope
2241
2274
# - MODULE_REF: reference to a module
2242
2275
# - TYPE_ALIAS: type alias
2243
- # - UNBOUND_IMPORTED: temporary kind for imported names
2276
+ # - UNBOUND_IMPORTED: temporary kind for imported names (we don't know the final kind yet)
2244
2277
kind = None # type: int
2245
- # AST node of definition (FuncDef/Var/TypeInfo/Decorator/ TypeVarExpr,
2278
+ # AST node of definition (among others, this can be FuncDef/Var/TypeInfo/TypeVarExpr/MypyFile ,
2246
2279
# or None for a bound type variable).
2247
2280
node = None # type: Optional[SymbolNode]
2248
- # If this not None, override the type of the 'node' attribute.
2281
+ # If this not None, override the type of the 'node' attribute. This is only used for
2282
+ # type aliases.
2249
2283
type_override = None # type: Optional[mypy.types.Type]
2250
2284
# For generic aliases this stores the (qualified) names of type variables.
2251
2285
# (For example see testGenericAliasWithTypeVarsFromDifferentModules.)
@@ -2258,7 +2292,9 @@ class SymbolTableNode:
2258
2292
# For deserialized MODULE_REF nodes, the referenced module name;
2259
2293
# for other nodes, optionally the name of the referenced object.
2260
2294
cross_ref = None # type: Optional[str]
2261
- # Was this node created by normalіze_type_alias?
2295
+ # Used to distinguish between 'typing.List' and 'builtins.list'. This is
2296
+ # True when the former has been normalized to the latter, and it allow us
2297
+ # to reject 'list[str]' and similar.
2262
2298
normalized = False # type: bool
2263
2299
# Was this defined by assignment to self attribute?
2264
2300
implicit = False # type: bool
0 commit comments