Skip to content

Walrus operator marked as syntax error #94

Closed

Description

@alexchandel

The new walrus operator is marked as a syntax error in Pynsource 1.77:

Syntax error in parsing
'.../main.py'

'invalid syntax' on line 14:

if (pair := chairs.get(number, None)) is None:

Activity

  1. abulka commented on Jun 29, 2021

    @abulka
    Owner

    This seems to pass OK under Python 3.9

    def test_issue_walrus_issue_94(self):
        source_code = dedent("""
            if (pair := chairs.get(number, None)) is None:
                pass
        """
        )
        pmodel, debuginfo = parse_source(source_code, 
                                            options={"mode": 3}, 
                                            html_debug_root_name="test_issue_walrus_issue_94")
        self.assertNotIn("error", pmodel.errors)

    Perhaps this error only happens with a lower version of Python - will need to check. As it stands, it looks promising that no changes to the Pynsource parser are needed, only a Python version bump. That is, assuming the source code fragment above reproduces the problem.

  2. added a commit that references this issue on Jun 29, 2021
  3. added a commit that references this issue on Jul 1, 2021
  4. alexchandel commented on Jul 2, 2021

    @alexchandel
    Author

    I think walrus entered in 3.8. I have 3.9 installed in /usr/local (macOS) but I assume you don't use that. Source fragment was something like:

    chairs: dict[int, str]
    number: int
    ...
    if (pair := chairs.get(number, None)) is None:
        ...
  5. abulka commented on Jul 8, 2021

    @abulka
    Owner

    Latest master branch and 1.78 beta binary release should have fixed this.
    Official 1.78 release only a few days away.

    Note: Ubuntu Snap is stuck at Python 3.6 till Canonical fix their Snapcraft core20 stuff.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions