Skip to content

Commit b5504c3

Browse files
committed
Split file extension to its own variable to allow it to be overridden (e.g. for nested code)
1 parent 5b6bab0 commit b5504c3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

formate/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,22 @@ class Reformatter:
255255
.. autosummary-widths:: 5/16
256256
"""
257257

258-
#: The filename being reformatted.
258+
#: The filename being reformatted, as a POSIX-style path.
259259
filename: str
260260

261-
#: The filename being reformatted, as a POSIX-style path.
261+
#: The filename being reformatted, as a :class:`~.PathPlus` object.
262262
file_to_format: PathPlus
263263

264+
#: The file extension of the file being reformatted.
265+
filetype: str
266+
264267
#: The ``formate`` configuration, parsed from a TOML file (or similar).
265268
config: FormateConfigDict
266269

267270
def __init__(self, filename: PathLike, config: FormateConfigDict):
268271
self.file_to_format = PathPlus(filename)
269272
self.filename = self.file_to_format.as_posix()
273+
self.filetype = self.file_to_format.suffix
270274
self.config = config
271275
self._unformatted_source = self.file_to_format.read_text()
272276
self._reformatted_source: Optional[str] = None
@@ -279,7 +283,7 @@ def run(self) -> bool:
279283
"""
280284

281285
hooks = parse_hooks(self.config)
282-
hooks = get_hooks_for_filetype(self.file_to_format.suffix, hooks)
286+
hooks = get_hooks_for_filetype(self.filetype, hooks)
283287
reformatted_source = StringList(call_hooks(hooks, self._unformatted_source, self.filename))
284288
reformatted_source.blankline(ensure_single=True)
285289

0 commit comments

Comments
 (0)