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

Recursive protocols seem to crash pylance (maximum call stack exceeded) #225

Closed
jaycosaur opened this issue Aug 10, 2020 · 2 comments
Closed
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@jaycosaur
Copy link

jaycosaur commented Aug 10, 2020

Environment data

Language Server version: v2020.8.0
OS and version: macOS Catalina 10.15.5 (19F101)
Python version: 3.8.2
VSCode version: 1.47.3

Expected behaviour

Should be able to handle recursive protocols and not crash the tool.

Actual behaviour

Crashes out tool with RangeError: Maximum call stack size exceeded and Error performing analysis: RangeError: Maximum call stack size exceeded messages

Code Snippet / Additional information

The below code snippet is a modified version of mypys recursive protocol example which crashes out pylance.

from typing import Optional, Protocol


class TreeLike(Protocol):
    value: int

    @property
    def left(self) -> Optional["TreeLike"]:
        ...

    @property
    def right(self) -> Optional["TreeLike"]:
        ...


class SimpleTree:
    value: int

    @property
    def left(self) -> Optional["SimpleTree"]:
        return self._left

    @property
    def right(self) -> Optional["SimpleTree"]:
        return self._right

    def __init__(self, value: int) -> None:
        self.value = value
        self._left: Optional["SimpleTree"] = None
        self._right: Optional["SimpleTree"] = None


root: TreeLike = SimpleTree(0)

Though rewriting like the following presents no errors and passes successfully.

from typing import Optional, Protocol
from dataclasses import dataclass


class TreeLike(Protocol):
    value: int
    left: Optional["TreeLike"]
    right: Optional["TreeLike"]


@dataclass
class SimpleTree:
    value: int
    left: Optional["SimpleTree"] = None
    right: Optional["SimpleTree"] = None


root: TreeLike = SimpleTree(0)
@erictraut
Copy link
Contributor

Thanks for the bug report and the clear repro steps!

This will be fixed in the next version of Pylance. I've added your sample to our unit tests to prevent future regressions.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Aug 10, 2020
@github-actions github-actions bot removed the triage label Aug 10, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.8.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202081-13-august-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants