Skip to content

Commit 6f86268

Browse files
committed
DOC: make documentation build work with Python 3.10
1 parent 695f0fa commit 6f86268

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

RELEASE_NOTES.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Python 3.10, and drops support for Python versions.
8383
class of two types
8484
- new function :func:`.get_common_generic_subclass` to retrieve the common generic
8585
subclass of two types
86-
- new function :func:`.get_generic_bases` to retrieve the generic base classes of a
87-
type
86+
- new function :func:`~pytools.typing.get_generic_bases` to retrieve the generic base
87+
classes of a type
8888
- new function :func:`.get_generic_instance` to retrieve the generic instance of a
8989
type
9090
- new function :func:`.get_type_arguments` to retrieve the type arguments of a generic
@@ -99,7 +99,7 @@ Python 3.10, and drops support for Python versions.
9999
- API: new class :class:`.HTMLStyle` for rendering HTML content with drawers
100100
- API: new function :func:`.is_running_in_notebook` to check if the code is running
101101
in a Jupyter or Colab notebook
102-
- API: new property :attr:`.hex` for :class:`.RgbColor` and :class:`.RgbaColor` to
102+
- API: new property :attr:`.RgbColor.hex` and :attr:`.RgbaColor.hex` to
103103
return the color as a hexadecimal string
104104

105105
- Various adjustments to maintain compatibility with recent Python versions

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ docs = [
5353
"jupyter == 1",
5454
"docutils ~= 0.17",
5555
"xlrd ~= 1.2",
56-
"m2r ~= 0.2"
56+
"m2r ~= 0.2",
57+
"mypy ~= 1.10",
5758
]
5859

5960
[tool.flit.metadata.urls]

src/pytools/api/_api.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import numpy as np
1212
import pandas as pd
13-
import typing_inspect
1413

1514
from ._alltracker import AllTracker
1615
from ._decorators import subsdoc
@@ -20,7 +19,6 @@
2019
__all__ = [
2120
"deprecated",
2221
"deprecation_warning",
23-
"get_generic_bases",
2422
"is_list_like",
2523
"as_collection",
2624
"as_list",
@@ -439,23 +437,6 @@ def _raise_type_mismatch(
439437
)
440438

441439

442-
def get_generic_bases(class_: type) -> tuple[type, ...]:
443-
"""
444-
Bugfix version of :func:`typing_inspect.get_generic_bases`.
445-
446-
Prevents getting the generic bases of the parent class if not defined for the given
447-
class.
448-
449-
:param class_: class to get the generic bases for
450-
:return: the generic base classes of the given class
451-
"""
452-
bases: tuple[type, ...] = typing_inspect.get_generic_bases(class_)
453-
if bases is typing_inspect.get_generic_bases(super(class_, class_)):
454-
return ()
455-
else:
456-
return bases
457-
458-
459440
#
460441
# Decorators
461442
#

src/pytools/sphinx/util/_util.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
from collections.abc import Callable, Generator, Iterable, Mapping
1515
from inspect import getattr_static
1616
from re import Pattern
17-
from types import FunctionType, MethodType, UnionType
17+
from types import FunctionType, GenericAlias, MethodType, UnionType
1818
from typing import Any, ForwardRef, Generic, TypeVar, Union, cast, get_type_hints
1919

2020
import typing_inspect
2121

2222
from ...api import (
2323
AllTracker,
24-
get_generic_bases,
2524
inheritdoc,
2625
public_module_prefix,
2726
subsdoc,
@@ -273,9 +272,10 @@ def _class_tag(
273272
def _typevar_name(self, cls: TypeVar) -> str:
274273
if isinstance(cls, TypeVar):
275274
args: list[str] = [
276-
self._class_name_with_generics(c) for c in cls.__constraints__
275+
self._class_name_with_generics(c)
276+
for c in getattr(cls, "__constraints__", ())
277277
]
278-
if cls.__bound__:
278+
if getattr(cls, "__bound__", None):
279279
args.append(f"bound= {self._class_name_with_generics(cls.__bound__)}")
280280
return f'{cls}({", ".join(args)})' if args else str(cls)
281281
else:
@@ -288,7 +288,7 @@ def _get_generics(self, child_class: type) -> list[str]:
288288
self._typevar_name(arg)
289289
for arg in typing_inspect.get_args(base, evaluate=True)
290290
)
291-
for base in get_generic_bases(child_class)
291+
for base in _get_generic_bases(child_class)
292292
if typing_inspect.get_origin(base) is Generic
293293
)
294294
)
@@ -640,7 +640,7 @@ def _inner(_subclass: type, _include_subclass: bool) -> Generator[type, None, No
640640
# get the base classes; try generic bases first then fall back to regular
641641
# bases
642642
base_classes: tuple[type, ...] = (
643-
get_generic_bases(_subclass) or _subclass.__bases__
643+
_get_generic_bases(_subclass) or _subclass.__bases__
644644
)
645645

646646
# include the _subclass itself in the list of bases, if requested
@@ -773,7 +773,7 @@ def _get_parameter_bindings(
773773

774774
superclass_bindings = {
775775
superclass: bindings
776-
for generic_superclass in get_generic_bases(cls)
776+
for generic_superclass in _get_generic_bases(cls)
777777
for superclass, bindings in (
778778
self._get_parameter_bindings(
779779
cls=generic_superclass, subclass_bindings=class_bindings
@@ -1287,3 +1287,22 @@ def _copy_generic_type_with_arguments(
12871287
new_arguments = (*new_arguments[0], *new_arguments[1:])
12881288

12891289
return copy_with(new_arguments)
1290+
1291+
1292+
def _get_generic_bases(class_: type) -> tuple[type, ...]:
1293+
"""
1294+
Bugfix version of :func:`typing_inspect.get_generic_bases`.
1295+
1296+
Prevents getting the generic bases of the parent class if not defined for the given
1297+
class.
1298+
1299+
:param class_: class to get the generic bases for
1300+
:return: the generic base classes of the given class
1301+
"""
1302+
bases: tuple[type, ...] = typing_inspect.get_generic_bases(class_)
1303+
if not isinstance(
1304+
class_, GenericAlias
1305+
) and bases is typing_inspect.get_generic_bases(super(class_, class_)):
1306+
return ()
1307+
else:
1308+
return bases

0 commit comments

Comments
 (0)