From d96e75924b4a53b85362a8822d0c419974b1741c Mon Sep 17 00:00:00 2001 From: Per Fagrell Date: Wed, 25 Oct 2023 20:03:17 +0200 Subject: [PATCH] Fix: Support changed pathlib in Python 3.12 (#221) --- pycln/utils/refactor.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pycln/utils/refactor.py b/pycln/utils/refactor.py index c42ef53..d5dc337 100644 --- a/pycln/utils/refactor.py +++ b/pycln/utils/refactor.py @@ -1,8 +1,8 @@ """Pycln code refactoring utility.""" import ast import os +import sys from importlib import import_module -from pathlib import Path, _posix_flavour, _windows_flavour # type: ignore from typing import Iterable, List, Optional, Set, Tuple, Union, cast from .. import ISWIN @@ -20,6 +20,13 @@ from .config import Config from .report import Report +if sys.version_info >= (3, 12): + from pathlib import Path + _flavour = os.path +else: + from pathlib import Path, _posix_flavour, _windows_flavour # type: ignore + _flavour = _windows_flavour if ISWIN else _posix_flavour + # Constants. NOPYCLN = "nopycln" CHANGE_MARK = "\n_CHANGED_" @@ -28,13 +35,13 @@ class PyPath(Path): - """Path subclass that has `is_stub` property.""" - - _flavour = _windows_flavour if ISWIN else _posix_flavour - + _flavour = _flavour def __init__(self, *args) -> None: # pylint: disable=unused-argument - super().__init__() # Path.__init__ does not take any args. + if sys.version_info >= (3, 12): + super().__init__(*args) + else: + super().__init__() # Path.__init__ does not take any args. self._is_stub = regexu.is_stub_file(self) @property @@ -50,7 +57,6 @@ class LazyLibCSTLoader: THIS CLASS DOES NOT INCLUDED ON THE TESTS SUITE. SO DON'T MODIFY IT FOR ANY REASON! """ - def __init__(self): self._module = None