pytype icon indicating copy to clipboard operation
pytype copied to clipboard

--quick doesn't look inside generators?

Open taralx opened this issue 4 years ago • 7 comments

Testcase:

from typing import List

def f(d: int) -> int:
    return d + 1

def g(l: List[str]) -> List[str]:
    return list(f(x) for x in l)

Running pytype-single --quick says it's fine, but running without that flag reveals the error:

File "testcase.py", line 7, in g: Function f was called with the wrong arguments [wrong-arg-types]
         Expected: (d: int)
  Actually passed: (d: str)

taralx avatar May 27 '21 02:05 taralx

Also tried running with the various other optional flags (e.g. protocols) and they don't fix the problem.

taralx avatar May 27 '21 02:05 taralx

I believe the issue here is that --quick restricts the analysis depth, so it sees g() calls list() calls a generator, and it gives up at that point because it hits maximum call depth. The only way to really fix this is to increase the maximum depth, which has potential performance implications.

rchen152 avatar Jun 01 '21 22:06 rchen152

Is there a way to specifically override maximum call depth?

taralx avatar Jun 01 '21 22:06 taralx

There's no way to pass in a specific maximum call depth, no; you can choose to not use --quick which will remove the limit altogether.

rchen152 avatar Jun 02 '21 00:06 rchen152

But there's no way to remove --quick when running over a package, only for a single file. People have previously been told that there's no need for it.

taralx avatar Jun 02 '21 17:06 taralx

Ah you're right; we've hard-coded --quick into pytype_runner (https://github.com/google/pytype/blob/5a00cf4f5e05b0411ea3feb6ebd2dbcba72c09cd/pytype/tools/analyze_project/pytype_runner.py#L173).

I'm not sure what exactly you're referring to with "People have previously been told that there's no need for it," but what I've probably said in the past (which still applies) is that pytype is primarily run and tested with --quick (that's the only configuration we use internally), so it's hard to say how well the tool will perform with --quick disabled. In some cases, it'll probably be unusably slow.

With that said, we do offer other options (such as --protocols) that are more experimental, so I wouldn't be opposed to making --quick configurable.

rchen152 avatar Jun 02 '21 18:06 rchen152