microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

An internal error occurred while type checking file: RangeError: Maximum call stack size exceeded #825

Closed harenbrs closed 3 years ago

harenbrs commented 3 years ago

Environment data

Expected behaviour

Type checking functions correctly

Actual behaviour

Type checking throws an error at the top of the file

Logs

An internal error occurred while type checking file "/Users/seb/path/to/file.py": RangeError: Maximum call stack size exceeded
    at Object.lookUpClassMember (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeUtils.ts:711:17)
    at forEach (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14900:34)
    at Map.forEach (<anonymous>)
    at canAssignClassToProtocol (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14897:25)
    at canAssignClass (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15205:20)
    at canAssignType (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:16198:22)
    at partiallySpecializeFunctionForBoundClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17524:25)
    at bindFunctionToClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17392:24)
    at /Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.0/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14958:63
    at Map.forEach (<anonymous>)Pylance

Code Snippet / Additional information

Code is closed source at the moment, and I haven't been able to find a minimum-reproducible example.

The stack trace to my eyes looks different from the recently closed similar issues.

erictraut commented 3 years ago

Thanks for reporting the bug.

We've identified and fixed one potential cause for this. Please try the next release of Pylance (which should be published in the next couple of days) and let us know if you still see the problem.

jakebailey commented 3 years ago

This issue has been fixed in version 2021.1.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202111-13-january-2021

harenbrs commented 3 years ago

I am now on Pylance language server 2021.1.1 (pyright 6a970b45) but I am still experiencing this error on Python 3.8.6, as well as an apparently different error on 3.9.1.

I have since published the "offending" source code here. Open the file pyclee/clusters.py for analysis.

Stack trace for 3.8.6:

An internal error occurred while type checking file "/Users/seb/tmp/pyclee/pyclee/clusters.py": RangeError: Maximum call stack size exceeded
    at Object.lookUpClassMember (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeUtils.ts:711:17)
    at forEach (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14970:34)
    at Map.forEach (<anonymous>)
    at canAssignClassToProtocol (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14953:25)
    at canAssignClass (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15383:20)
    at canAssignType (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:16386:22)
    at partiallySpecializeFunctionForBoundClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17723:25)
    at bindFunctionToClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17591:24)
    at /Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15019:63
    at Map.forEach (<anonymous>)Pylance

Stack trace for 3.9.1:

An internal error occurred while type checking file "/Users/seb/tmp/pyclee/pyclee/clusters.py": RangeError: Maximum call stack size exceeded
    at canAssignClass (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15350:14)
    at canAssignType (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:16386:22)
    at assignTypeToTypeVar (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15936:18)
    at canAssignType (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:16056:24)
    at partiallySpecializeFunctionForBoundClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17723:25)
    at bindFunctionToClassOrObject (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:17591:24)
    at forEach (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15009:58)
    at Map.forEach (<anonymous>)
    at canAssignClassToProtocol (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14953:25)
    at Fn (/Users/seb/.vscode/extensions/ms-python.vscode-pylance-2021.1.1/dist/pyright-internal/src/analyzer/typeEvaluator.ts:15383:20)Pylance
erictraut commented 3 years ago

@harenbrs, thanks for the repro steps. I was able to find and fix the problem. You are using NewType with a protocol class, which is something we've never seen before. That was causing infinite recursion within the type analyzer. The fix will be included in the next release.

harenbrs commented 3 years ago

Excellent, many thanks for dealing with it so quickly. Also happy to be making history, of a kind 😉

jakebailey commented 3 years ago

This issue has been fixed in version 2021.1.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202112-20-january-2021

AW1534 commented 3 years ago

dont think its been resolved as im having that issue right now.

erictraut commented 3 years ago

The original bug was definitely fixed. If you're experiencing a similar symptom, please file a new bug. And if you can provide a minimal code snippet that exhibits the problem, that would be really helpful.