Skip to content

Commit d76e480

Browse files
Lint fixes for B, PERF, RUF and C4 errors (#311)
1 parent d34e0f2 commit d76e480

31 files changed

+99
-90
lines changed

src/conductor/client/ai/integrations.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from typing import Optional
66

77
class IntegrationConfig(ABC):
8-
def __init__(self):
9-
pass
10-
118
@abstractmethod
129
def to_dict(self) -> dict:
1310
pass

src/conductor/client/ai/orchestrator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def associate_prompt_template(self, name: str, ai_integration: str, ai_models: L
4747
def test_prompt_template(self, text: str, variables: dict,
4848
ai_integration: str,
4949
text_complete_model: str,
50-
stop_words: Optional[List[str]] = [], max_tokens: Optional[int] = 100,
50+
stop_words: List[str] = None, max_tokens: int = 100,
5151
temperature: int = 0,
5252
top_p: int = 1):
53-
53+
stop_words = stop_words or []
5454
return self.prompt_client.test_prompt(text, variables, ai_integration, text_complete_model, temperature, top_p,
5555
stop_words)
5656

src/conductor/client/automator/task_handler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ def register_decorated_fn(name: str, poll_interval: int, domain: str, worker_id:
4646
class TaskHandler:
4747
def __init__(
4848
self,
49-
workers: List[WorkerInterface] = [],
49+
workers: Optional[List[WorkerInterface]] = None,
5050
configuration: Optional[Configuration] = None,
5151
metrics_settings: Optional[MetricsSettings] = None,
5252
scan_for_annotated_workers: bool = True,
5353
import_modules: Optional[List[str]] = None
5454
):
55+
workers = workers or []
5556
self.logger_process, self.queue = _setup_logging_queue(configuration)
5657

5758
# imports
@@ -62,8 +63,6 @@ def __init__(
6263
logger.info(f'loading module {module}')
6364
importlib.import_module(module)
6465

65-
if workers is None:
66-
workers = []
6766
elif not isinstance(workers, list):
6867
workers = [workers]
6968
if scan_for_annotated_workers is True:

src/conductor/client/automator/task_runner.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ def run(self) -> None:
5858
f'interval {self.worker.get_polling_interval_in_seconds()}')
5959

6060
while True:
61-
try:
62-
self.run_once()
63-
except Exception:
64-
pass
61+
self.run_once()
6562

6663
def run_once(self) -> None:
67-
task = self.__poll_task()
68-
if task is not None and task.task_id is not None:
69-
task_result = self.__execute_task(task)
70-
self.__update_task(task_result)
71-
self.__wait_for_polling_interval()
72-
self.worker.clear_task_definition_name_cache()
64+
try:
65+
task = self.__poll_task()
66+
if task is not None and task.task_id is not None:
67+
task_result = self.__execute_task(task)
68+
self.__update_task(task_result)
69+
self.__wait_for_polling_interval()
70+
self.worker.clear_task_definition_name_cache()
71+
except Exception as e:
72+
pass
7373

7474
def __poll_task(self) -> Task:
7575
task_definition_name = self.worker.get_task_definition_name()

src/conductor/client/automator/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ def convert_from_dict(cls: type, data: dict) -> object:
7272
else:
7373
kwargs[member] = members[member].default
7474
elif str(typ).startswith('typing.List[') or str(typ).startswith('typing.Set[') or str(typ).startswith('list['):
75-
values = []
7675
generic_type = object
7776
if len(generic_types) > 0:
7877
generic_type = generic_types[0]
79-
for val in data[member]:
80-
values.append(get_value(generic_type, val))
78+
values = [get_value(generic_type, item) for item in data[member]]
8179
kwargs[member] = values
8280
elif (str(typ).startswith('dict[') or
8381
str(typ).startswith('typing.Dict[') or
@@ -112,8 +110,8 @@ def get_value(typ: type, val: object) -> object:
112110
return val
113111
elif str(typ).startswith('typing.List[') or str(typ).startswith('typing.Set[') or str(typ).startswith('list['):
114112
values = []
115-
for val in val:
116-
converted = get_value(type(val), val)
113+
for item in val:
114+
converted = get_value(type(item), item)
117115
values.append(converted)
118116
return values
119117
elif str(typ).startswith('dict[') or str(typ).startswith(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def get_default_temporary_folder() -> str:
17-
return f'{str(Path.home())}/tmp/'
17+
return f'{Path.home()!s}/tmp/'
1818

1919

2020
class MetricsSettings:

src/conductor/client/event/queue/queue_configuration.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from abc import ABC
2-
from typing import Any, Dict
1+
from abc import ABC, abstractmethod
2+
from typing import Any, ClassVar, Dict
33

44
from conductor.client.event.queue.queue_worker_configuration import QueueWorkerConfiguration
55

66

77
class QueueConfiguration(ABC):
8-
WORKER_CONSUMER_KEY = "consumer"
9-
WORKER_PRODUCER_KEY = "producer"
8+
WORKER_CONSUMER_KEY: ClassVar[str] = "consumer"
9+
WORKER_PRODUCER_KEY: ClassVar[str] = "producer"
1010

1111
def __init__(self, queue_name: str, queue_type: str):
1212
self.queue_name = queue_name
@@ -19,5 +19,6 @@ def add_consumer(self, worker_configuration: QueueWorkerConfiguration) -> None:
1919
def add_producer(self, worker_configuration: QueueWorkerConfiguration) -> None:
2020
self.worker_configuration[self.WORKER_PRODUCER_KEY] = worker_configuration
2121

22+
@abstractmethod
2223
def get_worker_configuration(self) -> Dict[str, Any]:
2324
raise NotImplementedError

src/conductor/client/exceptions/api_exception_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def inner_function(*args, **kwargs):
4646
return inner_function
4747

4848

49-
def for_all_methods(decorator, exclude=[]):
49+
def for_all_methods(decorator, exclude=None):
5050
def decorate(cls):
51+
exclude_local = [] if exclude is None else exclude
5152
for attr in cls.__dict__:
52-
if callable(getattr(cls, attr)) and attr not in exclude:
53+
if callable(getattr(cls, attr)) and attr not in exclude_local:
5354
setattr(cls, attr, decorator(getattr(cls, attr)))
5455
return cls
55-
56-
return decorate
56+
return decorate

src/conductor/client/helpers/helper.py

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

56
import six
67
from requests.structures import CaseInsensitiveDict
@@ -17,10 +18,10 @@
1718

1819

1920
class ObjectMapper(object):
20-
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
21-
NATIVE_TYPES_MAPPING = {
21+
PRIMITIVE_TYPES: ClassVar[Tuple[Any, ...]] = (float, bool, bytes, six.text_type, *six.integer_types)
22+
NATIVE_TYPES_MAPPING: ClassVar[Dict[str, Any]] = {
2223
'int': int,
23-
'long': int if six.PY3 else long, # noqa: F821
24+
'long': int if six.PY3 else long, # noqa: F821, RUF100
2425
'float': float,
2526
'str': str,
2627
'bool': bool,
@@ -137,11 +138,11 @@ def __deserialize_date(self, string):
137138
return parse(string).date()
138139
except ImportError:
139140
return string
140-
except ValueError:
141+
except ValueError as err:
141142
raise rest.ApiException(
142143
status=0,
143144
reason="Failed to parse `{0}` as date object".format(string)
144-
)
145+
) from err
145146

146147
def __deserialize_datatime(self, string):
147148
"""Deserializes string to datetime.
@@ -156,14 +157,14 @@ def __deserialize_datatime(self, string):
156157
return parse(string)
157158
except ImportError:
158159
return string
159-
except ValueError:
160+
except ValueError as err:
160161
raise rest.ApiException(
161162
status=0,
162163
reason=(
163164
"Failed to parse `{0}` as datetime object"
164165
.format(string)
165166
)
166-
)
167+
) from err
167168

168169
def __hasattr(self, object, name):
169170
return name in object.__class__.__dict__

src/conductor/client/integration_client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,58 +42,75 @@ def delete_integration_api(self, api_name:str, integration_name:str):
4242
"""Delete a specific integration api for a given integration"""
4343
pass
4444

45+
@abstractmethod
4546
def delete_integration(self, integration_name:str):
4647
"""Delete an integration"""
4748
pass
4849

50+
@abstractmethod
4951
def get_integration_api(self, api_name:str, integration_name:str) -> IntegrationApi:
5052
pass
5153

54+
@abstractmethod
5255
def get_integration_apis(self, integration_name:str) -> List[IntegrationApi]:
5356
pass
5457

58+
@abstractmethod
5559
def get_integration(self, integration_name:str) -> Integration:
5660
pass
5761

62+
@abstractmethod
5863
def get_integrations(self) -> List[Integration]:
5964
"""Returns the list of all the available integrations"""
6065
pass
6166

67+
@abstractmethod
6268
def get_prompts_with_integration(self, ai_integration:str, model_name:str) -> List[PromptTemplate]:
6369
pass
6470

71+
@abstractmethod
6572
def get_token_usage_for_integration(self, name, integration_name) -> int:
6673
pass
6774

75+
@abstractmethod
6876
def get_token_usage_for_integration_provider(self, name) -> dict:
6977
pass
7078

79+
@abstractmethod
7180
def register_token_usage(self, body, name, integration_name):
7281
pass
7382

83+
@abstractmethod
7484
def save_integration_api(self, integration_name, api_name, api_details: IntegrationApiUpdate):
7585
pass
7686

87+
@abstractmethod
7788
def save_integration(self, integration_name, integration_details: IntegrationUpdate):
7889
pass
7990

8091
# Tags
8192

93+
@abstractmethod
8294
def delete_tag_for_integration(self, body, tag_name, integration_name):
8395
"""Delete an integration"""
8496
pass
8597

98+
@abstractmethod
8699
def delete_tag_for_integration_provider(self, body, name):
87100
pass
88101

102+
@abstractmethod
89103
def put_tag_for_integration(self, body, name, integration_name):
90104
pass
91105

106+
@abstractmethod
92107
def put_tag_for_integration_provider(self, body, name):
93108
pass
94109

110+
@abstractmethod
95111
def get_tags_for_integration(self, name, integration_name):
96112
pass
97113

114+
@abstractmethod
98115
def get_tags_for_integration_provider(self, name):
99116
pass

0 commit comments

Comments
 (0)