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

Inconsistent type evaluation with Self #4844

Closed
Azureblade3808 opened this issue Mar 27, 2023 · 2 comments
Closed

Inconsistent type evaluation with Self #4844

Azureblade3808 opened this issue Mar 27, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@Azureblade3808
Copy link
Contributor

Azureblade3808 commented Mar 27, 2023

Describe the bug
It seems sometimes Self gets narrowed too much, but I'm not sure about the condition.

To Reproduce
See "Screenshots or Code".

Expected behavior
Nothing gets reported.

Screenshots or Code

from __future__ import annotations

from typing import Protocol
from typing_extensions import Self

class Negatable(Protocol):
    def __neg__(self) -> Self: ...

def f(x: Negatable) -> None: ...

f(0)  # This fails.
f(int(0))
f(0)  # This passes.

image

VS Code extension or command-line
Pylance v2023.3.31 Pre-Release

Additional context
VSCode config:

"python.analysis.diagnosticSeverityOverrides": {
    "reportAssertAlwaysTrue": "error",
    "reportConstantRedefinition": "error",
    "reportDuplicateImport": "warning",
    "reportFunctionMemberAccess": "error",
    "reportGeneralTypeIssues": "information",
    "reportImplicitStringConcatenation": "warning",
    "reportImportCycles": "none",
    "reportIncompatibleMethodOverride": "error",
    "reportIncompatibleVariableOverride": "error",
    "reportInconsistentConstructor": "warning",
    "reportInvalidStubStatement": "none",
    "reportMissingModuleSource": "none",
    "reportMissingTypeArgument": "none",
    "reportMissingTypeStubs": "none",
    "reportOverlappingOverload": "none",
    "reportPrivateImportUsage": "none",
    "reportPrivateUsage": "none",
    "reportPropertyTypeMismatch": "none",
    "reportUnknownArgumentType": "none",
    "reportUnknownLambdaType": "none",
    "reportUnknownMemberType": "none",
    "reportUnknownParameterType": "none",
    "reportUnknownVariableType": "none",
    "reportUnnecessaryCast": "none",
    "reportUnnecessaryComparison": "none",
    "reportUnnecessaryIsInstance": "none",
    "reportUnsupportedDunderAll": "warning",
    "reportUntypedClassDecorator": "none",
    "reportUntypedFunctionDecorator": "none",
    "reportUnusedCallResult": "error",
    "reportUnusedClass": "error",
    "reportUnusedFunction": "error",
    "reportUnusedImport": "warning",
    "reportUnusedVariable": "error"
},
"python.analysis.typeCheckingMode": "strict",
erictraut pushed a commit that referenced this issue Mar 27, 2023
… matching where the object type (i.e. the `self` value) is a literal value. This addresses #4844.
@erictraut
Copy link
Collaborator

Thanks for the bug report. This will be addressed 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 Mar 27, 2023
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.301, 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