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
All pathlib.Path,... have the same interface, but are not based on the same class.
We should have a typing annotation based on protocol (https://www.python.org/dev/peps/pep-0544/) to annotate those functions:
Could be inspired from importlib_resources.abc.Traversable:
classTraversable(typing.Protocol):
""" An object with a subset of pathlib.Path methods suitable for traversing directories and opening files. """@abc.abstractmethoddefiterdir(self):
""" Yield Traversable objects in self """@abc.abstractmethoddefread_bytes(self):
""" Read contents of self as bytes """@abc.abstractmethoddefread_text(self, encoding=None):
""" Read contents of self as bytes """@abc.abstractmethoddefis_dir(self):
""" Return True if self is a dir """@abc.abstractmethoddefis_file(self):
""" Return True if self is a file """@abc.abstractmethoddefjoinpath(self, child):
""" Return Traversable child in self """@abc.abstractmethoddef__truediv__(self, child):
""" Return Traversable child in self """@abc.abstractmethoddefopen(self, mode='r', *args, **kwargs):
""" mode may be 'r' or 'rb' to open as text or binary. Return a handle suitable for reading (same as pathlib.Path.open). When opening as text, accepts encoding parameters such as those accepted by io.TextIOWrapper. """@abc.abstractpropertydefname(self):
# type: () -> str""" The base name of this object without any parent references. """
https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/core/utils/type_utils.py define Python typing annotations.
Currently it's not easy to annotate function which accept multiple types of pathlib-like object:
All
pathlib.Path
,... have the same interface, but are not based on the same class.We should have a typing annotation based on protocol (https://www.python.org/dev/peps/pep-0544/) to annotate those functions:
It will be very helpful when a Gfile based path-like interface exists.
The text was updated successfully, but these errors were encountered: