Skip to content

Commit 1eb3805

Browse files
committed
fix self import for python3.10
1 parent 0483d02 commit 1eb3805

File tree

6 files changed

+250
-228
lines changed

6 files changed

+250
-228
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ dependencies = [
1616
"pyyaml>=6.0.2",
1717
# need to exclude 8.2.0, as it drops support for Python 3.10
1818
"sphinx>=8.0.0,<8.2.0",
19-
"sphinx-inline-tabs>=2023.4.21",
19+
"sphinx-inline-tabs>=2025",
2020
"termcolor>=3.2.0",
21+
# Python 3.10 does not have Self
22+
"typing_extensions>=4.6.0;python_version<'3.11'",
2123
]
2224
classifiers = [
2325
"Development Status :: 4 - Beta",

structured_tutorials/models/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""Base model classes."""
55

66
from pathlib import Path
7-
from typing import Annotated, Any, Self
7+
from typing import Annotated, Any
88

99
from pydantic import (
1010
BaseModel,
@@ -17,6 +17,8 @@
1717
)
1818
from pydantic.fields import FieldInfo
1919

20+
from structured_tutorials.typing import Self
21+
2022
# Type for commands to execute
2123
CommandType = str | tuple[str, ...]
2224

structured_tutorials/models/parts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import os
77
from pathlib import Path
8-
from typing import Annotated, Any, Literal, Self
8+
from typing import Annotated, Any, Literal
99

1010
from pydantic import BaseModel, ConfigDict, Discriminator, Field, NonNegativeInt, Tag, model_validator
1111

@@ -18,6 +18,7 @@
1818
template_field_title_generator,
1919
)
2020
from structured_tutorials.models.tests import TestCommandModel, TestOutputModel, TestPortModel
21+
from structured_tutorials.typing import Self
2122

2223

2324
def part_discriminator(value: Any) -> str | None:

structured_tutorials/models/tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"""Module containing main tutorial model and global configuration models."""
55

66
from pathlib import Path
7-
from typing import Annotated, Any, Self
7+
from typing import Annotated, Any
88

99
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag, field_validator, model_validator
1010
from pydantic_core.core_schema import ValidationInfo
1111
from yaml import safe_load
1212

1313
from structured_tutorials.models.base import default_tutorial_root_factory
1414
from structured_tutorials.models.parts import AlternativeModel, PartModels, PromptModel, part_discriminator
15+
from structured_tutorials.typing import Self
1516

1617

1718
class DocumentationConfigurationModel(BaseModel):

structured_tutorials/typing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 Mathias Ertl
2+
# Licensed under the MIT License. See LICENSE file for details.
3+
4+
"""Module that re-exports some type hints."""
5+
6+
try:
7+
from typing import Self
8+
except ImportError: # pragma: only py3.10
9+
from typing_extensions import Self
10+
11+
12+
__all__ = [
13+
"Self",
14+
]

0 commit comments

Comments
 (0)