cloudpathlib icon indicating copy to clipboard operation
cloudpathlib copied to clipboard

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

Open karolzlot opened this issue 4 years ago • 16 comments

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

image

karolzlot avatar Nov 11 '21 12:11 karolzlot

Pylance uses pyright to do type checking. We use (and pass) with mypy. Here's the error output with pyright for reference if anyone wants to tackle making pyright pass as well:

❯ pyright cloudpathlib
npx: installed 1 in 1.553s
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 25 source files
/Users/bull/code/cloudpathlib/cloudpathlib/client.py
  /Users/bull/code/cloudpathlib/cloudpathlib/client.py:58:16 - error: Object of type "None" cannot be called (reportOptionalCall)
/Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:66:64 - error: Cannot access member "__name__" for type "None"
    Member "__name__" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:89:38 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of 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.prefixes.py:122:31 - error: Argument of type "Self@CloudPathMeta" cannot be assigned to parameter "cls" of type "Type[_TT@__new__]" in function "__new__"
    Type "Self@CloudPathMeta" cannot be assigned to type "Type[_TT@__new__]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:153:14 - error: Cannot assign member "cloud_prefix" for type "CloudPath"
    Expression of type "str | None" cannot be assigned to member "cloud_prefix" of class "CloudPath"
      Type "str | None" cannot be assigned to type "str"
        Type "None" cannot be assigned to type "str" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:165:56 - error: Cannot access member "get_default_client" for type "None"
    Member "get_default_client" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:166:35 - error: Argument of type "None" cannot be assigned to parameter "__class_or_tuple" of type "type | UnionType | Tuple[type | UnionType | Tuple[Any, ...], ...]" in function "isinstance"
    Type "None" cannot be assigned to type "type | UnionType | Tuple[type | UnionType | Tuple[Any, ...], ...]"
      Type "None" cannot be assigned to type "type"
      Type "None" cannot be assigned to type "UnionType"
      Type "None" cannot be assigned to type "Tuple[type | UnionType | Tuple[Any, ...], ...]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.prefixes.py:166: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.prefixes.py:172:14 - error: Cannot assign member "client" for type "CloudPath"
    Expression of type "Client[Unknown] | None" cannot be assigned to member "client" of class "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.prefixes.py:419: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
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:49:64 - error: Cannot access member "__name__" for type "None"
    Member "__name__" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:72:38 - error: Cannot assign member "_path_class" for type "CloudImplementation"
    Expression of 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:105:31 - error: Argument of type "Self@CloudPathMeta" cannot be assigned to parameter "cls" of type "Type[_TT@__new__]" in function "__new__"
    Type "Self@CloudPathMeta" cannot be assigned to type "Type[_TT@__new__]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:158: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:159:35 - error: Argument of type "None" cannot be assigned to parameter "__class_or_tuple" of type "type | UnionType | Tuple[type | UnionType | Tuple[Any, ...], ...]" in function "isinstance"
    Type "None" cannot be assigned to type "type | UnionType | Tuple[type | UnionType | Tuple[Any, ...], ...]"
      Type "None" cannot be assigned to type "type"
      Type "None" cannot be assigned to type "UnionType"
      Type "None" cannot be assigned to type "Tuple[type | UnionType | Tuple[Any, ...], ...]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:159: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:165:14 - error: Cannot assign member "client" for type "CloudPath"
    Expression of type "Client[Unknown] | None" cannot be assigned to member "client" of class "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:423: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:594:31 - error: Operator "/" not supported for types "Path" and "Unknown | list[Unknown] | Any | Sequence[Unknown]"
    Operator "/" not supported for types "Path" and "list[Unknown]"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:624:33 - error: Cannot access member "upload_from" for type "list[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:624:33 - error: Cannot access member "upload_from" for type "Sequence[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:634:17 - error: Cannot access member "_upload_file_to_cloud" for type "list[Unknown]"
    Member "_upload_file_to_cloud" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:634: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:636:20 - error: Expression of type "Unknown | list[Unknown] | Any | Sequence[Unknown] | Self@CloudPath" cannot be assigned to return type "CloudPath"
    Type "Unknown | list[Unknown] | Any | Sequence[Unknown] | CloudPath" cannot be assigned to type "CloudPath"
      "list[Unknown]" is incompatible with "CloudPath"
      "Sequence[Unknown]" is incompatible with "CloudPath" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:651: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:680:50 - error: Cannot access member "upload_from" for type "list[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:680:50 - error: Cannot access member "upload_from" for type "Sequence[Unknown]"
    Member "upload_from" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:709:21 - error: Operator "/" not supported for types "CloudPath | Path" and "Unknown | list[Unknown] | Any | Sequence[Unknown]"
    Operator "/" not supported for types "Path" and "list[Unknown]"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:713:21 - error: Operator "/" not supported for types "CloudPath | Path" and "Unknown | list[Unknown] | Any | Sequence[Unknown]"
    Operator "/" not supported for types "Path" and "list[Unknown]"
    Operator "/" not supported for types "Path" and "Sequence[Unknown]" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/cloudpath.py:640:9 - error: Parameter declaration "destination" is obscured by a declaration of the same name (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/progress.py
  /Users/bull/code/cloudpathlib/cloudpathlib/progress.py:5:6 - error: Import "tqdm" could not be resolved (reportMissingImports)
  /Users/bull/code/cloudpathlib/cloudpathlib/progress.py:86:30 - error: Cannot assign member "_update_progress" for type "Type[_ChunkDownloader]"
    Expression of type "(slf: Unknown, length: Unknown) -> None" cannot be assigned to member "_update_progress" of class "_ChunkDownloader"
      Type "(slf: Unknown, length: Unknown) -> None" cannot be assigned to type "(self: _ChunkDownloader, length: Unknown) -> Unknown"
        Parameter name mismatch: "self" versus "slf" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/progress.py:87:28 - error: Cannot assign member "_update_progress" for type "Type[_ChunkUploader]"
    Expression of type "(slf: Unknown, length: Unknown) -> None" cannot be assigned to member "_update_progress" of class "_ChunkUploader"
      Type "(slf: Unknown, length: Unknown) -> None" cannot be assigned to type "(self: _ChunkUploader, length: Unknown) -> Unknown"
        Parameter name mismatch: "self" versus "slf" (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:91:65 - error: "BlobProperties" is possibly unbound (reportUnboundVariable)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:93:34 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:93:61 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:103:34 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:103:61 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:118:27 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:125:33 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:130:84 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:144:80 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:146:29 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:165:61 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:172:53 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:180:31 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:180:51 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:188:72 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:188:92 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:190:72 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:190:92 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:201:24 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:202:84 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:206:38 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:206:65 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:215:34 - error: Cannot access member "container" for type "CloudPath"
    Member "container" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobclient.py:215:61 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:80:46 - error: Cannot access member "timestamp" for type "int"
    Member "timestamp" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/azure/azblobpath.py:71:13 - error: Argument of type "tuple[None, None, str, None, None, None, Unknown | Any | Literal[0], None, Unknown | Any, None]" cannot be assigned to parameter "tuple" of type "Tuple[int, ...]" in function "__init__"
    Tuple entry 1 is incorrect type
      Type "None" cannot be assigned to type "int" (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:82:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:83:43 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:95:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:96:43 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:105:27 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:108:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:109:43 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:114:33 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:131:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:133:29 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:152:61 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:159:53 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:164:45 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:165:40 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:175:49 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:176:49 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:178:48 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:179:60 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:188:24 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:189:52 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:193:52 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:194:40 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:197:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gsclient.py:198:39 - error: Cannot access member "blob" for type "CloudPath"
    Member "blob" is unknown (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py:70:13 - error: Argument of type "tuple[None, None, str, None, None, None, Any | Literal[0], None, Any | Literal[0], None]" cannot be assigned to parameter "tuple" of type "Tuple[int, ...]" in function "__init__"
    Tuple entry 1 is incorrect type
      Type "None" cannot be assigned to type "int" (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/gs/gspath.py:101: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:50: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/s3client.py
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:98:49 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:98:68 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:110:41 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:110:60 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:117:27 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:138:45 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:138:64 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:148:51 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:149:59 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:128:51 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:157:44 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:159:29 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:171:65 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:180:35 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:185:61 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:189:61 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:194:36 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:194:48 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:196:43 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:196:62 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:202:41 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:202:53 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:203:40 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:203:59 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:211:45 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:211:64 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:221:48 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:223:33 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:235:41 - error: Cannot access member "bucket" for type "CloudPath"
    Member "bucket" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3client.py:235:60 - error: Cannot access member "key" for type "CloudPath"
    Member "key" is unknown (reportGeneralTypeIssues)
/Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py:75:46 - error: Cannot access member "timestamp" for type "int"
    Member "timestamp" is unknown (reportGeneralTypeIssues)
  /Users/bull/code/cloudpathlib/cloudpathlib/s3/s3path.py:66:13 - error: Argument of type "tuple[None, None, str, None, None, None, Any | Literal[0], None, Any | Unknown, None]" cannot be assigned to parameter "tuple" of type "Tuple[int, ...]" in function "__init__"
    Tuple entry 1 is incorrect type
      Type "None" cannot be assigned to type "int" (reportGeneralTypeIssues)
124 errors, 0 warnings, 0 infos
Completed in 1.884sec

pjbull avatar Nov 12 '21 16:11 pjbull

@pjbull Important information is here:

https://github.com/microsoft/pyright/issues/3117#issuecomment-1053539303

karolzlot avatar Feb 27 '22 12:02 karolzlot

Thanks for sharing those details.

Does the workaround mentioned resolve the reported pylance error at least? That would be good for other folks finding this issue to know.

Your pyright config is relevant here. I can reproduce this with"useLibraryCodeForTypes": truebut not with "useLibraryCodeForTypes": false.

It's still the case that we'd accept a PR that makes pyright pass and adds that verification to CI. That said, if I'm reading the issue you linked right, it seems that typing any of the properties that use the dispatching to the Path version may be tricky.

pjbull avatar Feb 28 '22 01:02 pjbull

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:
    ...

hmc-cs-mdrissi avatar Feb 28 '22 03:02 hmc-cs-mdrissi

@pjbull

When I disable this setting: image

I don't have previous error anymore, but I don't have anything, no autocompletion, nothing:

image

image

So this is fixing it, but at the same time it is disabling so much convenience (auto-completion). So I will keep this setting turned on ;)

karolzlot avatar Mar 01 '22 00:03 karolzlot

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

pjbull avatar Dec 19 '22 00:12 pjbull

I discovered one issue, described here: https://github.com/microsoft/pyright/issues/4896

If you think that CloudPath.init should accept any CloudPath argument, then you should report the bug to the library maintainer. If the CloudPath.init type information is correct, then you must pass an S3PathWrapper object to it, not any CloudPath.

I am reporting here, because I think it is issue in cloudpathlib.

karolzlot avatar Apr 13 '23 09:04 karolzlot

@karolzlot Do you know what the required change would look like? It does seem that CloudPath should be initializable from any CloudPath object (including S3Path, GSPath, etc.), but S3Path should just work with S3Path. That makes me think maybe the issue is more about how the wrapper class in your example is architected than a library problem, but maybe I am missing something.

pjbull avatar Apr 14 '23 18:04 pjbull

@karolzlot, a few thoughts here from looking at your example in https://github.com/microsoft/pyright/issues/4896:

First, as @pjbull said, S3Path intentionally does not accept any CloudPath object as an argument—it should only work with S3Path. I think you actually intend something like:

cloud_path: Union[str, S3Path]

However, this will still result in a type error from pyright, because super().__init__ is expecting cloud_path: Union[str, S3PathWrapper]. As was correctly explained in this comment in the other thread, the inherited super().__init__ is designed only to expect objects of the self type.

It may be possible that we could change S3Path to explicitly initialize from instances of S3Path rather than a self class. That would mean subclasses would in general inherit an __init__ that takes S3Path, like what you are doing. However, I'm not convinced this is a sensible change to make—in general, I would expect more often that subclasses add more behavior that would be missing from the parent S3Path and so it wouldn't make sense to be able to initialize from S3Path.

I don't know much about what you're trying to accomplish since you've only shared a minimal example with the interface. However, the fact that you named your class "Wrapper" suggests that subclassing isn't the best approach. You may want a different implementation that stores an instance of S3Path as an attribute (that actually wraps S3Path).

jayqi avatar Apr 16 '23 03:04 jayqi

@pjbull @jayqi

Sorry for confusion with CloudPath, I only need S3Path.

It's possible that this suggestion with using S3Path object as attribute is right approach, I will try it, thanks! What I did: I added custom download method for S3Path object, because the one provided by cloudpathlib is not fast enough.


My understanding of this issue isn't very good, maybe cloudpathlib really doesn't need changes in this regard. I can't recommend anything, because I feel those concepts are still too difficult for me.

karolzlot avatar Apr 22 '23 23:04 karolzlot

PR #330 will solve this issue, right?

chopeen avatar Jun 16 '23 06:06 chopeen

I will try it once new version with this change is released. I think it will solve it :)

karolzlot avatar Jun 16 '23 10:06 karolzlot

0.15.0 is released if you want to give it a shot! https://pypi.org/project/cloudpathlib/

Going to leave this issue open since we still only pass mypy and not pyright with the default settings.

pjbull avatar Jun 16 '23 22:06 pjbull

FYI 0.15.0 solved all pyright errors beside this one:

(For me it's small issue, as it's enough to use # type:ignore on this or refactor this with approach suggested above)

from typing import Union
from cloudpathlib import S3Path

class S3PathWrapper(S3Path):

    def __init__(
        self,
        cloud_path: Union[str, S3Path],
    ):

        super().__init__(cloud_path=cloud_path)

image

karolzlot avatar Jun 18 '23 01:06 karolzlot

Related: https://github.com/microsoft/pyright/discussions/5258

karolzlot avatar Jun 27 '23 01:06 karolzlot

@karolzlot Your contribution has now shipped in version 0.16.0.

I think that pyright still doesn't pass outright, so will leave this open for now.

pjbull avatar Oct 10 '23 00:10 pjbull