Skip to content
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 does weird stuff #15644

Closed
1 task done
timptner opened this issue Aug 1, 2024 · 13 comments
Closed
1 task done

pyright does weird stuff #15644

timptner opened this issue Aug 1, 2024 · 13 comments
Labels
bug [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors python Python programming language support

Comments

@timptner
Copy link

timptner commented Aug 1, 2024

Check for existing issues

  • Completed

Related issues:
#13541 #13206 #12883 #11508 #10587 #7296 #8541 #7646 #5524

Describe the bug / provide steps to reproduce it

Pyright complaints about unresolvable imports and undefined values.

Fresh install of Zed and starting a python project with virtualenv pyright highlights all non-standard library imports as unresolvable. This is fine because pyright doesn't know anything about my virtualenv. But it also marks any python standard functions, e. g. print() or int().

(1) Using ./pyproject.toml it recognizes all custom imports but no longer standard library. Still does not know anything about standard python functions.

[tool.pyright]
venvPath = "."
venv = ".venv"

(2) Using ./pyrightconfig.json same results as with ./pyproject.toml.

{
  "venvPath": ".",
  "venv": ".venv"
}

(3) Using global ~/.config/zed/settings.json it does find all third-party libraries installed inside .venv and also finds standard libraries. But it still does not know about standard functions (print, int, dict, sorted, ...).

{
  "lsp": {
    "pyright": {
      "settings": {
        "python": {
          "pythonPath": ".venv/bin/python"
        }
      }
    }
  }
}

I'm quite sure that some weeks ago I could solve all pyright errors by using pyproject.toml or pyrightconfig.json. But in the meantime nothing seems to work anymore. Using combinations of those 3 options above pyrightconfig.json will overwrite pyconfig.toml and settings.json in their behaviour.

Environment

Zed: v0.146.4 (Zed)
OS: macOS 13.6.7
Memory: 8 GiB
Architecture: x86_64

Python is installed via brew (python@3.12). PyRight is not installed via brew or as global pip package. (Brew stops one with a warning when trying python3 -m pip install <package> outside of an virtualenv.)

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

@timptner timptner added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Aug 1, 2024
@JosephTLyons JosephTLyons added python Python programming language support language An umbrella label for all programming languages syntax behaviors language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Aug 2, 2024
@JosephTLyons
Copy link
Collaborator

Hey @timptner, do you have any projects you could share that show the issue? I'm not able to reproduce this on my end - here's a project where print is being recognized by pyright:

SCR-20240802-kfob

We've had some issues where restarting Zed, after creating a pyrightconfig.json file, would correct some weird pyright issues - do your issues still persist after restarting Zed?

@JosephTLyons JosephTLyons added the needs info / awaiting response Issue that needs more information from the user label Aug 2, 2024
@timptner
Copy link
Author

timptner commented Aug 2, 2024

Freshly project:

Bildschirmfoto 2024-08-02 um 22 29 08

Restartet Zed multiple times in between those 3 options above. Even restarted Zed before creating this project and also tried zed . while CWD is this project, which some other issue mentioned as solution.

@timptner
Copy link
Author

timptner commented Aug 2, 2024

Bildschirmfoto 2024-08-02 um 22 31 29

@timptner
Copy link
Author

timptner commented Aug 2, 2024

I noticed that each time I restart Zed it always checks for pyright updates and everytime downloads pyright. Don't know if this is expected behaviour.

@timptner
Copy link
Author

timptner commented Aug 3, 2024

Just checked with my second workstation (debian) and there I don't get the pyright errors

@imbev
Copy link

imbev commented Aug 5, 2024

I've encountered the same problem:

  1. Open empty directory
  2. uv init
  3. uv venv
  4. Set pyproject.toml dependencies to dependencies = ["requests"]
  5. uv pip compile pyproject.toml -o requirements.txt
  6. uv pip sync requirements.txt
  7. Add import requests to src/project/__init__.py

There will be a warning with Pyright: Import "requests" could not be resolved from source.

As @timptner said, this can be resolved by adding the following to pyproject.toml:

[tool.pyright]
venvPath = "."
venv = ".venv"

However this is a tweak that isn't needed when working in other editors.

@ikheifets
Copy link

ikheifets commented Aug 11, 2024

@JosephTLyons the same behaviour, venv's libraries pyright recognizing correctly, but pythons builtins not:

Pyright: "str" is not defined (reportUndefinedVariable)
Pyright: "print" is not defined (reportUndefinedVariable)
Pyright: "range" is not defined (reportUndefinedVariable)

Previously it worked fluently, it seems that something became wrong after auto-update

I using the same setting for venv and I tried recreate venv and restart zed. Disable of venv settings also not working.

@timptner
Copy link
Author

Just installed pyright with pip and checked the files.

(.venv) aiven@MacBook-Pro test % pyright --version
pyright 1.1.375
(.venv) aiven@MacBook-Pro test % pyright main.py
0 errors, 0 warnings, 0 informations

Seems like it's a local problem of the pyright version inside Zed.

@ikheifets
Copy link

ikheifets commented Aug 13, 2024

@timptner for me working this workaround:

rm -rf ~/Library/Application\ Support/Zed/languages/pyright/

After that need to restart Zed and it will automatically download latest pyright version

@timptner
Copy link
Author

@timptner for me working this workaround:

rm -rf ~/Library/Application\ Support/Zed/languages/pyright/

After that need to restart Zed and it will automatically download latest pyright version

This has solved it!

@imbev
Copy link

imbev commented Aug 14, 2024

This is still a problem on the Linux version of Zed.

After running this command, the newly downloaded pyright has the same issues.

rm -rdf ~/.local/share/zed/languages/pyright/

@ikheifets
Copy link

ikheifets commented Aug 14, 2024

@imbev you have another problem. In our case pyright can't recognize python stdlib (it seems that we've got broken version of pyright), in your case third-patry libs from venv, big chance that you wrongly configured virtualenv, just read docs.

@JosephTLyons JosephTLyons removed the needs info / awaiting response Issue that needs more information from the user label Sep 23, 2024
@bhanusanghi
Copy link

bhanusanghi commented Dec 24, 2024

I encountered the same on zed preview, forced reinstall of pyright by deleting the existing pyright as suggested by @timptner . Working great since!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors python Python programming language support
Projects
None yet
Development

No branches or pull requests

5 participants