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

Error merging non-generic and generic Protocol classes #1101

Closed
marcinwrochna opened this issue Mar 29, 2021 · 3 comments
Closed

Error merging non-generic and generic Protocol classes #1101

marcinwrochna opened this issue Mar 29, 2021 · 3 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@marcinwrochna
Copy link

Environment data

  • Pylance language server 2021.3.3 (pyright be28f16e)
  • Python: 3.9.2
  • OS: Fedora 33

Actual behaviour

Defining the merge of a generic Protocol (such as Iterable[T]) and a non-generic Protocol (such as Sized) makes Pylance end with a cryptic error Error: Debug Failure. False expression. raised from canAssignProtocolClassToSelf.

The following example is from PEP-544:

from typing import Iterable, Protocol, Sized, TypeVar

T = TypeVar('T')
class SizedIterable(Iterable[T], Sized, Protocol):
    pass

The same happens if I make T covariant instead, or if I replace Protocol with Protocol[T] or Protocol, Generic[T].

In fact already the following fails:

T = TypeVar('T')

class FirstProtocol(Protocol):
    def first():
        ...
        
class MergedProtocol(FirstProtocol, Protocol[T]):
    def merged() -> T:
        ...

Logs

[Info  - 4:15:07 PM] Pylance language server 2021.3.3 (pyright be28f16e) starting
[Info  - 4:15:07 PM] Server root directory: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist
[Info  - 4:15:07 PM] No configuration file found.
[Info  - 4:15:07 PM] Setting pythonPath for service "vscode": "/bin/python"
Search paths found for configured python interpreter:
  /usr/lib64/python3.9
  /usr/lib64/python3.9/lib-dynload
  /home/token0/.local/lib/python3.9/site-packages
  /usr/lib64/python3.9/site-packages
  /usr/lib/python3.9/site-packages
[Warn  - 4:15:07 PM] stubPath /home/token0/tmp/vscode/typings is not a valid directory.
[Info  - 4:15:07 PM] Assuming Python version 3.9
[Info  - 4:15:07 PM] Assuming Python platform Linux
[Info  - 4:15:07 PM] Searching for source files
[Info  - 4:15:07 PM] Found 1 source file
[Info  - 4:15:07 PM] Background analysis(1) root directory: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist
[Info  - 4:15:07 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: ensurePartialStubPackages
Background analysis message: setFileOpened
Background analysis message: getSemanticTokens full
[BG(1)] getSemanticTokens full at /home/token0/tmp/vscode/tmp.py ...
[BG(1)]   parsing: /home/token0/tmp/vscode/tmp.py (61ms)
[BG(1)]   parsing: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 4ms] (135ms)
[BG(1)]   binding: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi (38ms)
[BG(1)]   binding: /home/token0/tmp/vscode/tmp.py (0ms)
[BG(1)]   parsing: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (43ms)
[BG(1)]   binding: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/typing.pyi (22ms)
[BG(1)]   parsing: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 2ms] (23ms)
[BG(1)]   binding: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (2ms)
[BG(1)]   parsing: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi [fs read 0ms] (4ms)
[BG(1)]   binding: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi (1ms)
[BG(1)]   parsing: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (1ms)
[BG(1)]   binding: /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
[BG(1)] getSemanticTokens full at /home/token0/tmp/vscode/tmp.py (369ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 9:0 at /home/token0/tmp/vscode/tmp.py (1ms)
Background analysis message: analyze
[Error - 4:15:08 PM] An internal error occurred while type checking file "/home/token0/tmp/vscode/tmp.py": Error: Debug Failure. False expression.
    at canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18276:9)
    at forEach (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18337:22)
    at Array.forEach (<anonymous>)
    at Object.canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18328:38)
    at callback (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:110:69)
    at i.timeOperation (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/common/timing.ts:44:28)
    at run (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:42:46)
    at Object.canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:110:13)
    at /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/checker.ts:2555:56
    at Array.forEach (<anonymous>)
[BG(1)] analyzing: /home/token0/tmp/vscode/tmp.py ...
[BG(1)]   checking: /home/token0/tmp/vscode/tmp.py (274ms)
[BG(1)] analyzing: /home/token0/tmp/vscode/tmp.py (275ms)
[Error - 4:15:08 PM] Error performing analysis: Error: Debug Failure. False expression.
    at canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18276:9)
    at forEach (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18337:22)
    at Array.forEach (<anonymous>)
    at Object.canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18328:38)
    at callback (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:110:69)
    at i.timeOperation (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/common/timing.ts:44:28)
    at run (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:42:46)
    at Object.canAssignProtocolClassToSelf (/home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/typeEvaluatorWithTracker.ts:110:13)
    at /home/token0/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/pyright-internal/src/analyzer/checker.ts:2555:56
    at Array.forEach (<anonymous>)
@erictraut
Copy link
Contributor

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

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Mar 29, 2021
@marcinwrochna
Copy link
Author

Thanks a lot!

@jakebailey
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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