Skip to content

Commit 0b1659f

Browse files
Add Pathlike as valid type for file arguments (GH-60)
1 parent e0a34bc commit 0b1659f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lxml-stubs/etree.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This is *far* from complete, and the stubgen-generated ones crash mypy.
33
# Any use of `Any` below means I couldn't figure out the type.
44

5+
from os import PathLike
56
from typing import (
67
IO,
78
Any,
@@ -79,6 +80,7 @@ _KnownEncodings = Literal[
7980
"us-ascii",
8081
]
8182
_ElementOrTree = Union[_Element, _ElementTree]
83+
_FileSource = Union[_AnyStr, IO[Any], PathLike[Any]]
8284

8385
class ElementChildIterator(Iterator["_Element"]):
8486
def __iter__(self) -> "ElementChildIterator": ...
@@ -241,7 +243,7 @@ class _ElementTree:
241243
) -> Iterable[_Element]: ...
242244
def write(
243245
self,
244-
file: Union[_AnyStr, IO[Any]],
246+
file: _FileSource,
245247
encoding: _AnyStr = ...,
246248
method: _AnyStr = ...,
247249
pretty_print: bool = ...,
@@ -255,7 +257,7 @@ class _ElementTree:
255257
) -> None: ...
256258
def write_c14n(
257259
self,
258-
file: Union[_AnyStr, IO[Any]],
260+
file: _FileSource,
259261
with_comments: bool = ...,
260262
compression: int = ...,
261263
inclusive_ns_prefixes: Iterable[_AnyStr] = ...,
@@ -427,7 +429,7 @@ class XMLSchema(_Validator):
427429
def __init__(
428430
self,
429431
etree: _ElementOrTree = ...,
430-
file: Union[_AnyStr, IO[Any]] = ...,
432+
file: _FileSource = ...,
431433
) -> None: ...
432434
def __call__(self, etree: _ElementOrTree) -> bool: ...
433435

@@ -466,7 +468,7 @@ def SubElement(
466468
) -> _Element: ...
467469
def ElementTree(
468470
element: _Element = ...,
469-
file: Union[_AnyStr, IO[Any]] = ...,
471+
file: _FileSource = ...,
470472
parser: XMLParser = ...,
471473
) -> _ElementTree: ...
472474
def ProcessingInstruction(
@@ -491,7 +493,7 @@ def cleanup_namespaces(
491493
keep_ns_prefixes: Optional[Iterable[_AnyStr]] = ...,
492494
) -> None: ...
493495
def parse(
494-
source: Union[_AnyStr, IO[Any]], parser: XMLParser = ..., base_url: _AnyStr = ...
496+
source: _FileSource, parser: XMLParser = ..., base_url: _AnyStr = ...
495497
) -> _ElementTree: ...
496498
def fromstring(
497499
text: _AnyStr, parser: XMLParser = ..., *, base_url: _AnyStr = ...
@@ -562,9 +564,7 @@ class _Validator:
562564
error_log = ... # type: _ErrorLog
563565

564566
class DTD(_Validator):
565-
def __init__(
566-
self, file: Union[_AnyStr, IO[Any]] = ..., *, external_id: Any = ...
567-
) -> None: ...
567+
def __init__(self, file: _FileSource = ..., *, external_id: Any = ...) -> None: ...
568568
def __call__(self, etree: _ElementOrTree) -> bool: ...
569569

570570
class _XPathEvaluatorBase: ...

0 commit comments

Comments
 (0)