Implement normalization for GlobalExpr
@@ -411,35 +411,23 @@ def normalize_GroupQuery(
raise AssertionError(f'normalize: cannot handle {node!r}')
-@normalize.register
-def compile_Path(
- node: qlast.Path,
+def _normalize_objref(
+ ref: qlast.ObjectRef,
*,
schema: s_schema.Schema,
modaliases: Mapping[Optional[str], str],
localnames: AbstractSet[str] = frozenset(),
) -> None:
-
- for step in node.steps:
- if isinstance(step, (qlast.Expr, qlast.TypeIntersection)):
- normalize(
- step,
- schema=schema,
- modaliases=modaliases,
- localnames=localnames,
- )
- elif isinstance(step, qlast.ObjectRef):
- # This is a specific path root, resolve it.
- if not step.module and step.name not in localnames:
+ if not ref.module and ref.name not in localnames:
obj = schema.get(
- step.name,
+ ref.name,
default=None,
module_aliases=modaliases,
)
if obj is not None:
name = obj.get_name(schema)
assert isinstance(name, sn.QualName)
- step.module = name.module
+ ref.module = name.module
elif None in modaliases:
# Even if the name was not resolved in the
# schema it may be the name of the object
@@ -447,7 +435,34 @@ def compile_Path(
# should be used. Names that must be ignored
# (like aliases and parameters) have already
# been filtered by the localnames.
- step.module = modaliases[None]
+ ref.module = modaliases[None]
+
+
+@normalize.register
+def normalize_Path(
+ node: qlast.Path,
+ *,
+ schema: s_schema.Schema,
+ modaliases: Mapping[Optional[str], str],
+ localnames: AbstractSet[str] = frozenset(),
+) -> None:
+
+ for step in node.steps:
+ if isinstance(step, (qlast.Expr, qlast.TypeIntersection)):
+ normalize(
+ step,
+ schema=schema,
+ modaliases=modaliases,
+ localnames=localnames,
+ )
+ elif isinstance(step, qlast.ObjectRef):
+ # This is a specific path root, resolve it.
+ _normalize_objref(
+ step,
+ schema=schema,
+ modaliases=modaliases,
+ localnames=localnames,
+ )
@normalize.register
@@ -531,3 +546,19 @@ def compile_TypeName(
modaliases=modaliases,
localnames=localnames,
)
+
+
+@normalize.register
+def normalize_GlobalExpr(
+ node: qlast.GlobalExpr,
+ *,
+ schema: s_schema.Schema,
+ modaliases: Mapping[Optional[str], str],
+ localnames: AbstractSet[str] = frozenset(),
+) -> None:
+ _normalize_objref(
+ node.name,
+ schema=schema,
+ modaliases=modaliases,
+ localnames=localnames,
+ )
