diff --git a/extras/fileformats/extras/application/archive.py b/extras/fileformats/extras/application/archive.py index 70a51e0..1d7bff1 100644 --- a/extras/fileformats/extras/application/archive.py +++ b/extras/fileformats/extras/application/archive.py @@ -10,7 +10,7 @@ import pydra.engine.specs from fileformats.generic import FsObject from fileformats.core.utils import set_cwd -from fileformats.core.type_aliases import PathType +from fileformats.core.typing import PathType from fileformats.core import converter, FileSet from fileformats.application import Zip, Tar, TarGzip @@ -238,4 +238,4 @@ def relative_path(path: PathType, base_dir: PathType) -> str: f"Cannot add {path} to archive as it is not a " f"subdirectory of {base_dir}" ) - return relpath + return relpath # type: ignore[no-any-return] diff --git a/extras/fileformats/extras/application/serialization.py b/extras/fileformats/extras/application/serialization.py index 0fdb189..65999d9 100644 --- a/extras/fileformats/extras/application/serialization.py +++ b/extras/fileformats/extras/application/serialization.py @@ -24,7 +24,7 @@ def convert_data_serialization( output_path = out_dir / ( in_file.fspath.stem + (output_format.ext if output_format.ext else "") ) - return output_format.save_new(output_path, dct) + return output_format.save_new(output_path, dct) # type: ignore[no-any-return] @extra_implementation(DataSerialization.load) diff --git a/extras/fileformats/extras/image/converters.py b/extras/fileformats/extras/image/converters.py index db01286..89266b9 100644 --- a/extras/fileformats/extras/image/converters.py +++ b/extras/fileformats/extras/image/converters.py @@ -25,4 +25,4 @@ def convert_image( output_path = out_dir / ( in_file.fspath.stem + (output_format.ext if output_format.ext else "") ) - return output_format.save_new(output_path, data_array) + return output_format.save_new(output_path, data_array) # type: ignore[no-any-return] diff --git a/fileformats/application/serialization.py b/fileformats/application/serialization.py index 1b23541..a454aea 100644 --- a/fileformats/application/serialization.py +++ b/fileformats/application/serialization.py @@ -1,6 +1,6 @@ import json import typing as ty -from typing_extensions import Self, TypeAlias +from fileformats.core.typing import Self, TypeAlias from pathlib import Path from fileformats.core import extra, DataType, FileSet, extra_implementation from fileformats.core.mixin import WithClassifiers diff --git a/fileformats/core/datatype.py b/fileformats/core/datatype.py index 3c2846b..8e7d14f 100644 --- a/fileformats/core/datatype.py +++ b/fileformats/core/datatype.py @@ -1,7 +1,7 @@ from __future__ import annotations from inspect import isclass import typing as ty -from typing_extensions import Self +from fileformats.core.typing import Self from abc import ABCMeta import importlib import itertools @@ -27,7 +27,7 @@ class DataType(Classifier, metaclass=ABCMeta): is_fileset = False is_field = False - nested_types: ty.Tuple[ty.Type["DataType"], ...] = () + nested_types: ty.Tuple[ty.Type[Classifier], ...] = () # Store converters registered by @converter decorator that convert to FileSet # NB: each class will have its own version of this dictionary converters: ty.Dict[ diff --git a/fileformats/core/extras.py b/fileformats/core/extras.py index db666b2..3305123 100644 --- a/fileformats/core/extras.py +++ b/fileformats/core/extras.py @@ -5,7 +5,7 @@ import functools import urllib.error import fileformats.core -from typing_extensions import TypeAlias +from fileformats.core.typing import TypeAlias from .datatype import DataType from .converter_helpers import ConverterWrapper, ConverterSpec, SubtypeVar from .exceptions import FormatConversionError, FileFormatsExtrasError diff --git a/fileformats/core/fileset.py b/fileformats/core/fileset.py index 919b770..5d87abb 100644 --- a/fileformats/core/fileset.py +++ b/fileformats/core/fileset.py @@ -14,7 +14,7 @@ from pathlib import Path import hashlib import logging -from typing_extensions import Self +from fileformats.core.typing import Self from .utils import ( classproperty, fspaths_converter, @@ -22,7 +22,7 @@ matching_source, import_extras_module, ) -from .type_aliases import FspathsInputType, CryptoMethod, PathType +from .typing import FspathsInputType, CryptoMethod, PathType from .sampling import SampleFileGenerator from .identification import ( to_mime_format_name, diff --git a/fileformats/core/mixin.py b/fileformats/core/mixin.py index b068184..97c2c5b 100644 --- a/fileformats/core/mixin.py +++ b/fileformats/core/mixin.py @@ -175,7 +175,7 @@ class MyFileFormatWithSeparateHeader(WithSeparateHeader, MyFileFormat): header_type: ty.Type["fileformats.core.FileSet"] @classproperty - def nested_types(cls) -> ty.Tuple[ty.Type["DataType"], ...]: + def nested_types(cls) -> ty.Tuple[ty.Type[Classifier], ...]: return (cls.header_type,) @property @@ -235,7 +235,7 @@ def read_metadata( return metadata @classproperty - def nested_types(cls) -> ty.Tuple[ty.Type["DataType"], ...]: + def nested_types(cls) -> ty.Tuple[ty.Type[Classifier], ...]: return cls.side_car_types @@ -316,7 +316,7 @@ def is_classified(cls) -> bool: return "unclassified" in cls.__dict__ @classproperty - def nested_types(cls) -> ty.Tuple[ty.Type["DataType"], ...]: + def nested_types(cls) -> ty.Tuple[ty.Type[Classifier], ...]: return cls.classifiers @classmethod diff --git a/fileformats/core/type_aliases.py b/fileformats/core/typing.py similarity index 60% rename from fileformats/core/type_aliases.py rename to fileformats/core/typing.py index 4825646..d7de7b6 100644 --- a/fileformats/core/type_aliases.py +++ b/fileformats/core/typing.py @@ -1,6 +1,11 @@ import typing as ty +import sys from pathlib import Path -from typing_extensions import TypeAlias + +if sys.version_info[:2] < (3, 11): + from typing_extensions import TypeAlias, Self +else: + from typing import TypeAlias, Self if ty.TYPE_CHECKING: import fileformats.core @@ -15,3 +20,6 @@ ] PathType: TypeAlias = ty.Union[str, Path] + + +__all__ = ["CryptoMethod", "FspathsInputType", "PathType", "TypeAlias", "Self"] diff --git a/fileformats/core/utils.py b/fileformats/core/utils.py index 537d6a2..98c7101 100644 --- a/fileformats/core/utils.py +++ b/fileformats/core/utils.py @@ -10,7 +10,7 @@ import logging import pkgutil from contextlib import contextmanager -from .type_aliases import FspathsInputType +from .typing import FspathsInputType import fileformats.core if ty.TYPE_CHECKING: diff --git a/fileformats/generic/directory.py b/fileformats/generic/directory.py index f107a65..b1a29fb 100644 --- a/fileformats/generic/directory.py +++ b/fileformats/generic/directory.py @@ -5,7 +5,7 @@ from .fsobject import FsObject from fileformats.core.fileset import FileSet, FILE_CHUNK_LEN_DEFAULT from fileformats.core.mixin import WithClassifiers -from fileformats.core.type_aliases import CryptoMethod +from fileformats.core.typing import CryptoMethod class Directory(FsObject): diff --git a/fileformats/generic/file.py b/fileformats/generic/file.py index 16fd87e..22e5b6e 100644 --- a/fileformats/generic/file.py +++ b/fileformats/generic/file.py @@ -125,7 +125,7 @@ def actual_ext(self) -> str: "(i.e. matches the None extension)" ) # Return the longest matching extension, useful for optional extensions - return sorted(matching, key=len)[-1] + return sorted(matching, key=len)[-1] # type: ignore[no-any-return] @property def stem(self) -> str: diff --git a/fileformats/image/raster.py b/fileformats/image/raster.py index 295691f..46e998a 100644 --- a/fileformats/image/raster.py +++ b/fileformats/image/raster.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing_extensions import Self, TypeAlias +from fileformats.core.typing import Self, TypeAlias import typing as ty from fileformats.core.mixin import WithMagicNumber from fileformats.core import extra