microsoft / python-language-server

Microsoft Language Server for Python
Apache License 2.0
915 stars 133 forks source link

Parse failure on decorator containing generator expression #1286

Open jekbradbury opened 5 years ago

jekbradbury commented 5 years ago

Code like the following:

  @parameterized.named_parameters(
      {"testcase_name": "_jit_scan={}_jit_f={}".format(jit_scan, jit_f),
       "jit_scan": jit_scan, "jit_f": jit_f}
      for jit_scan in [False, True]
      for jit_f in [False, True])
  def testScanImpl(self, jit_scan, jit_f):
    pass

fails to parse with the Python language server (giving unexpected token 'for'). This is the pattern used throughout tests for the https://github.com/google/jax codebase, and is valid Python code for (at least) 2.7 and 3.5+.

jakebailey commented 5 years ago

I get a different error, instead complaining about the last ) in the decorator. Surrounding the generator expression in [] seems to make it go away.

jakebailey commented 5 years ago

Writing this:

foo = (
    {"testcase_name": "_jit_scan={}_jit_f={}".format(jit_scan, jit_f),
    "jit_scan": jit_scan, "jit_f": jit_f}
    for jit_scan in [False, True]
    for jit_f in [False, True]
)

Does not produce any messages, so it's probably an issue in what we're allowing in the decorators.

A simple reproducer:

@foo(x for x in [])
def bar():
    pass