diff --git a/src/pystow/impl.py b/src/pystow/impl.py index bab9445..3f2c612 100644 --- a/src/pystow/impl.py +++ b/src/pystow/impl.py @@ -27,6 +27,7 @@ Optional, Sequence, Union, + cast, overload, ) @@ -875,7 +876,6 @@ def ensure_csv( :param download_kwargs: Keyword arguments to pass through to :func:`pystow.utils.download`. :param read_csv_kwargs: Keyword arguments to pass through to :func:`pandas.read_csv`. :return: A pandas DataFrame - :rtype: pandas.DataFrame """ import pandas as pd @@ -1438,7 +1438,6 @@ def ensure_zip_df( :param download_kwargs: Keyword arguments to pass through to :func:`pystow.utils.download`. :param read_csv_kwargs: Keyword arguments to pass through to :func:`pandas.read_csv`. :return: A pandas DataFrame - :rtype: pandas.DataFrame """ path = self.ensure( *subkeys, url=url, name=name, force=force, download_kwargs=download_kwargs @@ -1478,7 +1477,6 @@ def ensure_zip_np( Additional keyword arguments that are passed through to :func:`read_zip_np` and transitively to :func:`numpy.load`. :returns: An array-like object - :rtype: numpy.typing.ArrayLike """ path = self.ensure( *subkeys, url=url, name=name, force=force, download_kwargs=download_kwargs @@ -1514,7 +1512,6 @@ def ensure_rdf( Keyword arguments to pass through to :func:`pystow.utils.read_rdf` and transitively to :func:`rdflib.Graph.parse`. :return: An RDF graph - :rtype: rdflib.Graph """ path = self.ensure( *subkeys, url=url, name=name, force=force, download_kwargs=download_kwargs @@ -1525,7 +1522,7 @@ def ensure_rdf( cache_path = path.with_suffix(path.suffix + ".pickle.gz") if cache_path.exists() and not force: with gzip.open(cache_path, "rb") as file: - return pickle.load(file) + return cast(rdflib.Graph, pickle.load(file)) rv = read_rdf(path=path, **(parse_kwargs or {})) with gzip.open(cache_path, "wb") as file: diff --git a/src/pystow/utils.py b/src/pystow/utils.py index c0e7c2d..9e16175 100644 --- a/src/pystow/utils.py +++ b/src/pystow/utils.py @@ -31,6 +31,7 @@ NamedTuple, Optional, Union, + cast, ) from urllib.parse import urlparse from urllib.request import urlretrieve @@ -736,7 +737,7 @@ def read_zip_np(path: Union[str, Path], inner_path: str, **kwargs: Any) -> "nump with zipfile.ZipFile(file=path) as zip_file: with zip_file.open(inner_path) as file: - return np.load(file, **kwargs) + return cast(np.typing.ArrayLike, np.load(file, **kwargs)) def read_zipfile_rdf(path: Union[str, Path], inner_path: str, **kwargs: Any) -> "rdflib.Graph": @@ -752,7 +753,7 @@ def read_zipfile_rdf(path: Union[str, Path], inner_path: str, **kwargs: Any) -> graph = rdflib.Graph() with zipfile.ZipFile(file=path) as zip_file: with zip_file.open(inner_path) as file: - graph.load(file, **kwargs) + graph.parse(file, **kwargs) return graph @@ -809,7 +810,6 @@ def read_tarfile_xml( :param inner_path: The path inside the tar archive to the xml file :param kwargs: Additional kwargs to pass to :func:`lxml.etree.parse` :return: An XML element tree - :rtype: lxml.etree.ElementTree """ from lxml import etree @@ -833,7 +833,7 @@ def read_rdf(path: Union[str, Path], **kwargs: Any) -> "rdflib.Graph": with ( gzip.open(path, "rb") if isinstance(path, Path) and path.suffix == ".gz" else open(path) ) as file: - graph.parse(file, **kwargs) + graph.parse(file, **kwargs) # type:ignore return graph diff --git a/tox.ini b/tox.ini index 0ff69bd..dbb7610 100644 --- a/tox.ini +++ b/tox.ini @@ -104,7 +104,10 @@ description = Run linters. deps = mypy types-requests -skip_install = true +extras = + pandas + rdf + xml commands = mypy --install-types --non-interactive --ignore-missing-imports --strict src/pystow/ description = Run the mypy tool to check static typing on the project.