-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pyright fails to check types assigned to variables #9709
Comments
Please provide a minimal, self-contained code sample in text form that demonstrates your issue. Diagnosing type evaluation issues from partial screen shots is not really possible. If your code samples depend on imports from other libraries, please include the versions of those libraries or stubs that you're using. |
The Prisma statement from the example: git clone [email protected]:Significant-Gravitas/AutoGPT.git
git checkout pwuts/pyright-issue-9709-example
cd AutoGPT/autogpt_platform/backend
poetry install && poetry run prisma generate
poetry run pyright and you should see the lack of type error on the referenced lines in |
Thanks, I'm able to repro. The problem here is that the The code within this file's global (module) scope is exceeding pyright's internal threshold for cyclomatic complexity and statement count. Beyond this threshold, pyright will refuse to perform any sort of analysis on the code flow graph. Doing so will result in long (perhaps infinite) hangs. In this case, the cyclomatic complexity isn't very high (since there are very few loops in this file), but the statement count — the number of nodes in the control flow graph — is very large. There is a bug here, in that pyright should evaluate the type as You might wonder why a file with 75K lines would be problematic when the Python interpreter can handle it without issues. When the Python interpreter executes a large module like this, it follows only one path through the code flow graph. When a static analysis tool analyzes the same file, it needs to consider all possible paths through the code flow graph. That's much more complex and costly than what the interpreter does. There will always be some limit beyond which code flow analysis isn't viable, and this source file exceeds this limit by a fairly large margin. This limit wouldn't be an issue if the file contained only You may want to report the issue to the maintainers of prisma. Since this file is auto-generated, I'm hoping that it's straightforward for them to break it up into a more manageable submodules. Alternately, if they could generate I don't think there's anything I can do in pyright to address this issue without a change in prisma. The code complexity threshold is in place for good reasons, and it has been tuned over many years. Increasing it to a larger number — especially one as large as would be required for the prisma module — would result in a bad experience for many pyright and pylance users. As an experiment, I tried changing the this threshold to accommodate the prisma module, and it resulted in a 20-second hang on my (very fast) machine. That means on a more typical computer, it would hang for the better part of a minute, and that would occur on every keystroke while editing. |
…pyright determines that a symbol requires code flow analysis but the execution scope exceeds the cyclomatic complexity threshold. This partly addresses #9709.
Thank you very much for taking the time to repro and for explaining the issue in detail. I have learned something useful today. I'll raise this issue with the Prisma project and see if I can put in a PR to fix it. The "alternate functional syntax" for defining that specific
Would it be possible to add an info message or a warning when this happens? Either globally, or on types/statements/modules that aren't checked? |
Apparently there is a reason for defining TypedDicts like that: |
Pyright already emits an error in that module, but you would need to open it in your editor to see it. It would be confusing to emit the error in other modules. This is a rare issue (the first time I've seen it in a library), so I'm going to leave it as is for now. |
Understood. I was thinking of a message like "module {module_name} uses unchecked types: import {import_name} exceeds maximum complexity". |
_AgentGraphCompoundPrimaryKey
is reported as "Unbound" by Pylance, in a usage directly below the definition:This isn't just an issue with Pylance, because Pyright also fails to resolve and check uses of
AgentGraphWhereUniqueInput
when run through the CLI.Example
_AgentGraphCompoundPrimaryKey
with invalid arguments = error:AgentGraphWhereUniqueInput
, no errors despite invalid arguments:Package versions
Pyright: v1.1.392 (latest)
Prisma: v5.17.0
The text was updated successfully, but these errors were encountered: