Skip to content

Walrus target inside a module-level comprehension gets a malformed symbol (e.g. y.) #248

Open

Description

@ansonauhk

Summary

When an assignment expression (:=) appears inside a list, set or dict comprehension or a generator expression at module scope, scip-python emits the target with a bare descriptor as its symbol (y., z., k., w.), with no scheme, manager, package name or version. These symbols do not parse under the SCIP symbol grammar, and scip lint rejects them.

A plain walrus at module scope (outside any comprehension) is fine: it gets scip-python python walrus-repro 0.1.0 toplevel/n.. The same comprehensions inside a function body are also fine: their targets become local N.

Versions

  • scip-python 0.6.8 (npm), and a build of the scip branch at 51dd05f (built with npm ci --ignore-scripts in packages/pyright-internal and packages/pyright-scip, then npm run build in packages/pyright-scip). Both give identical scip print output.
  • Node v26.13.0
  • Python 3.15.0
  • scip CLI v0.10.0 (for print and lint)
  • macOS (arm64)

Repro

pyproject.toml:

[project]
name = "walrus-repro"
version = "0.1.0"

toplevel.py:

xs = [1, 2, 3]

if (n := len(xs)) > 0:
    pass

a = [y for x in xs if (y := x * 2) > 1]
b = {z for x in xs if (z := x + 1)}
c = {k: k for x in xs if (k := str(x))}
d = list(w for x in xs if (w := x - 1))

Command, run in that directory:

npx @sourcegraph/scip-python@0.6.8 index --project-name walrus-repro --project-version 0.1.0 --output index.scip
scip print --json index.scip
scip lint index.scip

Actual

Occurrences in toplevel.py (from scip print --json; range, symbol, symbol_roles):

[2, 4, 5]    'scip-python python walrus-repro 0.1.0 toplevel/n.'   1   <- control: OK
[5, 5, 6]    'y.'  8
[5, 23, 24]  'y.'  1
[6, 5, 6]    'z.'  8
[6, 23, 24]  'z.'  1
[7, 5, 6]    'k.'  8
[7, 8, 9]    'k.'  8
[7, 26, 27]  'k.'  1
[8, 9, 10]   'w.'  8
[8, 27, 28]  'w.'  1

scip lint index.scip:

error: found occurrence at toplevel.py @ 2:4-2:5 for symbol scip-python python walrus-repro 0.1.0 toplevel/n., but there is no matching SymbolInformation in external symbols or any document
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character
reached end of symbol while parsing <scheme>, expected a '32' character

The nine parse errors match the nine y./z./k./w. occurrences. (The first line, missing SymbolInformation for toplevel/n., is a separate matter.)

Why this is invalid

The Symbol comment in scip.proto defines:

<symbol> ::= <scheme> ' ' <package> ' ' (<descriptor>)+ | 'local ' <local-id>

y. is a single <descriptor> with no <scheme> and <package>, and it is not a local symbol, so it matches neither alternative. Consumers that parse symbols per the spec reject it.

Expected

Per PEP 572, an assignment expression in a comprehension or generator expression binds its target in the containing scope. At module level that is the module, so y, z, k and w are module globals, like n. Expected symbols, consistent with the control:

scip-python python walrus-repro 0.1.0 toplevel/y.
scip-python python walrus-repro 0.1.0 toplevel/z.
scip-python python walrus-repro 0.1.0 toplevel/k.
scip-python python walrus-repro 0.1.0 toplevel/w.

At minimum, a well-formed symbol (a global as above, or a local N) rather than a bare descriptor.

Related

#117, #8 and #80 cover the walrus operator in general. The existing snapshot packages/pyright-scip/snapshots/output/unique/walrus.py already contains this case (a module-level generator expression) and records the bare symbol for both the definition and a later reference outside the generator:

if any((any_n := num) < 0 for num in some_list):
#       ^^^^^ definition any_n.
    print(f"Negative number found: {any_n}")
#                                   ^^^^^ reference any_n.

So the snapshot locks in the malformed output rather than catching it. #148 was a similar malformed-symbol issue for lambdas.

Activity

  1. linear-code commented on Nov 17, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions