Skip to content

Commit

Permalink
fix: Python Version check upon importing some types
Browse files Browse the repository at this point in the history
Import from python proper instead of typing_extensions when PEPs are accepted, depending on the python version
  • Loading branch information
abelcheung committed Mar 25, 2024
1 parent 299185b commit 9eb1d9e
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 33 deletions.
7 changes: 6 additions & 1 deletion lxml-stubs/_types.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from _typeshed import SupportsRead, SupportsWrite, _KT_co, _VT_co
from os import PathLike
from typing import (
Expand All @@ -10,7 +11,11 @@ from typing import (
Protocol,
TypeVar,
)
from typing_extensions import TypeAlias

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from .etree import QName, _Element, _ElementTree

Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/etree/_docloader.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import sys
from _typeshed import SupportsRead
from abc import ABCMeta, abstractmethod
from typing import Any, final, type_check_only
from typing_extensions import Self

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from .._types import _AnyStr

Expand Down
25 changes: 19 additions & 6 deletions lxml-stubs/etree/_element.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import sys
from _typeshed import _T
from typing import Any, Generic, Iterable, Iterator, Literal, Mapping, overload
from typing_extensions import Never, Self, deprecated

if sys.version_info >= (3, 11):
from typing import Never, Self
else:
from typing_extensions import Never, Self

if sys.version_info >= (3, 13):
from typing import deprecated
else:
from typing_extensions import deprecated

from .. import _types as _t
from ..cssselect import _CSSTransArg
Expand Down Expand Up @@ -318,8 +328,9 @@ class _ElementTree(Generic[_t._ET_co]):
self,
_xslt: _t._ElementOrTree,
/,
extensions: _t.SupportsLaxedItems[tuple[_t._AnyStr, _t._AnyStr], XSLTExtension]
| None = ...,
extensions: (
_t.SupportsLaxedItems[tuple[_t._AnyStr, _t._AnyStr], XSLTExtension] | None
) = ...,
access_control: XSLTAccessControl | None = ...,
*, # all keywords are passed to XSLT.__call__
profile_run: bool = ...,
Expand Down Expand Up @@ -354,9 +365,11 @@ class _Attrib:
# explicitly checks for dict and _Attrib
def update(
self,
sequence_or_dict: _Attrib
| dict[Any, Any] # Compromise with MutableMapping key/val invariance
| Iterable[tuple[_t._AttrName, _t._AttrVal]],
sequence_or_dict: (
_Attrib
| dict[Any, Any] # Compromise with MutableMapping key/val invariance
| Iterable[tuple[_t._AttrName, _t._AttrVal]]
),
) -> None: ...
# Signature is pop(self, key, *default), yet followed by runtime
# check and raise exception if multiple default argument is supplied
Expand Down
12 changes: 11 additions & 1 deletion lxml-stubs/etree/_iterparse.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import sys
from _typeshed import SupportsRead, _T_co
from typing import IO, Iterable, Iterator, Literal, overload
from typing_extensions import LiteralString, TypeAlias

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 11):
from typing import LiteralString
else:
from typing_extensions import LiteralString

from .._types import (
SupportsLaxedItems,
Expand Down
12 changes: 11 additions & 1 deletion lxml-stubs/etree/_module_func.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import sys
from typing import Any, Iterable, Literal, final, overload
from typing_extensions import TypeGuard, deprecated

if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard

if sys.version_info >= (3, 13):
from typing import deprecated
else:
from typing_extensions import deprecated

from .._types import (
_ET,
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/etree/_module_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
# lxml.etree helper classes, exceptions and constants
#

import sys
from abc import ABCMeta, abstractmethod
from typing import overload
from typing_extensions import LiteralString

if sys.version_info >= (3, 11):
from typing import LiteralString
else:
from typing_extensions import LiteralString

from .._types import _AnyStr, _ElementOrTree, _TagName
from ._dtd import DTD
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/etree/_nsclasses.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from _typeshed import _KT, _T, _VT
from typing import (
Any,
Expand All @@ -9,7 +10,11 @@ from typing import (
final,
overload,
)
from typing_extensions import ParamSpec

if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec

from .._types import SupportsLaxedItems
from ._classlookup import ElementBase, ElementClassLookup, FallbackElementClassLookup
Expand Down
13 changes: 12 additions & 1 deletion lxml-stubs/etree/_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import sys
from _typeshed import _T
from typing import Any, Generic, Iterable, Iterator
from typing_extensions import LiteralString, Self, deprecated

if sys.version_info >= (3, 11):
from typing import LiteralString, Self
else:
from typing_extensions import LiteralString, Self

if sys.version_info >= (3, 13):
from typing import deprecated
else:
from typing_extensions import deprecated

from .._types import (
SupportsLaxedItems,
Expand Down Expand Up @@ -84,6 +94,7 @@ class _FeedParser(Generic[_ET_co]):
```
"""
...

@deprecated(
"Removed since 5.0; deprecated since v2.0 (2008); renamed to set_element_class_lookup()"
)
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/etree/_xmlid.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys
from typing import Collection, Generic, Iterator, overload
from typing_extensions import Self

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from .._types import _ET, _AnyStr, _FileReadSource
from ._element import _Element, _ElementTree
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/etree/_xpath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# etree/_extension.pxi are merged here.
#

import sys
from abc import abstractmethod
from typing import Any, Callable, Generic, Mapping, Protocol, final, overload
from typing_extensions import deprecated

if sys.version_info >= (3, 13):
from typing import deprecated
else:
from typing_extensions import deprecated

from .._types import (
_ET,
Expand Down
22 changes: 18 additions & 4 deletions lxml-stubs/etree/_xslt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
#

import abc
from typing import Any, ClassVar, Literal, final, overload
from typing_extensions import TypeAlias, TypedDict, deprecated
import sys
from typing import Any, ClassVar, Literal, TypedDict, final, overload

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 13):
from typing import deprecated
else:
from typing_extensions import deprecated

from .._types import SupportsLaxedItems, _AnyStr, _ElementOrTree, _FileWriteSource
from ._classlookup import PIBase
Expand Down Expand Up @@ -46,6 +56,7 @@ class _XSLTResultTree(_ElementTree[_Element]):
As opposed to the generic ``.write()`` method, ``.write_output()`` serialises
the result as defined by the ``<xsl:output>`` tag.
"""

@property
def xslt_profile(self) -> _ElementTree[_Element] | None:
"""Return an ElementTree with profiling data for the stylesheet run"""
Expand Down Expand Up @@ -128,8 +139,9 @@ class XSLT:
def __init__(
self,
xslt_input: _ElementOrTree,
extensions: SupportsLaxedItems[tuple[_AnyStr, _AnyStr], XSLTExtension]
| None = ...,
extensions: (
SupportsLaxedItems[tuple[_AnyStr, _AnyStr], XSLTExtension] | None
) = ...,
regexp: bool = ...,
access_control: XSLTAccessControl | None = ...,
) -> None: ...
Expand Down Expand Up @@ -197,6 +209,7 @@ class XSLTExtension(metaclass=abc.ABCMeta):
is no parent element in the current context (e.g. no content
was added to the output tree yet).
"""

@overload
def apply_templates(
self,
Expand Down Expand Up @@ -247,6 +260,7 @@ class XSLTExtension(metaclass=abc.ABCMeta):
Note that the string discarding options will be ignored in this
case.
"""

@overload
def process_children(
self,
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/html/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from typing_extensions import LiteralString
import sys

if sys.version_info >= (3, 11):
from typing import LiteralString
else:
from typing_extensions import LiteralString

from ._element import (
Classes as Classes,
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/html/_element.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
from _typeshed import _T
from typing import Callable, Iterable, Iterator, Literal, MutableSet, overload
from typing_extensions import Self

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from .. import etree
from .._types import (
Expand Down
12 changes: 11 additions & 1 deletion lxml-stubs/html/_form.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import (
Any,
Callable,
Expand All @@ -7,7 +8,16 @@ from typing import (
MutableMapping,
MutableSet,
)
from typing_extensions import Never, TypeAlias

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 11):
from typing import Never
else:
from typing_extensions import Never

from .._types import SupportsLaxedItems, _AnyStr
from ._element import HtmlElement
Expand Down
11 changes: 8 additions & 3 deletions lxml-stubs/html/_funcs.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import sys
from typing import AnyStr, Callable, Iterator, Literal, TypeVar, overload
from typing_extensions import TypeAlias

from .. import etree
if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from .._types import _AnyStr, _OutputMethodArg
from ..etree import _ElementTree
from ._element import _HANDLE_FAILURES, HtmlElement

_HtmlDoc_T = TypeVar("_HtmlDoc_T", str, bytes, HtmlElement)
_HtmlElemOrTree: TypeAlias = HtmlElement | etree._ElementTree[HtmlElement]
_HtmlElemOrTree: TypeAlias = HtmlElement | _ElementTree[HtmlElement]

# These are HtmlMixin methods converted to standard functions,
# with element or HTML string as first argument followed by all
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/html/_parse.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys
from typing import Any, Iterable, MutableMapping
from typing_extensions import TypeAlias

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from .. import etree
from .._types import Unused, _AnyStr, _ElemClsLookupArg, _FileReadSource
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/html/clean.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys
from typing import Iterable, Pattern, TypeVar, Union, overload
from typing_extensions import TypeAlias

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from .._types import Unused, _ElemFactory
from ..etree import _Element, _ElementTree
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/isoschematron.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys
from typing import Any, ClassVar, overload
from typing_extensions import LiteralString

if sys.version_info >= (3, 11):
from typing import LiteralString
else:
from typing_extensions import LiteralString

from . import etree as _e
from ._types import _ElementOrTree, _FileReadSource
Expand Down
7 changes: 6 additions & 1 deletion lxml-stubs/objectify/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from typing_extensions import LiteralString
import sys

if sys.version_info >= (3, 11):
from typing import LiteralString
else:
from typing_extensions import LiteralString

from ._annotate import (
PyType as PyType,
Expand Down
Loading

0 comments on commit 9eb1d9e

Please sign in to comment.