Skip to content

Commit a9822c4

Browse files
author
Худайбердыев Виктор Мамедович
committed
feat: Refactoring (PNLP-15749)
1 parent 1668a1c commit a9822c4

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

core/basic_models/actions/show_versions_action.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
from collections.abc import AsyncGenerator
33
from dataclasses import dataclass
44
from dataclasses import field
5-
from typing import Any
6-
from typing import NotRequired
7-
from typing import Self
8-
from typing import TypedDict
5+
from typing import Any, List, Dict, Optional
96

107
import core.logging.logger_constants as log_const
118
from core.basic_models.actions.basic_actions import Action
@@ -15,12 +12,7 @@
1512
from scenarios.user.user_model import User
1613

1714

18-
class _ServiceVersionMetadata(TypedDict):
19-
name: str
20-
pronounce_as: NotRequired[str]
21-
22-
23-
_VersionType = str | None
15+
_VersionType = Optional[str]
2416

2517

2618
@dataclass
@@ -29,7 +21,7 @@ class ServiceVersions:
2921
dp_static_version: _VersionType = field(metadata={"name": "Dialog Policy static"})
3022

3123
@classmethod
32-
def init_from_user(cls, user: User) -> Self:
24+
def init_from_user(cls, user: User) -> "ServiceVersions":
3325
return cls(
3426
dp_code_version=user.settings.version.code_version,
3527
dp_static_version=user.settings.version.static_version,
@@ -45,10 +37,10 @@ class ShowVersionsAction(Action):
4537
}
4638

4739
async def run(
48-
self,
49-
user: User,
50-
text_preprocessing_result: BaseTextPreprocessingResult,
51-
params: dict[str, Any] | None = None,
40+
self,
41+
user: User,
42+
text_preprocessing_result: BaseTextPreprocessingResult,
43+
params: Optional[Dict[str, Any]] = None,
5244
) -> AsyncGenerator[Command, None]:
5345
params = {**(params or {}), **user.parametrizer.collect(text_preprocessing_result)}
5446

@@ -74,7 +66,7 @@ async def run(
7466
)
7567

7668
@staticmethod
77-
def _get_items(versions: ServiceVersions) -> list[dict[str, dict[str, str]]]:
69+
def _get_items(versions: ServiceVersions) -> List[Dict[str, Dict[str, str]]]:
7870
parts = [
7971
f"**Dialog Policy**\nкод: {versions.dp_code_version}\nстатики: {versions.dp_static_version}\n\n",
8072
]
@@ -102,6 +94,6 @@ def _version_to_ssml(version: str) -> str:
10294
return "bad format"
10395
ssml_groups = [f'<say-as interpret-as="digits">{gr}</say-as>' for gr in match.groups()]
10496
return (
105-
'<say-as interpret-as="characters">D</say-as>-'
106-
+ f"{ssml_groups[0]}.{ssml_groups[1]}.{ssml_groups[2]}-{ssml_groups[3]}"
97+
'<say-as interpret-as="characters">D</say-as>-' +
98+
f"{ssml_groups[0]}.{ssml_groups[1]}.{ssml_groups[2]}-{ssml_groups[3]}"
10799
)

smart_kit/configs/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import os
55
from io import StringIO
6-
from typing import Any, Union, List, Self
6+
from typing import Any, Union, List, Optional
77

88
import yaml
99

@@ -18,7 +18,7 @@
1818

1919

2020
class DPVersion:
21-
def __init__(self, code_version: str | None, separate_static=False, static_version: str = None):
21+
def __init__(self, code_version: Optional[str], separate_static=False, static_version: Optional[str] = None):
2222
self.code_version = code_version
2323
self.separate_static = separate_static
2424
self.static_version = static_version
@@ -29,7 +29,7 @@ def __str__(self):
2929
return self.code_version or "UNKNOWN"
3030

3131
@classmethod
32-
def from_env_and_source(cls, source: DBAdapter) -> Self:
32+
def from_env_and_source(cls, source: DBAdapter) -> "DPVersion":
3333
code_version = os.getenv("VERSION", default=0)
3434
attrs = {"code_version": code_version}
3535
if isinstance(source, CephAdapter):
@@ -77,7 +77,7 @@ def init(self):
7777
if isinstance(repo, UpdatableFileRepository):
7878
repo.update_cooldown = update_time
7979

80-
def override_repositories(self, repositories: list):
80+
def override_repositories(self, repositories: List):
8181
"""
8282
Метод предназначен для переопределения репозиториев в дочерних классах.
8383
:param repositories: Список репозиториев родителя

smart_kit/utils/logger_writer/logger_formatter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def to_num(s):
1919

2020
TYPES = {
2121
"str": str,
22-
"dict": dict,
22+
"dict": Dict,
2323
"int": Number,
2424
"bool": bool,
2525
}
2626

2727
TYPE_CASTS = {
2828
"str": str,
29-
"dict": dict,
29+
"dict": Dict,
3030
"int": to_num,
3131
"bool": bool,
3232
}
@@ -43,7 +43,7 @@ class SmartKitJsonFormatter(jsonlogger.JsonFormatter):
4343
APPLICATION_NAME = "NA"
4444

4545
def __init__(self, *args, **kwargs):
46-
self.fields_type: dict = kwargs.pop("fields_type", None)
46+
self.fields_type: Dict = kwargs.pop("fields_type", None)
4747
super().__init__(*args, **kwargs)
4848

4949
def add_fields(self, log_record, record, message_dict):
@@ -61,7 +61,7 @@ def add_fields(self, log_record, record, message_dict):
6161
if isinstance(record.args, dict):
6262
log_record["args"] = self._check_fields(record.args)
6363

64-
def _check_fields(self, record_args: Dict[str, Any], types: Optional[Dict[str, dict]] = None):
64+
def _check_fields(self, record_args: Dict[str, Any], types: Optional[Dict[str, Dict]] = None):
6565
if types is None:
6666
types = self.fields_type
6767
if types is None:

0 commit comments

Comments
 (0)