Skip to content

Commit eb92d49

Browse files
Lint fixes for PLR, PLW, PLC, PUI and TC errors (#312)
1 parent d76e480 commit eb92d49

File tree

16 files changed

+105
-86
lines changed

16 files changed

+105
-86
lines changed

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ astor = ">=0.8.1"
3333
shortuuid = ">=1.0.11"
3434
dacite = ">=1.8.1"
3535
deprecated = ">=1.2.14"
36+
python-dateutil = "^2.8.2"
3637

3738
[tool.poetry.group.dev.dependencies]
3839
pylint = ">=2.17.5"
@@ -120,6 +121,14 @@ ignore = [
120121
"W191",
121122
"E501",
122123
"B011",
124+
# too-many-arguments
125+
"PLR0913",
126+
# collapsible-else-if
127+
"PLR5501",
128+
# too-many-branches
129+
"PLR0912",
130+
# too-many-return-statements
131+
"PLR0911"
123132
]
124133

125134
[tool.ruff.lint.isort]

src/conductor/client/ai/orchestrator.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
from __future__ import annotations
22

3-
from typing import Optional, List
3+
from typing import Optional, List, TYPE_CHECKING
44
from uuid import uuid4
55

66
from typing_extensions import Self
77

8-
from conductor.client.ai.configuration import LLMProvider, VectorDB
9-
from conductor.client.ai.integrations import IntegrationConfig
10-
from conductor.client.configuration.configuration import Configuration
118
from conductor.client.http.models.integration_api_update import IntegrationApiUpdate
129
from conductor.client.http.models.integration_update import IntegrationUpdate
13-
from conductor.client.http.models.prompt_template import PromptTemplate
1410
from conductor.client.http.rest import ApiException
1511
from conductor.client.orkes_clients import OrkesClients
1612

13+
if TYPE_CHECKING:
14+
from conductor.client.http.models.prompt_template import PromptTemplate
15+
from conductor.client.configuration.configuration import Configuration
16+
from conductor.client.ai.integrations import IntegrationConfig
17+
from conductor.client.ai.configuration import LLMProvider, VectorDB
18+
19+
NOT_FOUND_STATUS = 404
1720

1821
class AIOrchestrator:
1922
def __init__(self, api_configuration: Configuration, prompt_test_workflow_name: str = '') -> Self:
@@ -36,7 +39,7 @@ def get_prompt_template(self, template_name: str) -> PromptTemplate:
3639
try:
3740
return self.prompt_client.get_prompt(template_name)
3841
except ApiException as e:
39-
if e.code == 404:
42+
if e.code == NOT_FOUND_STATUS:
4043
return None
4144
raise e
4245

@@ -93,7 +96,6 @@ def add_vector_store(self, db_integration_name: str, provider: VectorDB, indices
9396
existing_integration_api = self.integration_client.get_integration_api(db_integration_name, index)
9497
if existing_integration_api is None or overwrite:
9598
self.integration_client.save_integration_api(db_integration_name, index, api_details)
96-
pass
9799

98100
def get_token_used(self, ai_integration: str) -> dict:
99101
return self.integration_client.get_token_usage_for_integration_provider(ai_integration)

src/conductor/client/automator/task_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def __init__(
6666
elif not isinstance(workers, list):
6767
workers = [workers]
6868
if scan_for_annotated_workers is True:
69-
for (task_def_name, domain) in _decorated_functions:
70-
record = _decorated_functions[(task_def_name, domain)]
69+
for (task_def_name, domain), record in _decorated_functions.items():
7170
fn = record['func']
7271
worker_id = record['worker_id']
7372
poll_interval = record['poll_interval']

src/conductor/client/automator/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ def get_value(typ: type, val: object) -> object:
109109
if typ in simple_types:
110110
return val
111111
elif str(typ).startswith('typing.List[') or str(typ).startswith('typing.Set[') or str(typ).startswith('list['):
112-
values = []
113-
for item in val:
114-
converted = get_value(type(item), item)
115-
values.append(converted)
112+
values = [get_value(type(item), item) for item in val]
116113
return values
117114
elif str(typ).startswith('dict[') or str(typ).startswith(
118115
'typing.Dict[') or str(typ).startswith('requests.structures.CaseInsensitiveDict[') or typ is dict:

src/conductor/client/configuration/settings/metrics_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def __set_dir(self, dir: str) -> None:
3535
os.mkdir(dir)
3636
except Exception as e:
3737
logger.warning(
38-
'Failed to create metrics temporary folder, reason: ', e)
38+
'Failed to create metrics temporary folder, reason: %s', e)
3939
self.directory = dir

src/conductor/client/exceptions/api_exception_handler.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
from conductor.client.exceptions.api_error import APIError, APIErrorCode
44
from conductor.client.http.rest import ApiException
55

6+
BAD_REQUEST_STATUS = 400
7+
FORBIDDEN_STATUS = 403
8+
NOT_FOUND_STATUS = 404
9+
REQUEST_TIMEOUT_STATUS = 408
10+
CONFLICT_STATUS = 409
11+
612
STATUS_TO_MESSAGE_DEFAULT_MAPPING = {
7-
400: "Invalid request",
8-
403: "Access forbidden",
9-
404: "Resource not found",
10-
408: "Request timed out",
11-
409: "Resource exists already",
13+
BAD_REQUEST_STATUS: "Invalid request",
14+
FORBIDDEN_STATUS: "Access forbidden",
15+
NOT_FOUND_STATUS: "Resource not found",
16+
REQUEST_TIMEOUT_STATUS: "Request timed out",
17+
CONFLICT_STATUS: "Resource exists already",
1218
}
1319

1420

@@ -18,20 +24,20 @@ def inner_function(*args, **kwargs):
1824
return function(*args, **kwargs)
1925
except ApiException as e:
2026

21-
if e.status == 404:
27+
if e.status == NOT_FOUND_STATUS:
2228
code = APIErrorCode.NOT_FOUND
23-
elif e.status == 403:
29+
elif e.status == FORBIDDEN_STATUS:
2430
code = APIErrorCode.FORBIDDEN
25-
elif e.status == 409:
31+
elif e.status == CONFLICT_STATUS:
2632
code = APIErrorCode.CONFLICT
27-
elif e.status == 400:
33+
elif e.status == BAD_REQUEST_STATUS:
2834
code = APIErrorCode.BAD_REQUEST
29-
elif e.status == 408:
35+
elif e.status == REQUEST_TIMEOUT_STATUS:
3036
code = APIErrorCode.REQUEST_TIMEOUT
3137
else:
3238
code = APIErrorCode.UNKNOWN
3339

34-
message = STATUS_TO_MESSAGE_DEFAULT_MAPPING[e.status]
40+
message = STATUS_TO_MESSAGE_DEFAULT_MAPPING.get(e.status, "Unknown error")
3541

3642
try:
3743
if e.body:

src/conductor/client/helpers/helper.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import logging
33
import re
4+
from dateutil.parser import parse
45
from typing import Any, ClassVar, Dict, Tuple
56

67
import six
@@ -21,7 +22,7 @@ class ObjectMapper(object):
2122
PRIMITIVE_TYPES: ClassVar[Tuple[Any, ...]] = (float, bool, bytes, six.text_type, *six.integer_types)
2223
NATIVE_TYPES_MAPPING: ClassVar[Dict[str, Any]] = {
2324
'int': int,
24-
'long': int if six.PY3 else long, # noqa: F821, RUF100
25+
'long': int if six.PY3 else long, # noqa: F821, RUF100, YTT202
2526
'float': float,
2627
'str': str,
2728
'bool': bool,
@@ -31,39 +32,29 @@ class ObjectMapper(object):
3132
}
3233

3334
def to_json(self, obj):
34-
3535
if obj is None:
3636
return None
3737
elif isinstance(obj, self.PRIMITIVE_TYPES):
3838
return obj
3939
elif isinstance(obj, list):
40-
return [self.to_json(sub_obj)
41-
for sub_obj in obj]
40+
return [self.to_json(sub_obj) for sub_obj in obj]
4241
elif isinstance(obj, tuple):
43-
return tuple(self.to_json(sub_obj)
44-
for sub_obj in obj)
42+
return tuple(self.to_json(sub_obj) for sub_obj in obj)
4543
elif isinstance(obj, (datetime.datetime, datetime.date)):
4644
return obj.isoformat()
47-
48-
if isinstance(obj, dict) or isinstance(obj, CaseInsensitiveDict):
45+
elif isinstance(obj, dict) or isinstance(obj, CaseInsensitiveDict):
4946
obj_dict = obj
47+
elif hasattr(obj, 'attribute_map') and hasattr(obj, 'swagger_types'):
48+
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
49+
for attr, _ in six.iteritems(obj.swagger_types)
50+
if getattr(obj, attr) is not None}
5051
else:
51-
# Convert model obj to dict except
52-
# attributes `swagger_types`, `attribute_map`
53-
# and attributes which value is not None.
54-
# Convert attribute name to json key in
55-
# model definition for request.
56-
if hasattr(obj, 'attribute_map') and hasattr(obj, 'swagger_types'):
57-
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
58-
for attr, _ in six.iteritems(obj.swagger_types)
59-
if getattr(obj, attr) is not None}
60-
else:
61-
obj_dict = {name: getattr(obj, name)
62-
for name in vars(obj)
63-
if getattr(obj, name) is not None}
52+
obj_dict = {name: getattr(obj, name)
53+
for name in vars(obj)
54+
if getattr(obj, name) is not None}
6455

6556
return {key: self.to_json(val)
66-
for key, val in six.iteritems(obj_dict)}
57+
for key, val in six.iteritems(obj_dict)}
6758

6859
def from_json(self, data, klass):
6960
return self.__deserialize(data, klass)
@@ -134,7 +125,6 @@ def __deserialize_date(self, string):
134125
:return: date.
135126
"""
136127
try:
137-
from dateutil.parser import parse
138128
return parse(string).date()
139129
except ImportError:
140130
return string
@@ -153,7 +143,6 @@ def __deserialize_datatime(self, string):
153143
:return: datetime.
154144
"""
155145
try:
156-
from dateutil.parser import parse
157146
return parse(string)
158147
except ImportError:
159148
return string

src/conductor/client/integration_client.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,82 +35,82 @@ class IntegrationClient(ABC):
3535
@abstractmethod
3636
def associate_prompt_with_integration(self, ai_integration:str, model_name:str, prompt_name:str):
3737
"""Associate a prompt with an AI integration and model"""
38-
pass
38+
...
3939

4040
@abstractmethod
4141
def delete_integration_api(self, api_name:str, integration_name:str):
4242
"""Delete a specific integration api for a given integration"""
43-
pass
43+
...
4444

4545
@abstractmethod
4646
def delete_integration(self, integration_name:str):
4747
"""Delete an integration"""
48-
pass
48+
4949

5050
@abstractmethod
5151
def get_integration_api(self, api_name:str, integration_name:str) -> IntegrationApi:
52-
pass
52+
...
5353

5454
@abstractmethod
5555
def get_integration_apis(self, integration_name:str) -> List[IntegrationApi]:
56-
pass
56+
...
5757

5858
@abstractmethod
5959
def get_integration(self, integration_name:str) -> Integration:
60-
pass
60+
...
6161

6262
@abstractmethod
6363
def get_integrations(self) -> List[Integration]:
6464
"""Returns the list of all the available integrations"""
65-
pass
65+
6666

6767
@abstractmethod
6868
def get_prompts_with_integration(self, ai_integration:str, model_name:str) -> List[PromptTemplate]:
69-
pass
69+
...
7070

7171
@abstractmethod
7272
def get_token_usage_for_integration(self, name, integration_name) -> int:
73-
pass
73+
...
7474

7575
@abstractmethod
7676
def get_token_usage_for_integration_provider(self, name) -> dict:
77-
pass
77+
...
7878

7979
@abstractmethod
8080
def register_token_usage(self, body, name, integration_name):
81-
pass
81+
...
8282

8383
@abstractmethod
8484
def save_integration_api(self, integration_name, api_name, api_details: IntegrationApiUpdate):
85-
pass
85+
...
8686

8787
@abstractmethod
8888
def save_integration(self, integration_name, integration_details: IntegrationUpdate):
89-
pass
89+
...
9090

9191
# Tags
9292

9393
@abstractmethod
9494
def delete_tag_for_integration(self, body, tag_name, integration_name):
9595
"""Delete an integration"""
96-
pass
96+
9797

9898
@abstractmethod
9999
def delete_tag_for_integration_provider(self, body, name):
100-
pass
100+
...
101101

102102
@abstractmethod
103103
def put_tag_for_integration(self, body, name, integration_name):
104-
pass
104+
...
105105

106106
@abstractmethod
107107
def put_tag_for_integration_provider(self, body, name):
108-
pass
108+
...
109109

110110
@abstractmethod
111111
def get_tags_for_integration(self, name, integration_name):
112-
pass
112+
...
113113

114114
@abstractmethod
115115
def get_tags_for_integration_provider(self, name):
116-
pass
116+
...

src/conductor/client/orkes/models/access_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from conductor.client.orkes.models.access_key_status import AccessKeyStatus
44

55

6-
class AccessKey:
6+
class AccessKey: # noqa: PLW1641
77
def __init__(self, id: str, status: AccessKeyStatus, created_at: int) -> Self:
88
self._id = id
99
self._status = status

0 commit comments

Comments
 (0)