Skip to content

Commit

Permalink
Add Pathlike as valid type for file arguments (GH-60)
Browse files Browse the repository at this point in the history
  • Loading branch information
janssenhenning authored Feb 28, 2022
1 parent e0a34bc commit 0b1659f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lxml-stubs/etree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This is *far* from complete, and the stubgen-generated ones crash mypy.
# Any use of `Any` below means I couldn't figure out the type.

from os import PathLike
from typing import (
IO,
Any,
Expand Down Expand Up @@ -79,6 +80,7 @@ _KnownEncodings = Literal[
"us-ascii",
]
_ElementOrTree = Union[_Element, _ElementTree]
_FileSource = Union[_AnyStr, IO[Any], PathLike[Any]]

class ElementChildIterator(Iterator["_Element"]):
def __iter__(self) -> "ElementChildIterator": ...
Expand Down Expand Up @@ -241,7 +243,7 @@ class _ElementTree:
) -> Iterable[_Element]: ...
def write(
self,
file: Union[_AnyStr, IO[Any]],
file: _FileSource,
encoding: _AnyStr = ...,
method: _AnyStr = ...,
pretty_print: bool = ...,
Expand All @@ -255,7 +257,7 @@ class _ElementTree:
) -> None: ...
def write_c14n(
self,
file: Union[_AnyStr, IO[Any]],
file: _FileSource,
with_comments: bool = ...,
compression: int = ...,
inclusive_ns_prefixes: Iterable[_AnyStr] = ...,
Expand Down Expand Up @@ -427,7 +429,7 @@ class XMLSchema(_Validator):
def __init__(
self,
etree: _ElementOrTree = ...,
file: Union[_AnyStr, IO[Any]] = ...,
file: _FileSource = ...,
) -> None: ...
def __call__(self, etree: _ElementOrTree) -> bool: ...

Expand Down Expand Up @@ -466,7 +468,7 @@ def SubElement(
) -> _Element: ...
def ElementTree(
element: _Element = ...,
file: Union[_AnyStr, IO[Any]] = ...,
file: _FileSource = ...,
parser: XMLParser = ...,
) -> _ElementTree: ...
def ProcessingInstruction(
Expand All @@ -491,7 +493,7 @@ def cleanup_namespaces(
keep_ns_prefixes: Optional[Iterable[_AnyStr]] = ...,
) -> None: ...
def parse(
source: Union[_AnyStr, IO[Any]], parser: XMLParser = ..., base_url: _AnyStr = ...
source: _FileSource, parser: XMLParser = ..., base_url: _AnyStr = ...
) -> _ElementTree: ...
def fromstring(
text: _AnyStr, parser: XMLParser = ..., *, base_url: _AnyStr = ...
Expand Down Expand Up @@ -562,9 +564,7 @@ class _Validator:
error_log = ... # type: _ErrorLog

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

class _XPathEvaluatorBase: ...
Expand Down

0 comments on commit 0b1659f

Please sign in to comment.