Skip to content

Commit b87b9e4

Browse files
committed
apply ruff check --fix
1 parent b3d37e0 commit b87b9e4

8 files changed

Lines changed: 16 additions & 9 deletions

File tree

deepmd/dpmodel/modifier/base_modifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
PluginVariant,
1313
make_plugin_registry,
1414
)
15+
from typing_extensions import Self
1516

1617

1718
def make_base_modifier() -> type[object]:
1819
class BaseModifier(ABC, PluginVariant, make_plugin_registry("modifier")):
1920
"""Base class for data modifier."""
2021

21-
def __new__(cls, *args: Any, **kwargs: Any) -> "BaseModifier":
22+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
2223
if cls is BaseModifier:
2324
cls = cls.get_class_by_type(kwargs["type"])
2425
return super().__new__(cls)

deepmd/infer/deep_eval.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from deepmd.utils.batch_size import (
2323
AutoBatchSize,
2424
)
25+
from typing_extensions import Self
2526

2627
if TYPE_CHECKING:
2728
import ase.neighborlist
@@ -91,7 +92,7 @@ def __init__(
9192

9293
def __new__(
9394
cls, model_file: str, *args: object, **kwargs: object
94-
) -> "DeepEvalBackend":
95+
) -> Self:
9596
if cls is DeepEvalBackend:
9697
backend = Backend.detect_backend_by_model(model_file)
9798
return super().__new__(backend().deep_eval)
@@ -384,7 +385,7 @@ class DeepEval(ABC):
384385
Keyword arguments.
385386
"""
386387

387-
def __new__(cls, model_file: str, *args: object, **kwargs: object) -> "DeepEval":
388+
def __new__(cls, model_file: str, *args: object, **kwargs: object) -> Self:
388389
if cls is DeepEval:
389390
deep_eval = DeepEvalBackend(
390391
model_file,

deepmd/pd/model/descriptor/descriptor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from deepmd.utils.plugin import (
3333
make_plugin_registry,
3434
)
35+
from typing_extensions import Self
3536

3637
log = logging.getLogger(__name__)
3738

@@ -44,7 +45,7 @@ class DescriptorBlock(paddle.nn.Layer, ABC, make_plugin_registry("DescriptorBloc
4445

4546
local_cluster = False
4647

47-
def __new__(cls, *args: Any, **kwargs: Any) -> "DescriptorBlock":
48+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
4849
if cls is DescriptorBlock:
4950
try:
5051
descrpt_type = kwargs["type"]

deepmd/pd/model/task/fitting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from deepmd.utils.path import (
4545
DPPath,
4646
)
47+
from typing_extensions import Self
4748

4849
dtype = env.GLOBAL_PD_FLOAT_PRECISION
4950
device = env.DEVICE
@@ -54,7 +55,7 @@
5455
class Fitting(paddle.nn.Layer, BaseFitting):
5556
# plugin moved to BaseFitting
5657

57-
def __new__(cls, *args: Any, **kwargs: Any) -> "Fitting":
58+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
5859
if cls is Fitting:
5960
return BaseFitting.__new__(BaseFitting, *args, **kwargs)
6061
return super().__new__(cls)

deepmd/pt/model/descriptor/descriptor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from deepmd.utils.plugin import (
3333
make_plugin_registry,
3434
)
35+
from typing_extensions import Self
3536

3637
log = logging.getLogger(__name__)
3738

@@ -44,7 +45,7 @@ class DescriptorBlock(torch.nn.Module, ABC, make_plugin_registry("DescriptorBloc
4445

4546
local_cluster = False
4647

47-
def __new__(cls, *args: Any, **kwargs: Any) -> "DescriptorBlock":
48+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
4849
if cls is DescriptorBlock:
4950
try:
5051
descrpt_type = kwargs["type"]

deepmd/pt/model/task/fitting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from deepmd.utils.path import (
4949
DPPath,
5050
)
51+
from typing_extensions import Self
5152

5253
dtype = env.GLOBAL_PT_FLOAT_PRECISION
5354
device = env.DEVICE
@@ -58,7 +59,7 @@
5859
class Fitting(torch.nn.Module, BaseFitting):
5960
# plugin moved to BaseFitting
6061

61-
def __new__(cls, *args: Any, **kwargs: Any) -> "Fitting":
62+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
6263
if cls is Fitting:
6364
return BaseFitting.__new__(BaseFitting, *args, **kwargs)
6465
return super().__new__(cls)

deepmd/utils/path.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from wcmatch.glob import (
2222
globfilter,
2323
)
24+
from typing_extensions import Self
2425

2526

2627
class DPPath(ABC):
@@ -34,7 +35,7 @@ class DPPath(ABC):
3435
mode, by default "r"
3536
"""
3637

37-
def __new__(cls, path: str, mode: str = "r") -> "DPPath":
38+
def __new__(cls, path: str, mode: str = "r") -> Self:
3839
if cls is DPPath:
3940
if os.path.isdir(path):
4041
return super().__new__(DPOSPath)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies = [
4545
'scipy',
4646
'pyyaml',
4747
'dargs >= 0.4.7',
48-
'typing_extensions; python_version < "3.8"',
48+
'typing_extensions>=4.0.0',
4949
'importlib_metadata>=1.4; python_version < "3.8"',
5050
'h5py',
5151
"h5py>=3.6.0,!=3.11.0; platform_system=='Linux' and platform_machine=='aarch64'",

0 commit comments

Comments
 (0)