Skip to content

Support try/except imports #11394

@mikelei8291

Description

@mikelei8291

Describe the bug
When using the evdev library, I noticed that methods defined in the parent EventIO class of the InputDevice 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:

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

Code or Screenshots

from evdev import InputDevice

device = InputDevice("/dev/input/event3")
device.async_  # try trigger autocomplete here

Notice that none of the async_* 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions