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 doesn't use local platform if no python interpreter is specified #858

Closed
ileonte opened this issue Jul 19, 2020 · 8 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@ileonte
Copy link

ileonte commented Jul 19, 2020

Before I describe the problem: I can only reproduce this with some code that I can not post in full. Trying to reproduce this separately doesn't trigger the same error.

I have code that looks something like this:

# [ ... ]
import select as _select

# [ ... stuff ... ]
def some_function() -> None:
    # [ ... code ... ]
    poller = _select.epoll()
    poller.register(fileno(in_write), _select.EPOLLOUT)

This causes the following error:
image
(_select.EPOLLOUT generates the same error)

I tried reproducing the error with a simpler example but I couldn't. For example, the following code does not trigger the problem:

import sys as _sys
import select as _select

def do_epoll(poller: _select.epoll) -> None:
    poller.register(_sys.stdin.fileno(), _select.EPOLLIN)
    poller.poll(-1)


def boop() -> None:
    poller = _select.epoll()
    do_epoll(poller)

Trying to figure out what is causing this I noticed the following: if I ctrl+click on _select I can see that sys.platform is being detected differently in the Typeshed code, which causes epoll to not appear as a symbol in my first case:
image
In this screenshot I have the problematic project on the left and the simple example on the right. Hovering sys.platform I get the following:

  • in the problematic case:
    image
  • in the simple (working) case:
    image

I am using version 1.1.54 of the VSCode extension. The OS is Linux. No virtual environment. The default system Python version is 3.8.4.

@ileonte
Copy link
Author

ileonte commented Jul 19, 2020

Pyright debug output for the two projects:
image

@ileonte
Copy link
Author

ileonte commented Jul 19, 2020

Ok, so this might be related to #697. What was happening was that in my 'working' case I had a left-over .vscode/settings.json that looked like this:

{
    "python.pythonPath": "/usr/bin/python"
}

With that file in place Pyright correctly picked up the system Python interpreter. If I remove that settings file my simple case also starts generating the same error.

If I look into Pyright's settings I can see that the Python Path setting defaults to python which should work:

ileonte@ltkcentral ~/Work/projects/pyright-tests $ which python
/usr/bin/python
ileonte@ltkcentral ~/Work/projects/pyright-tests $ python --version
Python 3.8.4

If I manually change that setting to python3 (which is just an alias for python) the errors go away.

@erictraut
Copy link
Collaborator

It looks like epoll is defined only if sys.platform is equal to linux. That is, it doesn't exist for other platforms. That means that a Python program that uses this symbol will presumably generate a runtime exception if it's run on Windows, MacOS or other non-Linux platforms.

When Pyright is performing its analysis, it assumes that the value of sys.platform is based on the platform Pyright is running on. Are you running Pyright on a Linux system?

You can override this default by providing a pyrightconfig.json file. Here is a sample config file that demonstrates how to specify the Linux platform.

@ileonte
Copy link
Author

ileonte commented Jul 20, 2020

Yes, I should have updated the description. The problem is that I am running VSCode on Linux and the system default interpreter is python (see my last comment before this). It seems that the Pyright vscode extension doesn't correctly apply the default setting for Python Path - if I go into settings I see it set to python which is correct for my system however it results in the error in the initial report if left unchanged. If I manually change it to python3 (which, again, on my system is the same as python) the error goes away.

@erictraut
Copy link
Collaborator

Hmm, I don't see any reason why the selected interpreter would affect this. The default platform is determined by the platform that VS Code is running on (as indicated by node). And the type information comes from the bundled typeshed stub files regardless of what interpreter is selected.

By any chance, do you have a pythonconfig.json or mspythonconfig.json file that defines different execution environments, some of which specify different pythonPlatform values?

@ileonte
Copy link
Author

ileonte commented Jul 20, 2020

As far as I can tell I have none of those files on my system:

ileonte@ltkcentral ~/Work/projects/pyright-tests $ find . -name pythonconfig.json
ileonte@ltkcentral ~/Work/projects/pyright-tests $ find . -name mspythonconfig.json
ileonte@ltkcentral ~/Work/projects/pyright-tests $ find ~/.vscode/ -name mspythonconfig.json
ileonte@ltkcentral ~/Work/projects/pyright-tests $ find ~/.vscode/ -name pythonconfig.json

(if I'm looking in the wrong places please let me know)

I've recorded a short video showing the problem occurring: https://www.youtube.com/watch?v=heT0-Efw5Nk

@erictraut
Copy link
Collaborator

I think I've figured out the root cause of this problem. I've introduced a fix, which will be in the next release of Pyright.

@erictraut erictraut added bug Something isn't working addressed in next version Issue is fixed and will appear in next published version labels Jul 22, 2020
@erictraut erictraut changed the title Weird '"epoll" is not a member of module" error Pyright doesn't use local platform if no python interpreter is specified Jul 22, 2020
@erictraut
Copy link
Collaborator

This is addressed in Pyright 1.1.56, which I just published. It will also be in the next version of Pylance.

heejaechang pushed a commit to heejaechang/pyright that referenced this issue Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants