88import stat
99import sys
1010import warnings
11+ from collections .abc import Iterable
1112from dataclasses import dataclass
1213from pathlib import Path
1314from typing import (
1415 TYPE_CHECKING ,
1516 Any ,
1617 Callable ,
17- Dict ,
1818 Generic ,
19- Iterable ,
20- List ,
2119 Literal ,
2220 Optional ,
23- Tuple ,
24- Type ,
2521 TypeVar ,
2622 Union ,
2723 cast ,
@@ -89,7 +85,7 @@ def get_logger() -> logging.Logger:
8985 return make_logger (__name__ )
9086
9187
92- BACKENDS : Dict [Backend , Type [AbstractBackend ]] = {
88+ BACKENDS : dict [Backend , type [AbstractBackend ]] = {
9389 'file' : FileBackend ,
9490 'sqlite' : SqliteBackend ,
9591}
@@ -130,7 +126,7 @@ def mtime_hash(path: Path, *args, **kwargs) -> SourceHash:
130126
131127Failure = str
132128Kind = Literal ['single' , 'multiple' ]
133- Inferred = Tuple [Kind , Type [Any ]]
129+ Inferred = tuple [Kind , type [Any ]]
134130
135131
136132def infer_return_type (func ) -> Union [Failure , Inferred ]:
@@ -299,7 +295,7 @@ def cachew_impl(
299295 cache_path : Optional [PathProvider [P ]] = use_default_path ,
300296 * ,
301297 force_file : bool = False ,
302- cls : Optional [Union [Type , Tuple [Kind , Type ]]] = None ,
298+ cls : Optional [Union [type , tuple [Kind , type ]]] = None ,
303299 depends_on : HashFunction [P ] = default_hash ,
304300 logger : Optional [logging .Logger ] = None ,
305301 chunk_by : int = 100 ,
@@ -387,7 +383,7 @@ def process(self, msg, kwargs):
387383 logger .debug (f'no cache_path specified, using the default { cache_path } ' )
388384
389385 use_kind : Optional [Kind ] = None
390- use_cls : Optional [Type ] = None
386+ use_cls : Optional [type ] = None
391387 if cls is not None :
392388 # defensive here since typing. objects passed as cls might fail on isinstance
393389 try :
@@ -475,7 +471,7 @@ def cachew(
475471 cache_path : Optional [PathProvider [P ]] = ...,
476472 * ,
477473 force_file : bool = ...,
478- cls : Optional [Union [Type , Tuple [Kind , Type ]]] = ...,
474+ cls : Optional [Union [type , tuple [Kind , type ]]] = ...,
479475 depends_on : HashFunction [P ] = ...,
480476 logger : Optional [logging .Logger ] = ...,
481477 chunk_by : int = ...,
@@ -498,7 +494,7 @@ def callable_module_name(func: Callable) -> Optional[str]:
498494
499495
500496# could cache this, but might be worth not to, so the user can change it on the fly?
501- def _parse_disabled_modules (logger : Optional [logging .Logger ] = None ) -> List [str ]:
497+ def _parse_disabled_modules (logger : Optional [logging .Logger ] = None ) -> list [str ]:
502498 # e.g. CACHEW_DISABLE=my.browser:my.reddit
503499 if 'CACHEW_DISABLE' not in os .environ :
504500 return []
@@ -582,14 +578,14 @@ class Context(Generic[P]):
582578 func : Callable
583579 cache_path : PathProvider [P ]
584580 force_file : bool
585- cls_ : Type
581+ cls_ : type
586582 depends_on : HashFunction [P ]
587583 logger : logging .Logger
588584 chunk_by : int
589585 synthetic_key : Optional [str ]
590586 backend : Optional [Backend ]
591587
592- def composite_hash (self , * args , ** kwargs ) -> Dict [str , Any ]:
588+ def composite_hash (self , * args , ** kwargs ) -> dict [str , Any ]:
593589 fsig = inspect .signature (self .func )
594590 # defaults wouldn't be passed in kwargs, but they can be an implicit dependency (especially inbetween program runs)
595591 defaults = {
@@ -693,7 +689,7 @@ def try_use_synthetic_key() -> None:
693689 return
694690 # attempt to use existing cache if possible, as a 'prefix'
695691
696- old_hash_d : Dict [str , Any ] = {}
692+ old_hash_d : dict [str , Any ] = {}
697693 if old_hash is not None :
698694 try :
699695 old_hash_d = json .loads (old_hash )
@@ -711,7 +707,7 @@ def try_use_synthetic_key() -> None:
711707 if not cache_compatible :
712708 return
713709
714- def missing_keys (cached : List [str ], wanted : List [str ]) -> Optional [List [str ]]:
710+ def missing_keys (cached : list [str ], wanted : list [str ]) -> Optional [list [str ]]:
715711 # FIXME assert both cached and wanted are sorted? since we rely on it
716712 # if not, then the user could use some custom key for caching (e.g. normalise filenames etc)
717713 # although in this case passing it into the function wouldn't make sense?
@@ -734,8 +730,8 @@ def missing_keys(cached: List[str], wanted: List[str]) -> Optional[List[str]]:
734730 # otherwise too many things are cached, and we seem to wante less
735731 return None
736732
737- new_values : List [str ] = new_hash_d [_SYNTHETIC_KEY_VALUE ]
738- old_values : List [str ] = old_hash_d [_SYNTHETIC_KEY_VALUE ]
733+ new_values : list [str ] = new_hash_d [_SYNTHETIC_KEY_VALUE ]
734+ old_values : list [str ] = old_hash_d [_SYNTHETIC_KEY_VALUE ]
739735 missing = missing_keys (cached = old_values , wanted = new_values )
740736 if missing is not None :
741737 # can reuse cache
@@ -760,7 +756,7 @@ def written_to_cache():
760756
761757 flush_blobs = backend .flush_blobs
762758
763- chunk : List [Any ] = []
759+ chunk : list [Any ] = []
764760
765761 def flush () -> None :
766762 nonlocal chunk
@@ -849,9 +845,9 @@ def cached_items():
849845
850846
851847__all__ = [
852- 'cachew' ,
853848 'CachewException' ,
854- 'SourceHash' ,
855849 'HashFunction' ,
850+ 'SourceHash' ,
851+ 'cachew' ,
856852 'get_logger' ,
857853]
0 commit comments