Skip to content

Commit 3cb969c

Browse files
chore: BI-0 fix & enforce UP006 check
1 parent 65494cb commit 3cb969c

File tree

301 files changed

+1239
-1703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

301 files changed

+1239
-1703
lines changed

lib/dl_api_client/dl_api_client/dsmaker/api/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import (
44
Any,
5-
Dict,
6-
List,
75
Optional,
86
)
97

@@ -22,7 +20,7 @@ class HttpApiResponse(ApiResponse):
2220
"""
2321

2422
_status_code: int = attr.ib(kw_only=True)
25-
_json: Dict[str, Any] = attr.ib(kw_only=True)
23+
_json: dict[str, Any] = attr.ib(kw_only=True)
2624

2725
@property
2826
def status_code(self) -> int:
@@ -37,11 +35,11 @@ def json(self) -> dict:
3735
return self._json
3836

3937
@property
40-
def response_errors(self) -> List[str]:
38+
def response_errors(self) -> list[str]:
4139
return self.extract_response_errors(self._json)
4240

4341
@classmethod
44-
def extract_response_errors(cls, response_json: Dict[str, Any]) -> List[str]:
42+
def extract_response_errors(cls, response_json: dict[str, Any]) -> list[str]:
4543
return []
4644

4745

lib/dl_api_client/dl_api_client/dsmaker/api/data_api.py

Lines changed: 98 additions & 100 deletions
Large diffs are not rendered by default.

lib/dl_api_client/dl_api_client/dsmaker/api/schemas/dataset.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import (
44
TYPE_CHECKING,
55
Any,
6-
Dict,
76
Mapping,
87
)
98

@@ -191,12 +190,12 @@ class ValueSchema(OneOfSchemaWithDumpLoadHooks):
191190
}
192191

193192
@pre_load(pass_many=False)
194-
def wrap_value_with_type(self, data: Any, **_: Any) -> Dict[str, Any]:
193+
def wrap_value_with_type(self, data: Any, **_: Any) -> dict[str, Any]:
195194
type = getattr(self, "context", {}).get(self.CONTEXT_KEY)
196195
return {"type": type, "value": data}
197196

198197
@post_dump(pass_many=False)
199-
def extract_value(self, data: Dict[str, Any], **_: Any) -> Any:
198+
def extract_value(self, data: dict[str, Any], **_: Any) -> Any:
200199
return data["value"]
201200

202201
def get_obj_type(self, obj: ParameterValue) -> str:
@@ -482,7 +481,7 @@ class DatasetContentInternalSchema(DefaultSchema[Dataset]):
482481
load_preview_by_default = ma_fields.Boolean(allow_none=True, dump_default=True, load_default=True)
483482

484483
@post_load
485-
def validate_rls2(self, item: Dict[str, Any], *args: Any, **kwargs: Any) -> Dict[str, Any]:
484+
def validate_rls2(self, item: dict[str, Any], *args: Any, **kwargs: Any) -> dict[str, Any]:
486485
for key, entries in item["rls2"].items():
487486
for entry in entries:
488487
if entry.pattern_type == RLSPatternType.value and entry.allowed_value is None:

lib/dl_api_client/dl_api_client/dsmaker/api/serialization_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from functools import singledispatchmethod
44
from typing import (
5-
List,
65
Union,
76
)
87

@@ -194,7 +193,7 @@ def dump_dataset(self, item: Dataset) -> dict:
194193
dataset_data = DatasetContentInternalSchema().dump(stripped_dataset)
195194
return {"dataset": dataset_data}
196195

197-
def generate_implicit_updates(self, dataset: Dataset) -> List[UpdateAction]:
196+
def generate_implicit_updates(self, dataset: Dataset) -> list[UpdateAction]:
198197
updates = []
199198
for dsrc in dataset.sources:
200199
if not dsrc.created_:
@@ -224,7 +223,7 @@ def _get_action_postfix(item: ApiProxyObject) -> str:
224223
ObligatoryFilter: "obligatory_filter",
225224
}[type(item)]
226225

227-
def dump_updates(self, updates: List[Union[UpdateAction, dict]] = None) -> List[dict]: # type: ignore # 2024-01-24 # TODO: Incompatible default for argument "updates" (default has type "None", argument has type "list[UpdateAction | dict[Any, Any]]") [assignment]
226+
def dump_updates(self, updates: list[Union[UpdateAction, dict]] = None) -> list[dict]: # type: ignore # 2024-01-24 # TODO: Incompatible default for argument "updates" (default has type "None", argument has type "list[UpdateAction | dict[Any, Any]]") [assignment]
228227
result = []
229228
for update in updates or ():
230229
if isinstance(update, UpdateAction):

lib/dl_api_client/dl_api_client/dsmaker/primitives.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
Any,
1111
ClassVar,
1212
Collection,
13-
Dict,
1413
Generator,
1514
Generic,
1615
List,
1716
Optional,
18-
Tuple,
1917
TypeVar,
2018
Union,
2119
)
@@ -116,9 +114,9 @@ class Container(Generic[_ITEM_TV]):
116114
"""
117115

118116
def __init__(self, data: Union[list, tuple, dict, "Container"] = None): # type: ignore # 2024-01-24 # TODO: Incompatible default for argument "data" (default has type "None", argument has type "list[Any] | tuple[Any, ...] | dict[Any, Any] | Container[Any]") [assignment]
119-
self._item_ids: List[str] = [] # order list of object IDs
120-
self._items: Dict[str, _ITEM_TV] = {} # objects by ID
121-
self._id_by_alias: Dict[str, str] = {} # alias -> ID
117+
self._item_ids: list[str] = [] # order list of object IDs
118+
self._items: dict[str, _ITEM_TV] = {} # objects by ID
119+
self._id_by_alias: dict[str, str] = {} # alias -> ID
122120

123121
if data:
124122
self.__iadd__(data)
@@ -162,7 +160,7 @@ def __getitem__(self, key: Union[str, int]) -> _ITEM_TV:
162160

163161
raise TypeError(f"Invalid key type for container: {type(key)}")
164162

165-
def items(self) -> Generator[Tuple[str, _ITEM_TV], None, None]:
163+
def items(self) -> Generator[tuple[str, _ITEM_TV], None, None]:
166164
"""Just like ``dict.items()`` - iterate over key-value tuples."""
167165
alias_by_id = {id: alias for alias, id in self._id_by_alias.items()}
168166
for id in self._item_ids:
@@ -261,7 +259,7 @@ def set_name(self, name: str) -> None:
261259
def join(
262260
self,
263261
other: "SourceAvatar",
264-
conditions: List["JoinCondition"] = None, # type: ignore # 2024-01-24 # TODO: Incompatible default for argument "conditions" (default has type "None", argument has type "list[JoinCondition]") [assignment]
262+
conditions: list["JoinCondition"] = None, # type: ignore # 2024-01-24 # TODO: Incompatible default for argument "conditions" (default has type "None", argument has type "list[JoinCondition]") [assignment]
265263
join_type: JoinType = JoinType.inner,
266264
) -> "AvatarRelation":
267265
return AvatarRelation(
@@ -479,7 +477,7 @@ class RangeParameterValueConstraint(BaseParameterValueConstraint):
479477
@attr.s
480478
class SetParameterValueConstraint(BaseParameterValueConstraint):
481479
type: ParameterValueConstraintType = ParameterValueConstraintType.set
482-
values: List[ParameterValue] = attr.ib(factory=list)
480+
values: list[ParameterValue] = attr.ib(factory=list)
483481

484482

485483
@attr.s
@@ -502,7 +500,7 @@ class RegexParameterValueConstraint(BaseParameterValueConstraint):
502500

503501
class CollectionParameterValueConstraint(BaseParameterValueConstraint):
504502
type: ParameterValueConstraintType = ParameterValueConstraintType.collection
505-
constraints: List[BaseParameterValueConstraint]
503+
constraints: list[BaseParameterValueConstraint]
506504

507505

508506
def _make_pivot_role_spec(
@@ -611,7 +609,7 @@ def as_req_legend_item(
611609
self,
612610
role: FieldRole = FieldRole.row,
613611
range_type: Optional[RangeType] = None,
614-
dimension_values: Optional[Dict[int, Any]] = None,
612+
dimension_values: Optional[dict[int, Any]] = None,
615613
tree_prefix: Optional[list] = None,
616614
tree_level: Optional[int] = None,
617615
legend_item_id: Optional[int] = None,
@@ -674,7 +672,7 @@ def for_block(self, block_id: int) -> WhereClause:
674672
@attr.s
675673
class ObligatoryFilter(ApiProxyObject):
676674
field_guid: str = attr.ib(default="")
677-
default_filters: List[WhereClause] = attr.ib(factory=list)
675+
default_filters: list[WhereClause] = attr.ib(factory=list)
678676
managed_by: ManagedBy = attr.ib(default=ManagedBy.user)
679677
valid: bool = attr.ib(default=True)
680678

@@ -708,7 +706,7 @@ class TemplateRoleSpec(DimensionRoleSpec): # noqa
708706
class TreeRoleSpec(DimensionRoleSpec):
709707
level: int = attr.ib(kw_only=True)
710708
prefix: str = attr.ib(kw_only=True)
711-
dimension_values: List[DimensionValueSpec] = attr.ib(kw_only=True, factory=list)
709+
dimension_values: list[DimensionValueSpec] = attr.ib(kw_only=True, factory=list)
712710

713711

714712
@attr.s
@@ -787,7 +785,7 @@ class DimensionValueSpec:
787785
class AfterBlockPlacement(BlockPlacement):
788786
type = QueryBlockPlacementType.after
789787

790-
dimension_values: Optional[List[DimensionValueSpec]] = attr.ib(default=None)
788+
dimension_values: Optional[list[DimensionValueSpec]] = attr.ib(default=None)
791789

792790

793791
@attr.s
@@ -914,12 +912,12 @@ class ComponentError:
914912
class ComponentErrorPack:
915913
id: str = attr.ib()
916914
type: ComponentType = attr.ib()
917-
errors: List[ComponentError] = attr.ib(factory=list)
915+
errors: list[ComponentError] = attr.ib(factory=list)
918916

919917

920918
@attr.s
921919
class ComponentErrorRegistry:
922-
items: List[ComponentErrorPack] = attr.ib(factory=list)
920+
items: list[ComponentErrorPack] = attr.ib(factory=list)
923921

924922
def get_pack(self, id: str) -> Optional[ComponentErrorPack]: # type: ignore # TODO: fix
925923
for item in self.items:
@@ -943,9 +941,9 @@ class Dataset(ApiProxyObject):
943941
result_schema: Container[ResultField] = attr.ib(factory=Container, converter=Container)
944942
result_schema_aux: ResultSchemaAux = attr.ib(factory=ResultSchemaAux)
945943
rls: dict = attr.ib(factory=dict)
946-
rls2: dict[str, List[RLSEntry]] = attr.ib(factory=dict)
944+
rls2: dict[str, list[RLSEntry]] = attr.ib(factory=dict)
947945
component_errors: ComponentErrorRegistry = attr.ib(factory=ComponentErrorRegistry)
948-
obligatory_filters: List[ObligatoryFilter] = attr.ib(default=attr.Factory(list))
946+
obligatory_filters: list[ObligatoryFilter] = attr.ib(default=attr.Factory(list))
949947

950948
def prepare(self) -> None:
951949
super().prepare()

lib/dl_api_commons/dl_api_commons/aio/middlewares/error_handling_outer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import logging
99
from typing import (
1010
Any,
11-
Dict,
1211
Optional,
13-
Tuple,
1412
)
1513

1614
from aiohttp import web
@@ -34,7 +32,7 @@ class ErrorLevel(enum.Enum):
3432
@attr.s(auto_attribs=True)
3533
class ErrorData:
3634
status_code: int
37-
response_body: Dict[str, Any]
35+
response_body: dict[str, Any]
3836
level: ErrorLevel = attr.ib(validator=[attr.validators.instance_of(ErrorLevel)])
3937
http_reason: Optional[str] = attr.ib(default=None)
4038

@@ -66,7 +64,7 @@ def _classify_error(self, err: Exception, request: web.Request) -> ErrorData:
6664

6765
def handle_error(
6866
self, err: Exception, request: web.Request, req_logging_ctx_ctrl: RequestLoggingContextController
69-
) -> Tuple[web.Response, ErrorData]:
67+
) -> tuple[web.Response, ErrorData]:
7068
if isinstance(err, CancelledError):
7169
LOGGER.warning("Client request was cancelled", exc_info=True)
7270
raise # noqa

lib/dl_api_commons/dl_api_commons/aio/middlewares/request_id.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
from typing import (
66
Optional,
7-
Type,
87
)
98

109
from aiohttp import web
@@ -40,7 +39,7 @@
4039
@attr.s
4140
class RequestId:
4241
header_name: str = attr.ib(default="X-Request-ID")
43-
dl_request_cls: Type[aiohttp_wrappers.DLRequestBase] = attr.ib(default=aiohttp_wrappers.DLRequestBase)
42+
dl_request_cls: type[aiohttp_wrappers.DLRequestBase] = attr.ib(default=aiohttp_wrappers.DLRequestBase)
4443
append_own_req_id: bool = attr.ib(default=False)
4544
app_prefix: Optional[str] = attr.ib(default=None)
4645
accept_logging_ctx: bool = attr.ib(default=False)

lib/dl_api_commons/dl_api_commons/aiohttp/aiohttp_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Awaitable,
1616
Callable,
1717
Optional,
18-
Type,
1918
)
2019

2120
import aiohttp
@@ -51,7 +50,7 @@ class PredefinedIntervalsRetrier(BaseRetrier):
5150
retry_intervals: tuple[float, ...] = attr.ib(default=(0.5, 1.0, 2.0))
5251
retry_codes: set[int] = attr.ib(default={408, 429, 500, 502, 503, 504})
5352
retry_methods: set[str] = attr.ib(default={"GET"})
54-
retry_exception_classes: tuple[Type[Exception]] = attr.ib(default=(aiohttp.ClientError,))
53+
retry_exception_classes: tuple[type[Exception]] = attr.ib(default=(aiohttp.ClientError,))
5554

5655
@retry_methods.validator
5756
def check_all_chars_upper(self, attribute: str, value: set[str]) -> None:
@@ -127,7 +126,7 @@ async def __aenter__(self) -> BIAioHTTPClient:
127126
return self
128127

129128
async def __aexit__(
130-
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
129+
self, exc_type: Optional[type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
131130
) -> None:
132131
await self.close()
133132

lib/dl_api_commons/dl_api_commons/aiohttp/aiohttp_wrappers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
Any,
99
Awaitable,
1010
Callable,
11-
FrozenSet,
1211
Generic,
1312
Literal,
1413
Optional,
15-
Type,
1614
TypeVar,
1715
Union,
1816
overload,
@@ -225,7 +223,7 @@ def get_single_json_header(self, header: DLHeaders) -> Union[bool, int, float, l
225223
) from e
226224

227225
@property
228-
def required_resources(self) -> FrozenSet[RequiredResource]:
226+
def required_resources(self) -> frozenset[RequiredResource]:
229227
handler = self.request.match_info.handler
230228

231229
if hasattr(handler, self.HANDLER_ATTR_NAME_REQUIRED_RESOURCES):
@@ -237,7 +235,7 @@ def required_resources(self) -> FrozenSet[RequiredResource]:
237235

238236
@classmethod
239237
def use_dl_request(
240-
cls: Type[_SELF_TYPE], coro: Callable[[_SELF_TYPE, Handler], Awaitable[web.StreamResponse]]
238+
cls: type[_SELF_TYPE], coro: Callable[[_SELF_TYPE, Handler], Awaitable[web.StreamResponse]]
241239
) -> Middleware:
242240
if not inspect.iscoroutinefunction(coro):
243241
raise ValueError("This decorator may only be applied to a coroutine")
@@ -274,7 +272,7 @@ async def wrapper(self: Any, request: web.Request, handler: Handler) -> web.Stre
274272

275273

276274
class DLRequestView(web.View, Generic[_DL_REQUEST_TV]):
277-
dl_request_cls: Type[_DL_REQUEST_TV] = DLRequestBase # type: ignore # 2024-01-30 # TODO: Incompatible types in assignment (expression has type "type[DLRequestBase]", variable has type "type[_DL_REQUEST_TV]") [assignment]
275+
dl_request_cls: type[_DL_REQUEST_TV] = DLRequestBase # type: ignore # 2024-01-30 # TODO: Incompatible types in assignment (expression has type "type[DLRequestBase]", variable has type "type[_DL_REQUEST_TV]") [assignment]
278276

279277
@property
280278
def dl_request(self) -> _DL_REQUEST_TV:

lib/dl_api_commons/dl_api_commons/base_models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import (
66
Any,
77
Optional,
8-
Type,
98
TypeVar,
109
Union,
1110
)
@@ -128,12 +127,12 @@ def normalize_headers_dict(headers: Union[CIMultiDict, dict, None]) -> CIMultiDi
128127
raise TypeError(f"Unexpected type of headers: {type(headers)}")
129128

130129
@classmethod
131-
def create_empty(cls: Type[_REQUEST_CONTEXT_INFO_TV]) -> _REQUEST_CONTEXT_INFO_TV:
130+
def create_empty(cls: type[_REQUEST_CONTEXT_INFO_TV]) -> _REQUEST_CONTEXT_INFO_TV:
132131
return cls()
133132

134133
@classmethod
135134
def create(
136-
cls: Type[_REQUEST_CONTEXT_INFO_TV],
135+
cls: type[_REQUEST_CONTEXT_INFO_TV],
137136
request_id: Optional[str],
138137
tenant: Optional[TenantDef],
139138
user_id: Optional[str],

0 commit comments

Comments
 (0)