microsoft / microsoft/pyright

Support try/except imports

Open
#11,394 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**
When using the evdev library, I noticed that methods defined in the parent [`EventIO`](https://github.com/gvalkov/python-evdev/blob/a47b5b5a6f79bde6823095d1105501856338aed7/src/evdev/eventio_async.py#L56) class of the [`InputDevice`](https://github.com/gvalkov/python-evdev/blob/a47b5b5a6f79bde6823095d1105501856338aed7/src/evdev/device.py#L105) class were not resolving, because the import of the parent class is using a try/except block to try to [import the async version of it first](https://github.com/gvalkov/python-evdev/blob/a47b5b5a6f79bde6823095d1105501856338aed7/src/evdev/device.py#L7-L10):

```python
try:
from .eventio_async import EvdevError, EventIO
except ImportError:
from .eventio import EvdevError, EventIO
```

**Code or Screenshots**
```python
from evdev import InputDevice

device = InputDevice("/dev/input/event3")
device.async_ # try trigger autocomplete here
```
Notice that none of the [`async_*`](https://github.com/gvalkov/python-evdev/blob/a47b5b5a6f79bde6823095d1105501856338aed7/src/evdev/eventio_async.py#L72-L97) methods shows up in the autocomplete.

evdev 1.9.3 is used in this example.

**VS Code extension or command-line**
ms-python.python: 2026.4.0
ms-python.vscode-pylance: 2026.1.1

**Extra Notes**
Also, I noticed that if I switched the language server from `Pylance` to `Jedi` in VSCode using the `python.languageServer` option, the good old Jedi will resolve these methods just fine.

This issue also presents in ty and some more details and discussions can be found here: astral-sh/ty#2096

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the evdev InputDevice example and inspect how Pyright resolves the try/except imports in evdev/device.py, especially the eventio_async.py and eventio.py imports. Compare the result with Jedi and verify that async_* methods from eventio_async.py resolve on InputDevice without breaking the fallback import.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.