2
2
# This is *far* from complete, and the stubgen-generated ones crash mypy.
3
3
# Any use of `Any` below means I couldn't figure out the type.
4
4
5
+ from os import PathLike
5
6
from typing import (
6
7
IO ,
7
8
Any ,
@@ -79,6 +80,7 @@ _KnownEncodings = Literal[
79
80
"us-ascii" ,
80
81
]
81
82
_ElementOrTree = Union [_Element , _ElementTree ]
83
+ _FileSource = Union [_AnyStr , IO [Any ], PathLike [Any ]]
82
84
83
85
class ElementChildIterator (Iterator ["_Element" ]):
84
86
def __iter__ (self ) -> "ElementChildIterator" : ...
@@ -241,7 +243,7 @@ class _ElementTree:
241
243
) -> Iterable [_Element ]: ...
242
244
def write (
243
245
self ,
244
- file : Union [ _AnyStr , IO [ Any ]] ,
246
+ file : _FileSource ,
245
247
encoding : _AnyStr = ...,
246
248
method : _AnyStr = ...,
247
249
pretty_print : bool = ...,
@@ -255,7 +257,7 @@ class _ElementTree:
255
257
) -> None : ...
256
258
def write_c14n (
257
259
self ,
258
- file : Union [ _AnyStr , IO [ Any ]] ,
260
+ file : _FileSource ,
259
261
with_comments : bool = ...,
260
262
compression : int = ...,
261
263
inclusive_ns_prefixes : Iterable [_AnyStr ] = ...,
@@ -427,7 +429,7 @@ class XMLSchema(_Validator):
427
429
def __init__ (
428
430
self ,
429
431
etree : _ElementOrTree = ...,
430
- file : Union [ _AnyStr , IO [ Any ]] = ...,
432
+ file : _FileSource = ...,
431
433
) -> None : ...
432
434
def __call__ (self , etree : _ElementOrTree ) -> bool : ...
433
435
@@ -466,7 +468,7 @@ def SubElement(
466
468
) -> _Element : ...
467
469
def ElementTree (
468
470
element : _Element = ...,
469
- file : Union [ _AnyStr , IO [ Any ]] = ...,
471
+ file : _FileSource = ...,
470
472
parser : XMLParser = ...,
471
473
) -> _ElementTree : ...
472
474
def ProcessingInstruction (
@@ -491,7 +493,7 @@ def cleanup_namespaces(
491
493
keep_ns_prefixes : Optional [Iterable [_AnyStr ]] = ...,
492
494
) -> None : ...
493
495
def parse (
494
- source : Union [ _AnyStr , IO [ Any ]] , parser : XMLParser = ..., base_url : _AnyStr = ...
496
+ source : _FileSource , parser : XMLParser = ..., base_url : _AnyStr = ...
495
497
) -> _ElementTree : ...
496
498
def fromstring (
497
499
text : _AnyStr , parser : XMLParser = ..., * , base_url : _AnyStr = ...
@@ -562,9 +564,7 @@ class _Validator:
562
564
error_log = ... # type: _ErrorLog
563
565
564
566
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 : ...
568
568
def __call__ (self , etree : _ElementOrTree ) -> bool : ...
569
569
570
570
class _XPathEvaluatorBase : ...
0 commit comments