Skip to content

[python3.10] import Self from typing_extensions#1592

Merged
AlpinDale merged 1 commit into
mainfrom
py310-self
Nov 4, 2025
Merged

[python3.10] import Self from typing_extensions#1592
AlpinDale merged 1 commit into
mainfrom
py310-self

Conversation

@AlpinDale

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: AlpinDale <alpindale@gmail.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly updates the import for Self to use typing_extensions, ensuring compatibility with Python 3.10. My review includes a suggestion to use a conditional import. This is a common practice for handling version-specific features, making the code more robust and maintainable by using the native typing.Self on Python 3.11+ while retaining the fallback for older versions.

Comment on lines 1 to +6
import hashlib
from typing import Any, Literal, Self
from typing import Any, Literal

from pydantic import model_validator
from pydantic.dataclasses import dataclass
from typing_extensions import Self

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For better compatibility and future-proofing, it's recommended to use a conditional import for Self based on the Python version. This ensures that the native typing.Self is used on Python 3.11+ while falling back to typing_extensions on older versions. This avoids an unnecessary dependency on typing_extensions for this feature on newer Python versions and makes the code's intent clearer.

Suggested change
import hashlib
from typing import Any, Literal, Self
from typing import Any, Literal
from pydantic import model_validator
from pydantic.dataclasses import dataclass
from typing_extensions import Self
import hashlib
import sys
from typing import Any, Literal
from pydantic import model_validator
from pydantic.dataclasses import dataclass
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self

@AlpinDale AlpinDale merged commit 2c3b58c into main Nov 4, 2025
1 check passed
@AlpinDale AlpinDale deleted the py310-self branch November 4, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant