[python3.10] import Self from typing_extensions#1592
Conversation
Signed-off-by: AlpinDale <alpindale@gmail.com>
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
No description provided.