Skip to content

Fix locally running pyright fails #1012

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

Closed
wants to merge 2 commits into from

Conversation

PerchunPak
Copy link
Member

No description provided.

Pyright is now smart enough to understand `sys.version_info` checks
@PerchunPak PerchunPak changed the title Bump pyright to 1.1.400 Fix locally running pyright fails May 13, 2025
@PerchunPak
Copy link
Member Author

pyright is not smart enough, it is just that uv decided to use 3.10 for local development...

@PerchunPak PerchunPak marked this pull request as draft May 13, 2025 08:44
Comment on lines 22 to 26
# Since pyright assumes lowest supported version, it would default to using tomli
# which we don't want, as it's only installed if on <3.11 and pyright usually runs
# on latest versions. For that reason, we include or TYPE_CHECKING in the condition.
if sys.version_info >= (3, 11) or TYPE_CHECKING:
if sys.version_info >= (3, 11):
from tomllib import load as toml_parse
else:
from tomli import load as toml_parse
Copy link
Member

@ItsDrike ItsDrike May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do the trick.

# Since pyright assumes lowest supported version, it would default to the tomli import
# which might however be unrecognized, as it's only installed conditionally by uv
# based on the python version. For that reason, we define a custom signature for pyright.
if TYPE_CHECKING:
    from typing import Any, BinaryIO

    def foo(fp: BinaryIO, /) -> dict[str, Any]: ...
elif sys.version_info >= (3, 11):
    from tomllib import load as toml_parse
else:
    from tomli import load as toml_parse

PerchunPak added a commit that referenced this pull request May 31, 2025
This way uv knows what version of Python to use. Before, it used 3.10
for me which resulted in #1012
@PerchunPak
Copy link
Member Author

Closing in favour of #1016

@PerchunPak PerchunPak closed this May 31, 2025
@PerchunPak PerchunPak deleted the fix-locally-running-pyright branch May 31, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants