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 hangs while using 100% CPU #4475

Closed
bkoropoff opened this issue Jan 17, 2023 · 3 comments
Closed

pyright hangs while using 100% CPU #4475

bkoropoff opened this issue Jan 17, 2023 · 3 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@bkoropoff
Copy link

Describe the bug
pyright hangs and uses 100% CPU on particular python code.

To Reproduce
Running pyright <file.py> on the code below hangs and pegs a CPU at 100%.

Expected behavior
It doesn't do that.

Screenshots or Code
This is the most reduced test case I could produce:

from typing import Iterable, TypeVar, Union

T = TypeVar("T")
Tree = list[Union["Tree[T]", T]]

def _flatten(tree: Union[Tree[T], T]) -> Iterable[T]:
    if not isinstance(tree, list):
        yield tree
        return
    for v in tree:
        yield from _flatten(v)

def flatten(tree: Tree[T]) -> Iterable[T]:
    return _flatten(tree)

VS Code extension or command-line
Command line, latest version from pip (1.1.289), Linux.

Additional context
Originally found using pyright as LSP from neovim.

@erictraut
Copy link
Collaborator

Thanks for the bug report. This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working addressed in next version Issue is fixed and will appear in next published version labels Jan 17, 2023
@bkoropoff
Copy link
Author

The latest version from git still hangs if I modify the test case to call the function:

from typing import Iterable, TypeVar, Union

T = TypeVar("T")
Tree = list[Union["Tree[T]", T]]

def _flatten(tree: Union[Tree[T], T]) -> Iterable[T]:
    if not isinstance(tree, list):
        yield tree
        return
    for v in tree:
        yield from _flatten(v)

def flatten(tree: Tree[T]) -> Iterable[T]:
    return _flatten(tree)

flatten([1,[2,3]])

@erictraut erictraut removed the addressed in next version Issue is fixed and will appear in next published version label Jan 17, 2023
erictraut pushed a commit that referenced this issue Jan 17, 2023
…hen using a recursive type alias with a type variable. This addresses #4475.
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jan 17, 2023
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.290, which I just published. It will also be included in a future release of pylance.

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