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

RangeError: Maximum call stack size exceeded #1681

Closed
torarvid opened this issue Aug 16, 2021 · 3 comments
Closed

RangeError: Maximum call stack size exceeded #1681

torarvid opened this issue Aug 16, 2021 · 3 comments

Comments

@torarvid
Copy link

Environment data

  • Language Server version: 2021.8.1
  • OS and version: macOS 11.4
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.6 (venv using poetry)

Issue

I was attempting to rewrite some internal library to change the way it imports Protocol. After rewriting from the style:

try:
    from typing import Protocol
except ImportError:
    from typing_extensions import Protocol  # type: ignore

to this style:

import sys
if sys.version_info >= (3.8):
    from typing import Protocol
else:
    from typing_extensions import Protocol

I got the exception RangeError: Maximum call stack size exceeded from pylance. Unfortunately, the library isn't public, so I haven't found a way to make a reproducable example. Also, since I don't understand what's happening, I'm not sure if this is related to #1671 or not. At least, my stack trace seems to be different.

If it matters; the reason I'm doing the rewrite in the first place is that when using the first approach, VS Code is giving me squigglies all over the place when using Protocol as a base class:

image

Logs

Expand this to see the logs
[Info  - 5:18:54 PM] Pylance language server 2021.8.1 (pyright abd41b72) starting
[Info  - 5:18:54 PM] Server root directory: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist
[Info  - 5:18:54 PM] No configuration file found.
[Info  - 5:18:54 PM] pyproject.toml file found at /Users/tor/oda/sdxp.
[Info  - 5:18:54 PM] Setting pythonPath for service "sdxp": "/Users/tor/oda/sdxp/.venv/bin/python"
[Info  - 5:18:54 PM] Loading pyproject.toml file at /Users/tor/oda/sdxp/pyproject.toml
[Error - 5:18:54 PM] Pyproject file "/Users/tor/oda/sdxp/pyproject.toml" is missing "[tool.pyright] section.
[Warn  - 5:18:54 PM] stubPath /Users/tor/oda/sdxp/typings is not a valid directory.
[Info  - 5:18:54 PM] Assuming Python version 3.9
[Info  - 5:18:54 PM] Assuming Python platform Darwin
Search paths for /Users/tor/oda/sdxp
  /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib
  /Users/tor/oda/sdxp
  /Users/tor/oda/sdxp/src
  /Users/tor/oda/sdxp/typings
  /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stubs/...
  /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/bundled/stubs
  /usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9
  /usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
  /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages
  /Users/tor/oda/sdxp/src
[Info  - 5:18:54 PM] Searching for source files
[Info  - 5:18:54 PM] Auto-excluding /Users/tor/oda/sdxp/.venv
[Info  - 5:18:54 PM] Found 133 source files
[FG] parsing: /Users/tor/oda/sdxp/src/sdxp/types/_channel.py (30ms)
[FG] parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (65ms)
[FG] binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/builtins.pyi (30ms)
[FG] binding: /Users/tor/oda/sdxp/src/sdxp/types/_channel.py (0ms)
[Info  - 5:18:54 PM] Background analysis(1) root directory: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist
[Info  - 5:18:54 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: setFileOpened
Background analysis message: analyze
[BG(1)] analyzing: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py ...
[BG(1)]   parsing: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py (42ms)
[BG(1)]   parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (63ms)
[BG(1)]   binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/builtins.pyi (29ms)
[BG(1)]   binding: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py (2ms)
[BG(1)]   checking: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py ...
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (23ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/typing.pyi (9ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (5ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (1ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 1ms] (5ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi (1ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/__init__.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/__init__.pyi (1ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/dataclasses.pyi [fs read 0ms] (3ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/dataclasses.pyi (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/__init__.py [fs read 0ms] (8ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/__init__.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_config.py [fs read 0ms] (12ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_config.py (2ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_loggers.py [fs read 1ms] (9ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_loggers.py (3ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_log_levels.py [fs read 0ms] (5ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/_log_levels.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/types.py [fs read 1ms] (5ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/types.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/dev.py [fs read 0ms] (16ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/dev.py (3ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/processors.py [fs read 1ms] (12ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/structlog/processors.py (4ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/sys.pyi [fs read 14ms] (19ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/sys.pyi (2ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/abc.pyi [fs read 12ms] (12ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/channel/__init__.py [fs read 2ms] (2ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/channel/__init__.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/channel/_base.py [fs read 0ms] (9ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/channel/_base.py (2ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/channel/_client.py [fs read 0ms] (2ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/channel/_client.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/contrib/logging.py [fs read 0ms] (0ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/contrib/logging.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/protocol/__init__.py [fs read 0ms] (1ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/protocol/__init__.py (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/protocol/_sdxp.py [fs read 0ms] (13ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/protocol/_sdxp.py (3ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/protocols.pyi [fs read 1ms] (3ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/protocols.pyi (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/manager/_exceptions.py [fs read 1ms] (1ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/manager/_exceptions.py (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/exceptions.py [fs read 0ms] (0ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/exceptions.py (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/types/_channel.py (2ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/types/_channel.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/types/_manager.py [fs read 0ms] (1ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/types/_manager.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/types/_message_codec.py [fs read 1ms] (1ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/types/_message_codec.py (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/types/_protocol.py [fs read 0ms] (1ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/types/_protocol.py (0ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/types/_telegram.py [fs read 0ms] (9ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/types/_telegram.py (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/__init__.py [fs read 1ms] (7ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/__init__.py ...
[BG(1)]       parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/errors.py [fs read 0ms] (11ms)
[BG(1)]       binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/errors.py (4ms)
[BG(1)]       parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/main.py [fs read 1ms] (18ms)
[BG(1)]       binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/main.py (9ms)
[BG(1)]       parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/networks.py [fs read 0ms] (16ms)
[BG(1)]       binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/networks.py (4ms)
[BG(1)]       parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/tools.py [fs read 0ms] (2ms)
[BG(1)]       binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/tools.py (1ms)
[BG(1)]       parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/types.py [fs read 0ms] (13ms)
[BG(1)]       binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/types.py (7ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/__init__.py (85ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/utils.py [fs read 1ms] (10ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/.venv/lib/python3.9/site-packages/pydantic/utils.py (5ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/locks.pyi [fs read 0ms] (2ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/locks.pyi (1ms)
[BG(1)]     parsing: /Users/tor/oda/sdxp/src/sdxp/channel/_enums.py [fs read 0ms] (0ms)
[BG(1)]     binding: /Users/tor/oda/sdxp/src/sdxp/channel/_enums.py (0ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/enum.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/enum.pyi (3ms)
[BG(1)]     parsing: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/transports.pyi [fs read 0ms] (2ms)
[BG(1)]     binding: /Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/typeshed-fallback/stdlib/asyncio/transports.pyi (1ms)
[Error - 5:18:55 PM] An internal error occurred while type checking file "/Users/tor/oda/sdxp/src/sdxp/manager/_manager.py": RangeError: Maximum call stack size exceeded
    at Object.buildTypeVarMapFromSpecializedClass (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeUtils.ts:1135:17)
    at canAssignClassToProtocol (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20444:36)
    at canAssignClass (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20992:20)
    at canAssignType (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:22475:22)
    at partiallySpecializeFunctionForBoundClassOrObject (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:24243:18)
    at bindFunctionToClassOrObject (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:24107:24)
    at forEach (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20516:63)
    at Map.forEach (<anonymous>)
    at canAssignClassToProtocol (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20446:25)
    at Ii (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20992:20)
[BG(1)]   checking: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py (828ms)
[BG(1)] analyzing: /Users/tor/oda/sdxp/src/sdxp/manager/_manager.py (965ms)
[Error - 5:18:55 PM] Error performing analysis: RangeError: Maximum call stack size exceeded
    at Object.buildTypeVarMapFromSpecializedClass (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeUtils.ts:1135:17)
    at canAssignClassToProtocol (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20444:36)
    at canAssignClass (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20992:20)
    at canAssignType (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:22475:22)
    at partiallySpecializeFunctionForBoundClassOrObject (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:24243:18)
    at bindFunctionToClassOrObject (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:24107:24)
    at forEach (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20516:63)
    at Map.forEach (<anonymous>)
    at canAssignClassToProtocol (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20446:25)
    at Ii (/Users/tor/.vscode/extensions/ms-python.vscode-pylance-2021.8.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20992:20)
@erictraut
Copy link
Contributor

Thanks for reporting. Based on the stack crawl, I'm pretty sure this is the same bug mentioned in the other issue. It should be fixed in the next release. We typically release a new version of pylance on Wed or Thurs. Please let us know if the problem persists after you get the update.

@jakebailey
Copy link
Member

I'll close this in favor of #1671 for now.

@torarvid
Copy link
Author

Just came to say that the 2021.8.2 release did indeed fix my issue. Thanks a lot (indeed, you fixed my issue even before I reported it 😛)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants