From 5caa6324a95026219873fca5638cc07d1784bdf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleg=20H=C3=B6fling?= Date: Thu, 27 Oct 2022 09:18:12 +0200 Subject: [PATCH] fix: allow broader type for toml file path value (#243) * allow broader type for toml file path value Signed-off-by: oleg.hoefling * reuse strpath from typeshed Signed-off-by: oleg.hoefling Signed-off-by: oleg.hoefling --- tomlkit/toml_file.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tomlkit/toml_file.py b/tomlkit/toml_file.py index d05a62f1..74591308 100644 --- a/tomlkit/toml_file.py +++ b/tomlkit/toml_file.py @@ -1,10 +1,20 @@ import os import re +from typing import TYPE_CHECKING + from tomlkit.api import loads from tomlkit.toml_document import TOMLDocument +if TYPE_CHECKING: + from _typeshed import StrPath as _StrPath +else: + from typing import Union + + _StrPath = Union[str, os.PathLike] + + class TOMLFile: """ Represents a TOML file. @@ -12,7 +22,7 @@ class TOMLFile: :param path: path to the TOML file """ - def __init__(self, path: str) -> None: + def __init__(self, path: _StrPath) -> None: self._path = path self._linesep = os.linesep