11from __future__ import annotations
22
3- import re
43from abc import ABCMeta , abstractmethod
5- from typing import TYPE_CHECKING , Any , Generic , TypeAlias , TypeVar
4+ from typing import TYPE_CHECKING , Any , Generic , TypeVar
65
7- from typing_extensions import assert_never , override
6+ from typing_extensions import override
87
98from usethis ._config import usethis_config
109from usethis .errors import UsethisError
1716
1817 from typing_extensions import Self
1918
19+ from usethis ._file .types_ import Key
20+
2021
2122DocumentT = TypeVar ("DocumentT" )
2223
@@ -29,7 +30,7 @@ class UnexpectedFileIOError(UsethisError, IOError):
2930 """Raised when an unexpected attempt is made to read or write the pyproject.toml file."""
3031
3132
32- class UsethisFileManager (Generic [DocumentT ], metaclass = ABCMeta ):
33+ class FileManager (Generic [DocumentT ], metaclass = ABCMeta ):
3334 """Manages file access with deferred writes using a context manager.
3435
3536 This class implements the Command Pattern, encapsulating file operations. It defers
@@ -53,7 +54,7 @@ def __init__(self) -> None:
5354
5455 @override
5556 def __eq__ (self , other : object ) -> bool :
56- if not isinstance (other , UsethisFileManager ):
57+ if not isinstance (other , FileManager ):
5758 return NotImplemented
5859
5960 return self .relative_path == other .relative_path
@@ -181,10 +182,7 @@ def unlock(self) -> None:
181182 self ._content_by_path .pop (self .path , None )
182183
183184
184- Key : TypeAlias = str | re .Pattern [str ]
185-
186-
187- class KeyValueFileManager (UsethisFileManager , Generic [DocumentT ], metaclass = ABCMeta ):
185+ class KeyValueFileManager (FileManager , Generic [DocumentT ], metaclass = ABCMeta ):
188186 """A manager for files which store (at least some) values in key-value mappings."""
189187
190188 @abstractmethod
@@ -225,30 +223,3 @@ def remove_from_list(
225223 ) -> None :
226224 """Remove values from a list in the configuration file."""
227225 raise NotImplementedError
228-
229-
230- def print_keys (keys : Sequence [Key ]) -> str :
231- r"""Convert a list of keys to a string.
232-
233- Args:
234- keys: A list of keys.
235-
236- Returns:
237- A string representation of the keys.
238-
239- Examples:
240- >>> print_keys(["tool", "ruff", "line-length"])
241- 'tool.ruff.line-length'
242- >>> print_keys([re.compile(r"importlinter:contracts:.*")])
243- '<REGEX("importlinter:contracts:.*")>'
244- """
245- components : list [str ] = []
246- for key in keys :
247- if isinstance (key , str ):
248- components .append (key )
249- elif isinstance (key , re .Pattern ):
250- components .append (f'<REGEX("{ key .pattern } ")>' )
251- else :
252- assert_never (key )
253-
254- return "." .join (components )
0 commit comments