pappasam / jedi-language-server

A Python language server exclusively for Jedi. If Jedi supports it well, this language server should too.
MIT License
572 stars 44 forks source link

walrus detected incorrectly as keyword argument #250

Open mgzenitech opened 1 year ago

mgzenitech commented 1 year ago
    entrypoint_type: str = select(
        next_argument_number := next_argument_number + 1,
        "Please select entrypoint type:",
        [
            {
                "name": item.name,
                "value": item.name
            }
            for item in ENTRYPOINT_TEMPLATE_PATH.glob("*")
            if item.is_dir()
        ]
    )

2023-01-05 11:28:48  569x232 2023-01-05 11:29:13  547x41

pappasam commented 1 year ago

I believe this issue represents a limitation of our current syntax checking, which uses Python's built-in compile function, which is tied to the specific Python version that is running jedi-language-server itself: https://github.com/pappasam/jedi-language-server/pull/242/files

To get around this issue (for now), you'll need to either:

  1. install and run jedi-language-server with a version of Python that supports the Walrus operator and this specific use of it (3.8+, I'd guess)
  2. Disable jedi-language-server-provided diagnostics syntax checking using the provided initialization option (diagnostics.enable: false): https://github.com/pappasam/jedi-language-server#configuration
davidhalter commented 1 year ago

I feel like the walrus operator should be supported. This was a feature before 3.10... So I'm a bit confused. This is probably using Python pre-3.8.

mgzenitech commented 1 year ago

2023-01-06 11:38:18  1312x1022 I am using Python 3.10.8

davidhalter commented 1 year ago

Is there a chance that you have a virtualenv or a way of running pre-3.8? Because it might somehow pick up an older environment for some reason.

mgzenitech commented 1 year ago

As I said 3.10.8 in virtualenv (you can see the interpreter in screenshot bottom right corner)

davidhalter commented 1 year ago

Jedi has a separate subprocess, so there was a possibility that that somehow was broken.

However I was able to reproduce it with a very simple:

>>> import jedi
>>> x = jedi.Script('f(a := 1, b)\n').get_syntax_errors()
>>> x[0].get_message()
'SyntaxError: positional argument follows keyword argument'
>>> jedi.Script('f(a := 1)\n').get_syntax_errors()
[]

Note that Jedi/Parso can deal with walruses, it's just a small parso error. Created https://github.com/davidhalter/parso/issues/212 for it.