Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
exclude: ^source/3rdparty
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.13
rev: v0.14.14
hooks:
- id: ruff
args: ["--fix"]
Expand Down
6 changes: 5 additions & 1 deletion deepmd/dpmodel/modifier/base_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Any,
)

from typing_extensions import (
Self,
)

from deepmd.utils.plugin import (
PluginVariant,
make_plugin_registry,
Expand All @@ -18,7 +22,7 @@ def make_base_modifier() -> type[object]:
class BaseModifier(ABC, PluginVariant, make_plugin_registry("modifier")):
"""Base class for data modifier."""

def __new__(cls, *args: Any, **kwargs: Any) -> "BaseModifier":
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is BaseModifier:
cls = cls.get_class_by_type(kwargs["type"])
return super().__new__(cls)
Expand Down
9 changes: 5 additions & 4 deletions deepmd/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
)

import numpy as np
from typing_extensions import (
Self,
)

from deepmd.backend.backend import (
Backend,
Expand Down Expand Up @@ -89,9 +92,7 @@ def __init__(
) -> None:
pass

def __new__(
cls, model_file: str, *args: object, **kwargs: object
) -> "DeepEvalBackend":
def __new__(cls, model_file: str, *args: object, **kwargs: object) -> Self:
if cls is DeepEvalBackend:
backend = Backend.detect_backend_by_model(model_file)
return super().__new__(backend().deep_eval)
Expand Down Expand Up @@ -384,7 +385,7 @@ class DeepEval(ABC):
Keyword arguments.
"""

def __new__(cls, model_file: str, *args: object, **kwargs: object) -> "DeepEval":
def __new__(cls, model_file: str, *args: object, **kwargs: object) -> Self:
if cls is DeepEval:
deep_eval = DeepEvalBackend(
model_file,
Expand Down
5 changes: 4 additions & 1 deletion deepmd/pd/model/descriptor/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
)

import paddle
from typing_extensions import (
Self,
)

from deepmd.pd.model.network.network import (
TypeEmbedNet,
Expand Down Expand Up @@ -44,7 +47,7 @@ class DescriptorBlock(paddle.nn.Layer, ABC, make_plugin_registry("DescriptorBloc

local_cluster = False

def __new__(cls, *args: Any, **kwargs: Any) -> "DescriptorBlock":
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is DescriptorBlock:
try:
descrpt_type = kwargs["type"]
Expand Down
5 changes: 4 additions & 1 deletion deepmd/pd/model/task/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import numpy as np
import paddle
from typing_extensions import (
Self,
)

from deepmd.dpmodel.utils.seed import (
child_seed,
Expand Down Expand Up @@ -54,7 +57,7 @@
class Fitting(paddle.nn.Layer, BaseFitting):
# plugin moved to BaseFitting

def __new__(cls, *args: Any, **kwargs: Any) -> "Fitting":
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is Fitting:
return BaseFitting.__new__(BaseFitting, *args, **kwargs)
return super().__new__(cls)
Expand Down
5 changes: 4 additions & 1 deletion deepmd/pt/model/descriptor/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
)

import torch
from typing_extensions import (
Self,
)

from deepmd.pt.model.network.network import (
TypeEmbedNet,
Expand Down Expand Up @@ -44,7 +47,7 @@ class DescriptorBlock(torch.nn.Module, ABC, make_plugin_registry("DescriptorBloc

local_cluster = False

def __new__(cls, *args: Any, **kwargs: Any) -> "DescriptorBlock":
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is DescriptorBlock:
try:
descrpt_type = kwargs["type"]
Expand Down
5 changes: 4 additions & 1 deletion deepmd/pt/model/task/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import numpy as np
import torch
from typing_extensions import (
Self,
)

from deepmd.dpmodel.utils.seed import (
child_seed,
Expand Down Expand Up @@ -58,7 +61,7 @@
class Fitting(torch.nn.Module, BaseFitting):
# plugin moved to BaseFitting

def __new__(cls, *args: Any, **kwargs: Any) -> "Fitting":
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is Fitting:
return BaseFitting.__new__(BaseFitting, *args, **kwargs)
return super().__new__(cls)
Expand Down
5 changes: 4 additions & 1 deletion deepmd/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import h5py
import numpy as np
from typing_extensions import (
Self,
)
from wcmatch.glob import (
globfilter,
)
Expand All @@ -34,7 +37,7 @@ class DPPath(ABC):
mode, by default "r"
"""

def __new__(cls, path: str, mode: str = "r") -> "DPPath":
def __new__(cls, path: str, mode: str = "r") -> Self:
if cls is DPPath:
if os.path.isdir(path):
return super().__new__(DPOSPath)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies = [
'scipy',
'pyyaml',
'dargs >= 0.4.7',
'typing_extensions; python_version < "3.8"',
'typing_extensions>=4.0.0',
'importlib_metadata>=1.4; python_version < "3.8"',
'h5py',
"h5py>=3.6.0,!=3.11.0; platform_system=='Linux' and platform_machine=='aarch64'",
Expand Down