question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pyright type checking does not pass (causing Pylance in vscode to show typing errors)

See original GitHub issue

For example I need to use str() for .stem field, otherwise it shows:

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hmc-cs-mdrissicommented, Feb 28, 2022

I would type hint properties normally and for _dispatch_to_path just do,

def _dispatch_to_path(self, func: str, *args: object, **kwargs: object) -> Any:
    ...

dispatch_to_path is doing too much magic to be understandable for a static type checker. Mostly getattribute and how literal string value of func can change return type in a variety of ways. After you effectively ignore _dispatch_to_path you can add hints for each property normally like,

@property
def name(self) -> str:
    ...
0reactions
pjbullcommented, Dec 19, 2022

Down to 48 errors on latest code with #298 and other improvements, next time someone looks at making pyright pass. I get pretty decent hinting in vscode currently, just for the record.

pyright cloudpathlib
npx: installed 1 in 2.127s
No configuration file found.
pyproject.toml file found at /Users/bull/code/cloudpathlib.
Loading pyproject.toml file at /Users/bull/code/cloudpathlib/pyproject.toml
Pyproject file "/Users/bull/code/cloudpathlib/pyproject.toml" is missing "[tool.pyright]" section.
stubPath /Users/bull/code/cloudpathlib/typings is not a valid directory.
Assuming Python platform Darwin
Searching for source files
Found 21 source files
pyright 1.1.284
/Users/bull/code/cloudpathlib/cloudpathlib/__init__.py
  /Users/bull/code/cloudpathlib/cloudpathlib/__init__.py:16:12 - error: Import "importlib_metadata" could not be resolved (reportMissingImports)
/Users/bull/code/cloudpathlib/cloudpathlib/client.py
  /Users/bull/code/cloudpathlib/cloudpathlib/client.py:64:16 - error: Object of type "None" cannot be called (reportOptionalCall)
/Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:131:31 - error: Argument of type "Self@CloudPathMeta" cannot be assigned to parameter "__mcls" of type "Type[Self@__new__]" in function "__new__"
    Type "Self@CloudPathMeta" cannot be assigned to type "Type[Self@__new__]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:11:5 - error: "_make_selector" is unknown import symbol (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:12:5 - error: "_posix_flavour" is unknown import symbol (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:13:5 - error: "_PathParents" is unknown import symbol (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:73:64 - error: Cannot access member "__name__" for type "None"
    Member "__name__" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:98:38 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of type "Type[Type[CloudPath]]*" cannot be assigned to member "_path_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:189:56 - error: Cannot access member "get_default_client" for type "None"
    Member "get_default_client" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:190:35 - error: Argument of type "None" cannot be assigned to parameter "__class_or_tuple" of type "_ClassInfo" in function "isinstance"
    Type "None" cannot be assigned to type "_ClassInfo"
      Type "None" cannot be assigned to type "type"
      Type "None" cannot be assigned to type "UnionType"
      Type "None" cannot be assigned to type "tuple[_ClassInfo, ...]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:190:35 - error: Second argument to "isinstance" must be a class or tuple of classes
    TypeVar or generic type with type arguments not allowed (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:196:31 - error: Cannot assign member "client" for type "CloudPath"
    Type "Client[Unknown] | None" cannot be assigned to type "Client[Unknown]"
      Type "None" cannot be assigned to type "Client[Unknown]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:222:48 - error: Cannot access member "get_default_client" for type "None"
    Member "get_default_client" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:575:20 - error: Expected no arguments to "Sequence" constructor (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:503:18 - error: Argument of type "Iterable[CloudPath]" cannot be assigned to parameter "__i" of type "SupportsNext[_T@next]" in function "next"
    "Iterable[CloudPath]" is incompatible with protocol "SupportsNext[_T@next]"
      "__next__" is not present (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:708:31 - error: Operator "/" not supported for types "Path" and "Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" when expected type is "str | PathLike[Unknown]"
    Operator "/" not supported for types "Path" and "tuple[Unknown, ...]" when expected type is "str | PathLike[Unknown]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:738:33 - error: Cannot access member "upload_from" for type "Sequence[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:738:33 - error: Cannot access member "upload_from" for type "tuple[Unknown, ...]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:748:17 - error: Cannot access member "_upload_file_to_cloud" for type "Sequence[Unknown]"
    Member "_upload_file_to_cloud" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:748:17 - error: Cannot access member "_upload_file_to_cloud" for type "tuple[Unknown, ...]"
    Member "_upload_file_to_cloud" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:750:20 - error: Expression of type "Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any | Self@CloudPath" cannot be assigned to return type "CloudPath"
    Type "Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any | CloudPath" cannot be assigned to type "CloudPath"
      "Sequence[Unknown]" is incompatible with "CloudPath" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:765:27 - error: Expression of type "CloudPath | Path" cannot be assigned to declared type "CloudPath"
    Type "CloudPath | Path" cannot be assigned to type "CloudPath"
      "Path" is incompatible with "CloudPath" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:794:50 - error: Cannot access member "upload_from" for type "Sequence[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:794:50 - error: Cannot access member "upload_from" for type "tuple[Unknown, ...]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:830:62 - error: Argument of type "list[Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any]" cannot be assigned to parameter of type "List[str | PathLike[Unknown] | CloudPath]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:841:21 - error: Operator "/" not supported for types "CloudPath | Path" and "Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" when expected type is "str | PathLike[Unknown] | CloudPath"
    Operator "/" not supported for types "Path" and "tuple[Unknown, ...]" when expected type is "str | PathLike[Unknown] | CloudPath" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:845:21 - error: Operator "/" not supported for types "CloudPath | Path" and "Unknown | Sequence[Unknown] | tuple[Unknown, ...] | Any"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" when expected type is "str | PathLike[Unknown] | CloudPath"
    Operator "/" not supported for types "Path" and "tuple[Unknown, ...]" when expected type is "str | PathLike[Unknown] | CloudPath" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:754:9 - error: Parameter declaration "destination" is obscured by a declaration of the same name (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:166:41 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:182:41 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
/Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:18:2 - error: Argument of type "Type[AzureBlobPath]" cannot be assigned to parameter "cls" of type "Type[T@decorator]" in function "decorator"
    Type "AzureBlobPath" cannot be assigned to type "Type[CloudPath]"
      Type "AzureBlobPath" cannot be assigned to type "Type[CloudPath]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:82:46 - error: "timestamp" is not a known member of "None" (reportOptionalMemberAccess)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:82:46 - error: Cannot access member "timestamp" for type "int"
    Member "timestamp" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:73:13 - error: Argument of type "tuple[None, None, str, None, None, None, Any | Unknown | int | None, None, Any | Unknown, None]" cannot be assigned to parameter "sequence" of type "Iterable[float]" in function "__new__"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    "str" is incompatible with "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "Any | Unknown | int | None" cannot be assigned to type "float"
      Type "None" cannot be assigned to type "float" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:107:76 - error: "get" is not a known member of "None" (reportOptionalMemberAccess)
/Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py:13:2 - error: Argument of type "Type[GSPath]" cannot be assigned to parameter "cls" of type "Type[T@decorator]" in function "decorator"
    Type "GSPath" cannot be assigned to type "Type[CloudPath]"
      Type "GSPath" cannot be assigned to type "Type[CloudPath]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py:72:13 - error: Argument of type "tuple[None, None, str, None, None, None, Any | int, None, Any | Literal[0], None]" cannot be assigned to parameter "sequence" of type "Iterable[float]" in function "__new__"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    "str" is incompatible with "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py:103:48 - error: "get" is not a known member of "None" (reportOptionalMemberAccess)
/Users/bull/code/cloudpathlib/cloudpathlib/local/localclient.py
  /Users/bull/code/cloudpathlib/cloudpathlib/local/localclient.py:52:52 - error: Cannot access member "cloud_prefix" for type "None"
    Member "cloud_prefix" is unknown (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/azure.py
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/azure.py:80:33 - error: Cannot assign member "_client_class" for type "CloudImplementation"
    Expression of type "Type[LocalAzureBlobClient]" cannot be assigned to member "_client_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/azure.py:81:33 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of type "Type[LocalAzureBlobPath]" cannot be assigned to member "_path_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/gs.py
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/gs.py:59:25 - error: Cannot assign member "_client_class" for type "CloudImplementation"
    Expression of type "Type[LocalGSClient]" cannot be assigned to member "_client_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/gs.py:60:25 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of type "Type[LocalGSPath]" cannot be assigned to member "_path_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/s3.py
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/s3.py:59:25 - error: Cannot assign member "_client_class" for type "CloudImplementation"
    Expression of type "Type[LocalS3Client]" cannot be assigned to member "_client_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/local/implementations/s3.py:60:25 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of type "Type[LocalS3Path]" cannot be assigned to member "_path_class" of class "CloudImplementation"
      Type cannot be assigned to type "None" (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py:13:2 - error: Argument of type "Type[S3Path]" cannot be assigned to parameter "cls" of type "Type[T@decorator]" in function "decorator"
    Type "S3Path" cannot be assigned to type "Type[CloudPath]"
      Type "S3Path" cannot be assigned to type "Type[CloudPath]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py:77:46 - error: Cannot access member "timestamp" for type "int"
    Member "timestamp" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py:68:13 - error: Argument of type "tuple[None, None, str, None, None, None, Any | int, None, Any | Unknown, None]" cannot be assigned to parameter "sequence" of type "Iterable[float]" in function "__new__"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    "str" is incompatible with "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float"
    Type "None" cannot be assigned to type "float" (reportGeneralTypeIssues)
48 errors, 0 warnings, 0 informations
Completed in 1.982sec
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pyright CLI and VSCode problem tab gives different ... - GitHub
The problems tab on Visual Studio Code (VSCode) shows no information, warning nor error message. But if I try to run the following...
Read more >
Suppress Pylance type annotation warning in VS Code
You can see the error type in the hover widget where error messages appear. pyrightconfig.json example: { "reportGeneralTypeIssues": false, }.
Read more >
How to enable Python type checking in VSCode
In this article, we will see how to enable type IntelliSense and type checking analysis in Visual Studio Code editor.
Read more >
is not a known member of module pylance - You.com
The units imported imported into builtins appear not to be recognised by mypy language server (used in Pylance extension in VS Code) and...
Read more >
Pyre: A performant type-checker for Python 3 | Hacker News
Pyright's VSCode integration, Pylance, provides a great auto ... method that takes kwargs because you can't express it with `typing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found