hauntsaninja / no_implicit_optional

A codemod to make your implicit optional type hints PEP 484 compliant.
MIT License
79 stars 8 forks source link

match statement causes libcst._exceptions.ParserSyntaxError: #9

Closed MattHolmes123 closed 1 year ago

MattHolmes123 commented 1 year ago

This script causes a libcst._exceptions.ParserSyntaxError to be thrown:

def foo(bar: str = None):
    match bar:
        case "hey":
            print("Hi there")
        case _:
            print("default")

if __name__ == "__main__":
    foo("hey")
    foo("howdy")

Running this causes an exception: pipx run no_implicit_optional example.py

Traceback (most recent call last):
  File "/Users/matthewholmes/.local/pipx/.cache/94ee2c53f07b928/lib/python3.10/site-packages/libcst/_parser/base_parser.py", line 151, in _add_token
    plan = stack[-1].dfa.transitions[transition]
KeyError: TokenType(NAME)

During handling of the above exception, another exception occurred:

...

    raise ParserSyntaxError(
libcst._exceptions.ParserSyntaxError: Syntax Error @ 4:11.
Incomplete input. Encountered 'bar', but expected ';', or 'NEWLINE'.

    match bar:
          ^
hauntsaninja commented 1 year ago

Thanks, similar to #8 , this is a shortcoming of libcst, the library we use to obtain a concrete syntax tree. Could you try with setting export LIBCST_PARSER_TYPE=native? If that doesn't work unfortunately there's not too much I can do in this library.

MattHolmes123 commented 1 year ago

That works thanks. 👍