Skip to content

Commit 7e56899

Browse files
author
Andrei Neagu
committed
pylint
1 parent 45c163c commit 7e56899

File tree

18 files changed

+111
-78
lines changed

18 files changed

+111
-78
lines changed

packages/models-library/src/models_library/projects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from datetime import datetime
66
from enum import Enum
7-
from typing import Any, Final, TypeAlias
7+
from typing import Annotated, Any, Final, TypeAlias
88
from uuid import UUID
99

1010
from models_library.basic_types import ConstrainedStr
@@ -77,7 +77,7 @@ class BaseProjectModel(BaseModel):
7777
last_change_date: datetime = Field(...)
7878

7979
# Pipeline of nodes (SEE projects_nodes.py)
80-
workbench: NodesDict = Field(..., description="Project's pipeline")
80+
workbench: Annotated[NodesDict, Field(..., description="Project's pipeline")]
8181

8282
# validators
8383
_empty_thumbnail_is_none = field_validator("thumbnail", mode="before")(

packages/models-library/src/models_library/projects_state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from enum import Enum, unique
6+
from typing import Annotated
67

78
from pydantic import (
89
BaseModel,
@@ -126,7 +127,7 @@ class ProjectRunningState(BaseModel):
126127

127128

128129
class ProjectState(BaseModel):
129-
locked: ProjectLocked = Field(..., description="The project lock state")
130+
locked: Annotated[ProjectLocked, Field(..., description="The project lock state")]
130131
state: ProjectRunningState = Field(..., description="The project running state")
131132

132133
model_config = ConfigDict(extra="forbid")

services/web/server/src/simcore_service_webserver/application_settings.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from functools import cached_property
3-
from typing import Any, Final
3+
from typing import Annotated, Any, Final
44

55
from aiohttp import web
66
from common_library.pydantic_fields_extension import is_nullable
@@ -114,11 +114,16 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
114114
WEBSERVER_CREDIT_COMPUTATION_ENABLED: bool = Field(
115115
default=False, description="Enables credit computation features."
116116
)
117-
WEBSERVER_LOGLEVEL: LogLevel = Field(
118-
default=LogLevel.WARNING.value,
119-
validation_alias=AliasChoices("WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
120-
# NOTE: suffix '_LOGLEVEL' is used overall
121-
)
117+
WEBSERVER_LOGLEVEL: Annotated[
118+
LogLevel,
119+
Field(
120+
default=LogLevel.WARNING.value,
121+
validation_alias=AliasChoices(
122+
"WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"
123+
),
124+
# NOTE: suffix '_LOGLEVEL' is used overall
125+
),
126+
]
122127
WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
123128
default=False,
124129
validation_alias=AliasChoices(
@@ -187,9 +192,13 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
187192
description="invitations plugin",
188193
)
189194

190-
WEBSERVER_LOGIN: LoginSettings | None = Field(
191-
json_schema_extra={"auto_default_from_env": True}, description="login plugin"
192-
)
195+
WEBSERVER_LOGIN: Annotated[
196+
LoginSettings | None,
197+
Field(
198+
json_schema_extra={"auto_default_from_env": True},
199+
description="login plugin",
200+
),
201+
]
193202

194203
WEBSERVER_PAYMENTS: PaymentsSettings | None = Field(
195204
json_schema_extra={"auto_default_from_env": True},
@@ -221,9 +230,13 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
221230
description="scicrunch plugin",
222231
json_schema_extra={"auto_default_from_env": True},
223232
)
224-
WEBSERVER_SESSION: SessionSettings = Field(
225-
description="session plugin", json_schema_extra={"auto_default_from_env": True}
226-
)
233+
WEBSERVER_SESSION: Annotated[
234+
SessionSettings,
235+
Field(
236+
description="session plugin",
237+
json_schema_extra={"auto_default_from_env": True},
238+
),
239+
]
227240

228241
WEBSERVER_STATICWEB: StaticWebserverModuleSettings | None = Field(
229242
description="static-webserver service plugin",

services/web/server/src/simcore_service_webserver/login/settings.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import timedelta
2-
from typing import Final, Literal
2+
from typing import Annotated, Final, Literal
33

44
from aiohttp import web
55
from pydantic import BaseModel, ValidationInfo, field_validator
@@ -21,11 +21,14 @@
2121

2222

2323
class LoginSettings(BaseCustomSettings):
24-
LOGIN_ACCOUNT_DELETION_RETENTION_DAYS: PositiveInt = Field(
25-
default=30,
26-
description="Retention time (in days) of all the data after a user has requested the deletion of their account"
27-
"NOTE: exposed to the front-end as `to_client_statics`",
28-
)
24+
LOGIN_ACCOUNT_DELETION_RETENTION_DAYS: Annotated[
25+
PositiveInt,
26+
Field(
27+
default=30,
28+
description="Retention time (in days) of all the data after a user has requested the deletion of their account"
29+
"NOTE: exposed to the front-end as `to_client_statics`",
30+
),
31+
]
2932

3033
LOGIN_REGISTRATION_CONFIRMATION_REQUIRED: bool = Field(
3134
default=True,
@@ -44,10 +47,13 @@ class LoginSettings(BaseCustomSettings):
4447
default=120, description="Expiration time for code [sec]"
4548
)
4649

47-
LOGIN_2FA_REQUIRED: bool = Field(
48-
default=False,
49-
description="If true, it enables two-factor authentication (2FA)",
50-
)
50+
LOGIN_2FA_REQUIRED: Annotated[
51+
bool,
52+
Field(
53+
default=False,
54+
description="If true, it enables two-factor authentication (2FA)",
55+
),
56+
]
5157

5258
LOGIN_PASSWORD_MIN_LENGTH: PositiveInt = Field(
5359
default=12,

services/web/server/src/simcore_service_webserver/products/_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Product(BaseModel):
5050

5151
name: ProductName = Field(pattern=PUBLIC_VARIABLE_NAME_RE, validate_default=True)
5252

53-
display_name: str = Field(..., description="Long display name")
53+
display_name: Annotated[str, Field(..., description="Long display name")]
5454
short_name: str | None = Field(
5555
None,
5656
pattern=re.compile(TWILIO_ALPHANUMERIC_SENDER_ID_RE),
@@ -135,7 +135,8 @@ def _validate_name(cls, v):
135135
return v
136136

137137
@field_serializer("issues", "vendor")
138-
def _preserve_snake_case(self, v: Any) -> Any:
138+
@staticmethod
139+
def _preserve_snake_case(v: Any) -> Any:
139140
return v
140141

141142
@property

services/web/server/src/simcore_service_webserver/projects/_crud_handlers_models.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
"""
66

7-
from typing import Any
7+
from typing import Annotated, Any
88

99
from models_library.basic_types import IDStr
1010
from models_library.folders import FolderID
@@ -181,11 +181,14 @@ class ProjectListFullSearchParams(PageQueryParameters):
181181
max_length=100,
182182
examples=["My Project"],
183183
)
184-
tag_ids: str | None = Field(
185-
default=None,
186-
description="Search by tag ID (multiple tag IDs may be provided separated by column)",
187-
examples=["1,3"],
188-
)
184+
tag_ids: Annotated[
185+
str | None,
186+
Field(
187+
default=None,
188+
description="Search by tag ID (multiple tag IDs may be provided separated by column)",
189+
examples=["1,3"],
190+
),
191+
]
189192

190193
_empty_is_none = field_validator("text", mode="before")(
191194
empty_str_to_none_pre_validator

services/web/server/src/simcore_service_webserver/scicrunch/_rest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616

1717
import logging
18-
from typing import Any
18+
from typing import Annotated, Any
1919

2020
from aiohttp import ClientSession
2121
from pydantic import BaseModel, Field, RootModel
@@ -41,7 +41,7 @@ class FieldItem(BaseModel):
4141

4242

4343
class ResourceView(BaseModel):
44-
resource_fields: list[FieldItem] = Field([], alias="fields")
44+
resource_fields: Annotated[list[FieldItem], Field([], alias="fields")]
4545
version: int
4646
curation_status: str
4747
last_curated_version: int
@@ -60,7 +60,8 @@ def _get_field(self, fieldname: str):
6060
for field in self.resource_fields:
6161
if field.field_name == fieldname:
6262
return field.value
63-
raise ValueError(f"Cannot file expected field {fieldname}")
63+
msg = f"Cannot file expected field {fieldname}"
64+
raise ValueError(msg)
6465

6566
def get_name(self):
6667
return str(self._get_field("Resource Name"))

services/web/server/src/simcore_service_webserver/session/settings.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Final
1+
from typing import Annotated, Final
22

33
from aiohttp import web
44
from pydantic import AliasChoices, PositiveInt, field_validator
@@ -17,15 +17,18 @@
1717

1818
class SessionSettings(BaseCustomSettings, MixinSessionSettings):
1919

20-
SESSION_SECRET_KEY: SecretStr = Field(
21-
...,
22-
description="Secret key to encrypt cookies. "
23-
'TIP: python3 -c "from cryptography.fernet import *; print(Fernet.generate_key())"',
24-
min_length=44,
25-
validation_alias=AliasChoices(
26-
"SESSION_SECRET_KEY", "WEBSERVER_SESSION_SECRET_KEY"
20+
SESSION_SECRET_KEY: Annotated[
21+
SecretStr,
22+
Field(
23+
...,
24+
description="Secret key to encrypt cookies. "
25+
'TIP: python3 -c "from cryptography.fernet import *; print(Fernet.generate_key())"',
26+
min_length=44,
27+
validation_alias=AliasChoices(
28+
"SESSION_SECRET_KEY", "WEBSERVER_SESSION_SECRET_KEY"
29+
),
2730
),
28-
)
31+
]
2932

3033
SESSION_ACCESS_TOKENS_EXPIRATION_INTERVAL_SECS: int = Field(
3134
30 * _MINUTE,
@@ -37,10 +40,13 @@ class SessionSettings(BaseCustomSettings, MixinSessionSettings):
3740
# - Defaults taken from https://github.com/aio-libs/aiohttp-session/blob/master/aiohttp_session/cookie_storage.py#L20-L26
3841
#
3942

40-
SESSION_COOKIE_MAX_AGE: PositiveInt | None = Field(
41-
default=None,
42-
description="Max-Age attribute. Maximum age for session data, int seconds or None for “session cookie” which last until you close your browser.",
43-
)
43+
SESSION_COOKIE_MAX_AGE: Annotated[
44+
PositiveInt | None,
45+
Field(
46+
default=None,
47+
description="Max-Age attribute. Maximum age for session data, int seconds or None for “session cookie” which last until you close your browser.",
48+
),
49+
]
4450
SESSION_COOKIE_SAMESITE: str | None = Field(
4551
default=None,
4652
description="SameSite attribute lets servers specify whether/when cookies are sent with cross-site requests",
@@ -54,10 +60,8 @@ class SessionSettings(BaseCustomSettings, MixinSessionSettings):
5460
default=True,
5561
description="This prevents JavaScript from accessing the session cookie",
5662
)
57-
58-
model_config = SettingsConfigDict(
59-
extra="allow"
60-
)
63+
64+
model_config = SettingsConfigDict(extra="allow")
6165

6266
@field_validator("SESSION_SECRET_KEY")
6367
@classmethod

services/web/server/src/simcore_service_webserver/studies_dispatcher/_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Annotated
2+
13
from aiopg.sa.result import RowProxy
24
from models_library.services import ServiceKey, ServiceVersion
35
from pydantic import BaseModel, Field, HttpUrl, PositiveInt, TypeAdapter
@@ -7,7 +9,7 @@ class ServiceInfo(BaseModel):
79
key: ServiceKey
810
version: ServiceVersion
911

10-
label: str = Field(..., description="Display name")
12+
label: Annotated[str, Field(..., description="Display name")]
1113

1214
thumbnail: HttpUrl = Field(
1315
default=TypeAdapter(HttpUrl).validate_python(

services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import secrets
1313
import string
1414
from contextlib import suppress
15-
from datetime import UTC, datetime
15+
from datetime import datetime
1616

1717
import redis.asyncio as aioredis
1818
from aiohttp import web

0 commit comments

Comments
 (0)