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

Argument of type "float" cannot be assigned to parameter of type "... | Real" #6790

Closed
anabelle2001 opened this issue Dec 20, 2024 · 2 comments
Assignees
Labels
needs repro Issue has not been reproduced yet settings-override Feedback that pyrightconfig.json is taking precedence

Comments

@anabelle2001
Copy link

Environment data

  • Language Server version: 2024.12.1
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda): CPython 3.10.11 64-bit
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: off

Code Snippet

from collections.abc import Sequence
from numbers import Real
from typing import TypeVar, overload

from attr import dataclass
from typing_extensions import Self

T = TypeVar("T")


@dataclass(frozen=True)
class Point:
    x: float
    y: float

    def __new__(cls, x: "Real | PointLike", y: "Real | None" = None) -> "Point | Self":
        if not isinstance(x, Point):
            return super().__new__(cls)
        if y is not None:
            raise TypeError  # This would trigger if you tried to do x = Point(p,2.3) and p was already a point.
        return x

    @overload
    def __init__(self, x: Real, y: Real) -> None: ...

    @overload
    def __init__(self, x: "PointLike", y: None = None) -> None: ...

    def __init__(self, x: "Real | PointLike", y: "Real | None" = None) -> None:
        if y != None:
            if not isinstance(x, Real) or not isinstance(y, Real):
                raise TypeError(
                    f"Point.__init__/2 requires two real numbers - got types {type(x)} and {type(y)}"
                )

            object.__setattr__(self, "x", float(x))
            object.__setattr__(self, "y", float(y))

        if (
            isinstance(x, Sequence)
            and isinstance(x[0], Real)
            and isinstance(x[1], Real)
        ):
            object.__setattr__(self, "x", float(x[0]))
            object.__setattr__(self, "y", float(x[1]))

        raise TypeError(
            f"Point.__init__/1 requires a Point or tuple[Real,Real] - got type {type(x)}"
        )

    def __repr__(self) -> str:
        return f"({self.x}, {self.y})"

    def __add__(self, other: "PointLike") -> "Point":
        other = Point(other)
        return Point(x=self.x + other.x, y=self.y + other.y)


PointLike = tuple[float | int, float | int] | Point

This generates the following error, but only if there is a [tool.pyright] section in pyproject.toml:

No overloads for "__init__" match the provided argumentsPylance[reportCallIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportCallIssue)
test2.py(27, 9): Overload 2 is the closest match
Argument of type "float" cannot be assigned to parameter "x" of type "PointLike | Real" in function "__new__"
  Type "float" is not assignable to type "PointLike | Real"
    "float" is not assignable to "Real"
    "float" is not assignable to "tuple[float | int, float | int]"
    "float" is not assignable to "Point"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
Argument of type "float" cannot be assigned to parameter "x" of type "PointLike" in function "__init__"
  Type "float" is not assignable to type "PointLike | Real"
    "float" is not assignable to "Real"
    "float" is not assignable to "tuple[float | int, float | int]"
    "float" is not assignable to "Point"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)

The error insists that float cannot be assigned to a parameter of type "... | Real", which doesn't make much sense, as floats represent real numbers

Repro Steps

  1. Create new folder with the following pyproject.toml file:
[tools.pyright]
  1. add the big python code attached above

Expected behavior

No error is reported on line 53, regardless of whether there is a [tools.pyright] section in pyproject.toml

Actual behavior

if there is a [tools.pyright] section in pyproject.toml, an invalid error is reported on line 53.

Logs

2024-12-20 12:39:43.212 [info] (9416) Server settings returned for workspace: undefined: {
  "autoSearchPaths": true,
  "disableLanguageServices": false,
  "openFilesOnly": true,
  "useLibraryCodeForTypes": true,
  "watchForSourceChanges": true,
  "watchForLibraryChanges": true,
  "watchForConfigChanges": true,
  "typeCheckingMode": "off",
  "diagnosticSeverityOverrides": {
    "reportShadowedImports": "warning"
  },
  "diagnosticBooleanOverrides": {
    "strictListInference": false,
    "strictDictionaryInference": false,
    "strictSetInference": false,
    "analyzeUnannotatedFunctions": true,
    "strictParameterNoneValue": true,
    "enableTypeIgnoreComments": true,
    "deprecateTypingAliases": false,
    "enableReachabilityAnalysis": false,
    "enableExperimentalFeatures": false,
    "disableBytesTypePromotions": false
  },
  "logLevel": "log",
  "autoImportCompletions": false,
  "indexing": false,
  "completeFunctionParens": false,
  "enableExtractCodeAction": true,
  "indexOptions": {
    "packageDepths": [
      [
        "sklearn",
        2,
        false
      ],
      [
        "matplotlib",
        2,
        false
      ],
      [
        "scipy",
        2,
        false
      ],
      [
        "django",
        2,
        false
      ],
      [
        "flask",
        2,
        false
      ],
      [
        "fastapi",
        2,
        false
      ]
    ],
    "regenerateStdLibIndices": false,
    "includeAliasesFromUserFiles": false,
    "userFileIndexingLimit": 2000
  },
  "variableInlayTypeHints": false,
  "callArgumentNameInlayHints": "off",
  "functionReturnInlayTypeHints": false,
  "pytestParametersInlayTypeHints": false,
  "importFormat": "absolute",
  "includeFileSpecs": [],
  "excludeFileSpecs": [],
  "ignoreFileSpecs": [],
  "formatOnType": true,
  "taskListTokens": [],
  "enablePytestSupport": true,
  "gotoDefinitionInStringLiteral": true,
  "remapDiagnostics": false,
  "intelliCodeEnabled": true,
  "aiCodeActions": {
    "implementAbstractClasses": true
  },
  "generateWithTypeAnnotation": false,
  "languageServerMode": "default",
  "pythonPath": {
    "_key": "c:\\users\\anabelle\\appdata\\local\\programs\\python\\python310\\python.exe",
    "_filePath": "c:\\Users\\anabelle\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
    "_query": "",
    "_fragment": "",
    "_originalString": "file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/python.exe",
    "_isCaseSensitive": false,
    "_formattedString": "file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/python.exe"
  },
  "pythonEnvironmentName": "3.10.11 (global)",
  "disableTaggedHints": false,
  "fixAll": [],
  "showOnlyDirectDependenciesInAutoImport": false,
  "extraCommitChars": false,
  "autoFormatStrings": false,
  "autoIndent": true,
  "supportRestructuredText": false,
  "cacheLSPData": false,
  "reportExtraTelemetry": false,
  "supportDocstringTemplate": false,
  "displayEnglishDiagnostics": false,
  "nodeExecutable": "",
  "notebookRunStartupCommands": "",
  "editorIndentConfig": {
    "defaultTabSequence": "    ",
    "tabSize": 4
  }
}
2024-12-20 12:39:55.884 [info] [Info  - 12:39:55 PM] (28360) Server root directory: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist
2024-12-20 12:39:55.926 [info] [Info  - 12:39:55 PM] (28360) Pylance language server 2024.12.1 (pyright version 1.1.389, commit ce1325fc) starting
2024-12-20 12:39:55.960 [info] [Info  - 12:39:55 PM] (28360) Starting service instance "testproject"
2024-12-20 12:39:56.092 [info] (Client) Pylance async client (2024.12.1) started with python extension (2024.22.0)
2024-12-20 12:39:56.775 [info] (28360) No configuration file found.
2024-12-20 12:39:56.808 [info] (28360) pyproject.toml file found at c:\Users\anabelle\testproject.
2024-12-20 12:39:56.813 [info] [Info  - 12:39:56 PM] (28360) Loading pyproject.toml file at c:\Users\anabelle\testproject\pyproject.toml
2024-12-20 12:39:56.821 [info] [Info  - 12:39:56 PM] (28360) Setting pythonPath for service "testproject": "C:\Users\anabelle\AppData\Local\Programs\Python\Python310\python.exe"
2024-12-20 12:39:56.823 [info] [Info  - 12:39:56 PM] (28360) No include entries specified; assuming c:\Users\anabelle\testproject
2024-12-20 12:39:56.824 [info] [Info  - 12:39:56 PM] (28360) Auto-excluding **/node_modules
2024-12-20 12:39:56.824 [info] [Info  - 12:39:56 PM] (28360) Auto-excluding **/__pycache__
2024-12-20 12:39:56.824 [info] [Info  - 12:39:56 PM] (28360) Auto-excluding **/.*
2024-12-20 12:39:56.825 [info] [Info  - 12:39:56 PM] (28360) Assuming Python version 3.10.11.final.0
2024-12-20 12:39:56.825 [info] (28360) Assuming Python platform Windows
2024-12-20 12:39:57.058 [info] [Info  - 12:39:57 PM] (28360) Execution environment: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/python.exe
2024-12-20 12:39:57.059 [info] [Info  - 12:39:57 PM] (28360)   Extra paths:
2024-12-20 12:39:57.059 [info] [Info  - 12:39:57 PM] (28360)     (none)
2024-12-20 12:39:57.059 [info] [Info  - 12:39:57 PM] (28360)   Python version: 3.10.11.final.0
2024-12-20 12:39:57.060 [info] [Info  - 12:39:57 PM] (28360)   Python platform: Windows
2024-12-20 12:39:57.060 [info] [Info  - 12:39:57 PM] (28360)   Search paths:
2024-12-20 12:39:57.060 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\.vscode\extensions\ms-python.vscode-pylance-2024.12.1\dist\typeshed-fallback\stdlib
2024-12-20 12:39:57.060 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\testproject
2024-12-20 12:39:57.061 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\testproject\typings
2024-12-20 12:39:57.061 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\.vscode\extensions\ms-python.vscode-pylance-2024.12.1\dist\typeshed-fallback\stubs\...
2024-12-20 12:39:57.062 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\.vscode\extensions\ms-python.vscode-pylance-2024.12.1\dist\bundled\stubs
2024-12-20 12:39:57.062 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Local\Programs\Python\Python310\DLLs
2024-12-20 12:39:57.062 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Local\Programs\Python\Python310\Lib
2024-12-20 12:39:57.062 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Local\Programs\Python\Python310
2024-12-20 12:39:57.063 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Roaming\Python\Python310\site-packages
2024-12-20 12:39:57.063 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Roaming\Python\Python310\site-packages\win32
2024-12-20 12:39:57.063 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Roaming\Python\Python310\site-packages\win32\lib
2024-12-20 12:39:57.063 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Roaming\Python\Python310\site-packages\pythonwin
2024-12-20 12:39:57.064 [info] [Info  - 12:39:57 PM] (28360)     c:\Users\anabelle\AppData\Local\Programs\Python\Python310\Lib\site-packages
2024-12-20 12:39:57.064 [info] [Info  - 12:39:57 PM] (28360) Adding fs watcher for library directories:
 file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib
file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310
file:///c%3A/Users/anabelle/AppData/Roaming/Python/Python310/site-packages
2024-12-20 12:39:57.064 [info] [Info  - 12:39:57 PM] (28360) Adding fs watcher for directories:
 file:///c%3A/Users/anabelle/testproject
2024-12-20 12:39:57.064 [info] (28360) Searching for source files
2024-12-20 12:39:57.067 [info] [Info  - 12:39:57 PM] (28360) Found 1 source file
2024-12-20 12:39:57.067 [info] (28360) Adding fs watcher for files:
 file:///c%3A/Users/anabelle/testproject/requirements.txt
file:///c%3A/Users/anabelle/testproject/pyproject.toml
2024-12-20 12:39:57.088 [info] (28360) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-12-20 12:39:57.215 [info] (28360) Attempting to resolve using local imports: __builtins__
2024-12-20 12:39:57.233 [info] (28360) [FG] parsing: file:///c%3A/Users/anabelle/testproject/tmp2.py (137ms)
2024-12-20 12:39:57.335 [info] (28360) [FG] parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (100ms)
2024-12-20 12:39:57.389 [info] (28360) [FG] binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/builtins.pyi (52ms)
2024-12-20 12:39:57.390 [info] (28360) [FG] binding: file:///c%3A/Users/anabelle/testproject/tmp2.py (2ms)
2024-12-20 12:39:57.404 [info] (28360) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-12-20 12:39:57.598 [info] [Info  - 12:39:57 PM] (28360) Background analysis(1) root directory: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist
2024-12-20 12:39:57.600 [info] [Info  - 12:39:57 PM] (28360) Background analysis(1) started
2024-12-20 12:39:57.749 [info] [Info  - 12:39:57 PM] (28360) Indexer background runner(2) root directory: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist (index)
2024-12-20 12:39:57.750 [info] [Info  - 12:39:57 PM] (28360) Indexing(2) started
2024-12-20 12:39:57.753 [info] (28360) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-12-20 12:39:57.834 [info] (28360) Attempting to resolve using local imports: __builtins__
2024-12-20 12:39:57.850 [info] (28360) [BG(1)] SemanticTokens full at file:///c%3A/Users/anabelle/testproject/tmp2.py ...
2024-12-20 12:39:57.850 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/testproject/tmp2.py (92ms)
2024-12-20 12:39:57.926 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (74ms)
2024-12-20 12:39:57.972 [info] (28360) [IDX(2)] scan packages file:///c%3A/Users/anabelle/testproject ...
2024-12-20 12:39:57.972 [info] (28360) [IDX(2)]   read stdlib indices (33ms)
2024-12-20 12:39:57.977 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/builtins.pyi (48ms)
2024-12-20 12:39:57.980 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/testproject/tmp2.py (3ms)
2024-12-20 12:39:58.001 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/typing.pyi [fs read 2ms] (16ms)
2024-12-20 12:39:58.010 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/typing.pyi (8ms)
2024-12-20 12:39:58.050 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/types.pyi [fs read 0ms] (27ms)
2024-12-20 12:39:58.057 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/types.pyi (7ms)
2024-12-20 12:39:58.069 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (5ms)
2024-12-20 12:39:58.074 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (4ms)
2024-12-20 12:39:58.084 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/abc.pyi [fs read 1ms] (2ms)
2024-12-20 12:39:58.085 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
2024-12-20 12:39:58.089 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/collections/abc.pyi [fs read 0ms] (0ms)
2024-12-20 12:39:58.090 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/collections/abc.pyi ...
2024-12-20 12:39:58.090 [info] (28360) [BG(1)]     parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/_collections_abc.pyi [fs read 0ms] (1ms)
2024-12-20 12:39:58.091 [info] (28360) [BG(1)]     binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/_collections_abc.pyi (1ms)
2024-12-20 12:39:58.091 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/collections/abc.pyi (2ms)
2024-12-20 12:39:58.094 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/numbers.pyi [fs read 1ms] (2ms)
2024-12-20 12:39:58.103 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/numbers.pyi (3ms)
2024-12-20 12:39:58.106 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attr/__init__.pyi [fs read 0ms] (8ms)
2024-12-20 12:39:58.112 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attr/__init__.pyi (4ms)
2024-12-20 12:39:58.117 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (4ms)
2024-12-20 12:39:58.120 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi (2ms)
2024-12-20 12:39:58.144 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attrs/__init__.pyi [fs read 0ms] (12ms)
2024-12-20 12:39:58.146 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attrs/__init__.pyi (2ms)
2024-12-20 12:39:58.157 [info] (28360) [BG(1)]   parsing: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attr/setters.pyi [fs read 0ms] (1ms)
2024-12-20 12:39:58.158 [info] (28360) [BG(1)]   binding: file:///c%3A/Users/anabelle/AppData/Local/Programs/Python/Python310/Lib/site-packages/attr/setters.pyi (1ms)
2024-12-20 12:39:58.252 [info] (28360) [BG(1)] SemanticTokens full at file:///c%3A/Users/anabelle/testproject/tmp2.py (496ms)
2024-12-20 12:39:58.261 [info] (28360) [BG(1)] SemanticTokens range 15:0 - 56:0 at file:///c%3A/Users/anabelle/testproject/tmp2.py (5ms)
2024-12-20 12:39:58.264 [info] (28360) [BG(1)] indexing: file:///c%3A/Users/anabelle/testproject/tmp2.py [found 3] (1ms)
2024-12-20 12:39:58.264 [info] (28360) Workspace indexing done: file:///c%3A/Users/anabelle/testproject/tmp2.py
2024-12-20 12:39:58.298 [info] (28360) [BG(1)] analyzing: file:///c%3A/Users/anabelle/testproject/tmp2.py ...
2024-12-20 12:39:58.298 [info] (28360) [BG(1)]   checking: file:///c%3A/Users/anabelle/testproject/tmp2.py (31ms)
2024-12-20 12:39:58.298 [info] (28360) [BG(1)] analyzing: file:///c%3A/Users/anabelle/testproject/tmp2.py (32ms)
2024-12-20 12:39:58.307 [info] (28360) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-12-20 12:39:58.318 [info] (28360) [BG(1)] SemanticTokens delta previousResultId:1734716397980 at file:///c%3A/Users/anabelle/testproject/tmp2.py (5ms)
2024-12-20 12:39:58.896 [info] (28360) [IDX(2)] scan packages file:///c%3A/Users/anabelle/testproject (958ms)
2024-12-20 12:39:58.896 [info] [Info  - 12:39:58 PM] (28360) scanned(2) 326 files over 1 exec env
2024-12-20 12:39:59.192 [info] (28360) [IDX(2)] index packages file:///c%3A/Users/anabelle/testproject ...
2024-12-20 12:39:59.193 [info] (28360) [IDX(2)]   index execution environment file:///c%3A/Users/anabelle/testproject [found 10753 in 326 files] (12ms)
2024-12-20 12:39:59.193 [info] (28360) [IDX(2)] index packages file:///c%3A/Users/anabelle/testproject [found 10753 in 1 exec envs] (74ms)
2024-12-20 12:39:59.193 [info] [Info  - 12:39:59 PM] (28360) indexed(2) 326 files over 1 exec env
2024-12-20 12:39:59.288 [info] [Info  - 12:39:59 PM] (28360) Indexing finished(2).
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Dec 20, 2024
@erictraut
Copy link
Contributor

Pyright (the type checker upon which pylance is built) is behaving correctly here, so this isn't a bug. The built-in type float is not a subtype of numbers.Real, so the types are not compatible. The Python typing spec mandates the rules for type compatibility, and pyright conforms to the spec. Not surprisingly, other type checkers like mypy generate the same error in this situation.

The root of this is in how numbers.Real is defined in the typeshed type stubs. This class (and others, like numbers.Complex) are nominal types rather than structural types (protocols). There have been long debates within the Python typing community about changing these to protocols, but I think a change is unlikely.

I generally recommend avoiding the use of the numbers module if you want your code to type check without errors.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 20, 2024

See this for why the pyproject.toml causes this error. Having one changes your default typecheckingmode to 'standard'.

@rchiodo rchiodo closed this as completed Dec 20, 2024
@rchiodo rchiodo added the settings-override Feedback that pyrightconfig.json is taking precedence label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet settings-override Feedback that pyrightconfig.json is taking precedence
Projects
None yet
Development

No branches or pull requests

4 participants