You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One way to avoid this error is for end users to directly use implementation-specific CloudPath subclasses. The following script produces no Mypy errors:
Lastly, some changes could be made to how CloudPath instances are constructed to work around this issue. However, this would introduce a new way of instantiating CloudPath instances, which could be confusing.
One option would be to add a CloudPath.from_url class method, which would just return CloudPath(url). This way, the Mypy error could be ignored in the cloudpathlib codebase rather than user code.
Another option would be to implement cloud provider-specific dispatching in the new CloudPath.from_url class method, then have CloudPathMeta.__call__ delegate to CloudPath.from_url for its implementation. This wouldn't require any new ignore directives in the cloudpathlib codebase.
In any case, I didn't find any issues describing this behavior elsewhere, so hopefully this is helpful to others who run into this same issue in the future 🙂
Thanks for maintaining cloudpathlib! 😄
The text was updated successfully, but these errors were encountered:
Description
Currently, type-checking a very simple script that uses
cloudpathlib
with Mypy fails with an error.Script:
Mypy error:
Cause
I believe this is a result of the fact that Mypy doesn't yet understand the
__call__
method on metaclasses.Workarounds
Specific Subclass
One way to avoid this error is for end users to directly use implementation-specific
CloudPath
subclasses. The following script produces no Mypy errors:This slightly limits portability of end user scripts, but is one possible way to avoid the error.
Ignore Directive
The error can also be ignored with a
# type: ignore[abstract]
directive:New Method
Lastly, some changes could be made to how
CloudPath
instances are constructed to work around this issue. However, this would introduce a new way of instantiatingCloudPath
instances, which could be confusing.One option would be to add a
CloudPath.from_url
class method, which would justreturn CloudPath(url)
. This way, the Mypy error could be ignored in thecloudpathlib
codebase rather than user code.Another option would be to implement cloud provider-specific dispatching in the new
CloudPath.from_url
class method, then haveCloudPathMeta.__call__
delegate toCloudPath.from_url
for its implementation. This wouldn't require any new ignore directives in thecloudpathlib
codebase.In any case, I didn't find any issues describing this behavior elsewhere, so hopefully this is helpful to others who run into this same issue in the future 🙂
Thanks for maintaining cloudpathlib! 😄
The text was updated successfully, but these errors were encountered: