Skip to content

Commit acbb963

Browse files
committed
Reduce ruff lint exceptions
1 parent b3326f6 commit acbb963

File tree

12 files changed

+50
-164
lines changed

12 files changed

+50
-164
lines changed

pyproject.toml

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -68,127 +68,22 @@ ignore = [
6868
"D105",
6969
"D107",
7070
# These need to be fixed.
71-
"D202",
7271
"D205",
7372
"D400",
7473
"D401",
7574

7675
## E / W - pycodestyle ##
7776
"E501", # line too long
78-
"E203", # whitespace-before-punctuation
79-
"E741", # ambiguous variable name
8077

81-
## PL - pylint ##
82-
# Commented-out rules are rules that we disable in pylint but are not supported by ruff yet.
83-
84-
# Import order issues
85-
# "PLC0411", # wrong-import-order
86-
# "PLC0412", # wrong-import-position
87-
"PLC0414", # ungrouped-imports
88-
89-
# Documentation issues
90-
# "C0114", # missing-module-docstring
91-
92-
# Complexity issues
93-
# "PLR0904", # too-many-public-methods
94-
# "PLC0302", # too-many-lines
95-
# "PLR1702", # too-many-nested-blocks
96-
# "PLR0902", # too-many-instance-attributes
97-
"PLR0911", # too-many-return-statements
98-
"PLR0915", # too-many-statements
99-
"PLR0912", # too-many-branches
100-
# "PLR0903", # too-few-public-methods
101-
# "PLR0914", # too-many-locals
102-
# "PLC0301", # line-too-long
78+
# ## PL - pylint ##
10379
"PLR0913", # too-many-arguments
10480
"PLR2004", # magic-value-comparison
105-
"PLR5501", # collapsible-else-if
10681
"PLW0603", # global-statement
107-
"PLW2901", # redefined-loop-name
108-
"PLC1901", # compare-to-empty-string
109-
110-
## RUF - ruff ##
111-
"RUF001", # ambiguous-unicode-character-string
112-
"RUF002", # ambiguous-unicode-character-docstring
113-
"RUF003", # ambiguous-unicode-character-comment
114-
"RUF012", # mutable-class-default
11582

116-
# Enable when Poetry supports PEP 621 and we migrate our confguration to it.
117-
# See: https://github.com/python-poetry/poetry-core/pull/567
118-
"RUF200",
119-
120-
"S101", # assert
121-
"S104", # hardcoded-bind-all-interfaces
122-
"S105", # hardcoded-password-string
123-
"S106", # hardcoded-password-func-arg
124-
"S107", # hardcoded-password-default
125-
"S110", # try-except-pass
83+
#"S101", # assert
12684
"S301", # suspicious-pickle-usage
127-
"S303", # suspicious-insecure-hash-usage
128-
"S310", # suspicious-url-open-usage
12985
"S311", # suspicious-non-cryptographic-random-usage
130-
"S324", # hashlib-insecure-hash-function
131-
"S603", # subprocess-without-shell-equals-true
132-
"S607", # start-process-with-partial-path
133-
"S608", # hardcoded-sql-expression
134-
135-
## SIM - flake8-simplify ##
136-
"SIM102", # collapsible-if
137-
"SIM105", # suppressible-exception
138-
"SIM108", # if-else-block-instead-of-if-exp
139-
"SIM114", # if-with-same-arms
140-
"SIM116", # if-else-block-instead-of-dict-lookup
141-
"SIM117", # multiple-with-statements
142-
143-
# Enable when the rule is out of preview and false-positives are handled.
144-
# See: https://docs.astral.sh/ruff/rules/in-dict-keys/
145-
"SIM118", # in-dict-keys
14686
]
14787

148-
[tool.ruff.lint.per-file-ignores]
149-
# These files have only a bunch of imports in them to force code loading.
150-
"todoist/workers/todoist_handlers.py" = ["F401"]
151-
"todoist/signals/signal_handlers.py" = ["F401"]
152-
"todoist/workers/scripts_handlers.py" = ["F401"]
153-
"scripts/**" = ["S101"] # Allow assert statement in scripts.
154-
"tests/**" = ["S101"] # Allow assert statement in tests.
155-
156-
# We allow module-level imports to be not at the top of scripts, cron,
157-
# and configs because we initialize Todoist environment there
158-
"todoist/*/scripts/*.py" = ["E402"]
159-
"todoist/*/cron/*.py" = ["E402"]
160-
"scripts/*.py" = ["E402"]
161-
"configs/*.py" = ["E402"]
162-
163-
# To import all fixtures from other conftests.
164-
"conftest.py" = ["F401", "F403"]
165-
# To import select fixtures from non-local conftests.
166-
# Importing and using the fixture makes it be shadowed.
167-
"test_*.py" = ["F401", "F811"]
168-
169-
"tests/minimal/conftest.py" = ["E402", "F401", "F403"]
170-
171-
[tool.ruff.lint.isort]
172-
section-order = [
173-
"future",
174-
"standard-library",
175-
"third-party",
176-
"parts",
177-
"first-party",
178-
"td-models",
179-
"td-apps",
180-
"local-folder",
181-
]
182-
183-
[tool.ruff.lint.isort.sections]
184-
"parts" = ["parts"]
185-
"td-models" = ["todoist.models"]
186-
"td-apps" = ["todoist.apps"]
187-
18888
[tool.ruff.lint.pydocstyle]
18989
convention = "pep257"
190-
191-
[tool.ruff.lint.pyupgrade]
192-
# Required by tools like Pydantic that use type information at runtime.
193-
# https://github.com/asottile/pyupgrade/issues/622#issuecomment-1088766572
194-
keep-runtime-typing = true

sqs_workers/backoff_policies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_visibility_timeout(self, message):
99
class ConstantBackoff(BackoffPolicy):
1010
"""
1111
Backoff policy which always returns the message back to the queue
12-
immediately on failure
12+
immediately on failure.
1313
"""
1414

1515
def __init__(self, backoff_value: float = 0):
@@ -22,7 +22,7 @@ def get_visibility_timeout(self, message) -> float:
2222
class ExponentialBackoff(BackoffPolicy):
2323
"""
2424
Backoff policy which keeps the message hidden from the queue
25-
with an exponential backoff
25+
with an exponential backoff.
2626
"""
2727

2828
def __init__(

sqs_workers/batching.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ class BatchingConfiguration(ABC):
1212
def batching_enabled(self) -> bool:
1313
"""
1414
If false, messages are sent 1 by 1 to the call handler
15-
If true, messages are sent as a list to the call handler
15+
If true, messages are sent as a list to the call handler.
1616
"""
1717
...
1818

1919
@property
2020
@abstractmethod
2121
def batch_size(self) -> int:
22-
"""Number of messages to process at once if batching_enabled"""
22+
"""Number of messages to process at once if batching_enabled."""
2323
...
2424

2525

2626
class NoBatching(BatchingConfiguration):
27-
"""Configures the processor to send messages 1 by 1 to the call handler"""
27+
"""Configures the processor to send messages 1 by 1 to the call handler."""
2828

2929
@property
3030
def batching_enabled(self) -> bool:
@@ -36,7 +36,7 @@ def batch_size(self) -> int:
3636

3737

3838
class BatchMessages(BatchingConfiguration):
39-
"""Configures the processor to send a list of messages to the call handler"""
39+
"""Configures the processor to send a list of messages to the call handler."""
4040

4141
def __init__(self, batch_size: int):
4242
self.number_of_messages = batch_size

sqs_workers/context.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,40 @@ def hello_world(username=None, context=None):
3434

3535
@classmethod
3636
def from_dict(cls, kwargs):
37-
"""Create context from the dict"""
37+
"""Create context from the dict."""
3838
return cls(**kwargs)
3939

4040
def __init__(self, **kwargs):
41-
"""Create a new context and populate it with keys and values from kwargs"""
41+
"""Create a new context and populate it with keys and values from kwargs."""
4242
self._context = {}
4343
self.set(**kwargs)
4444

4545
def set(self, **kwargs):
46-
"""Clean up current context and replace it with values from kwargs"""
46+
"""Clean up current context and replace it with values from kwargs."""
4747
self._context = kwargs.copy()
4848

4949
def update(self, **kwargs):
50-
"""Extend current context with values from kwargs"""
50+
"""Extend current context with values from kwargs."""
5151
self._context.update(kwargs)
5252

5353
def clear(self):
54-
"""Remove all values from the context"""
54+
"""Remove all values from the context."""
5555
self._context.clear()
5656

5757
def to_dict(self):
58-
"""Convert context to dictionary"""
58+
"""Convert context to dictionary."""
5959
return self._context.copy()
6060

6161
def get(self, key, default=None):
62-
"""Get value by key from the context"""
62+
"""Get value by key from the context."""
6363
return self._context.get(key, default)
6464

6565
def __getitem__(self, item):
66-
"""Dict API emulation. Get value by key from the context"""
66+
"""Dict API emulation. Get value by key from the context."""
6767
return self._context[item]
6868

6969
def __setitem__(self, key, value):
70-
"""Dict API emulation. Set value by key"""
70+
"""Dict API emulation. Set value by key."""
7171
self._context[key] = value
7272

7373
@contextmanager

sqs_workers/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __repr__(self) -> str:
3333

3434
class RedrivePolicy:
3535
"""
36-
Redrive Policy for SQS queues
36+
Redrive Policy for SQS queues.
3737
3838
See for more details:
3939
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html

sqs_workers/memory_sqs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def send_messages(self, Entries):
115115
def receive_messages(self, WaitTimeSeconds="0", MaxNumberOfMessages="10", **kwargs):
116116
"""
117117
Helper function which returns at most max_messages from the
118-
queue. Used in an infinite loop inside `get_raw_messages`
118+
queue. Used in an infinite loop inside `get_raw_messages`.
119119
"""
120120
wait_seconds = int(WaitTimeSeconds)
121121
max_messages = int(MaxNumberOfMessages)
@@ -174,7 +174,7 @@ def delete_messages(self, Entries):
174174
def change_message_visibility_batch(self, Entries):
175175
"""
176176
Changes message visibility by looking at in-flight messages, setting
177-
a new visible_at, when it will return to the pool of messages
177+
a new visible_at, when it will return to the pool of messages.
178178
"""
179179
found_entries = []
180180
not_found_entries = []
@@ -210,7 +210,7 @@ def __getitem__(self, item):
210210
@dataclass(frozen=True)
211211
class MemoryMessage:
212212
"""
213-
A mock class to mimic the AWS message
213+
A mock class to mimic the AWS message.
214214
215215
Ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/
216216
services/sqs.html#SQS.Message

sqs_workers/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def process_batch(self, messages):
108108
def copy(self, **kwargs):
109109
"""
110110
Create a new instance of the processor, optionally updating
111-
arguments of the constructor from update_kwargs
111+
arguments of the constructor from update_kwargs.
112112
"""
113113
return replace(self, **kwargs)
114114

sqs_workers/queue.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def maker(cls, **kwargs):
6060
def process_queue(
6161
self, shutdown_policy: ShutdownPolicy = NEVER_SHUTDOWN, wait_second=10
6262
):
63-
"""Run worker to process one queue in the infinite loop"""
63+
"""Run worker to process one queue in the infinite loop."""
6464
logger.debug(
6565
"Start processing queue %s",
6666
self.name,
@@ -88,7 +88,7 @@ def process_queue(
8888
def process_batch(self, wait_seconds: int = 0) -> BatchProcessingResult:
8989
"""
9090
Process a batch of messages from the queue (10 messages at most), return
91-
the number of successfully processed messages, and exit
91+
the number of successfully processed messages, and exit.
9292
"""
9393
if self.batching_policy.batching_enabled:
9494
messages = self.get_raw_messages(
@@ -187,7 +187,7 @@ def process_messages(self, messages: list[Any]) -> bool:
187187
raise NotImplementedError()
188188

189189
def get_raw_messages(self, wait_seconds: int, max_messages: int = 10) -> list[Any]:
190-
"""Return raw messages from the queue, addressed by its name"""
190+
"""Return raw messages from the queue, addressed by its name."""
191191
queue = self.get_queue()
192192

193193
kwargs = {
@@ -246,7 +246,7 @@ def get_sqs_queue_name(self) -> str:
246246
"""
247247
Take "high-level" (user-visible) queue name and return SQS
248248
("low level") name by simply prefixing it. Used to create namespaces
249-
for different environments (development, staging, production, etc)
249+
for different environments (development, staging, production, etc).
250250
"""
251251
return self.env.get_sqs_queue_name(self.name)
252252

@@ -265,7 +265,7 @@ class RawQueue(GenericQueue):
265265

266266
def raw_processor(self):
267267
"""
268-
Decorator to assign processor to handle jobs from the raw queue
268+
Decorator to assign processor to handle jobs from the raw queue.
269269
270270
Usage example:
271271
@@ -302,8 +302,7 @@ def add_raw_job(
302302
deduplication_id: str | None = None,
303303
group_id: str = DEFAULT_MESSAGE_GROUP_ID,
304304
):
305-
"""Add raw message to the queue"""
306-
305+
"""Add raw message to the queue."""
307306
kwargs = {
308307
"MessageBody": message_body,
309308
"DelaySeconds": delay_seconds,
@@ -353,7 +352,7 @@ def process_message(self, message: Any) -> bool:
353352

354353
def process_messages(self, messages: list[Any]) -> bool:
355354
"""
356-
Sends a list of messages to the call handler
355+
Sends a list of messages to the call handler.
357356
358357
Return True if processing went successful for all messages in the batch.
359358
"""
@@ -400,7 +399,7 @@ def processor(
400399
) -> Callable[[Callable[P, Any]], AsyncTask[P]]:
401400
"""
402401
Decorator to assign processor to handle jobs with the name job_name
403-
from the queue queue_name
402+
from the queue queue_name.
404403
405404
Usage example:
406405
@@ -439,7 +438,7 @@ def connect_processor(
439438
) -> AsyncTask[P]:
440439
"""
441440
Assign processor (a function) to handle jobs with the name job_name
442-
from the queue queue_name
441+
from the queue queue_name.
443442
"""
444443
extra = {
445444
"queue_name": self.name,
@@ -463,7 +462,7 @@ def connect_processor(
463462
return AsyncTask(self, job_name, processor)
464463

465464
def get_processor(self, job_name: str) -> Processor | None:
466-
"""Helper function to return a processor for the queue"""
465+
"""Helper function to return a processor for the queue."""
467466
return self.processors.get(job_name)
468467

469468
def open_add_batch(self) -> None:
@@ -581,7 +580,7 @@ def add_job(
581580
) -> str | None:
582581
"""
583582
Add job to the queue. The body of the job will be converted to the text
584-
with one of the codecs (by default it's "pickle_compat")
583+
with one of the codecs (by default it's "pickle_compat").
585584
"""
586585
if not _content_type:
587586
_content_type = self.env.codec
@@ -608,7 +607,7 @@ def add_raw_job(
608607
deduplication_id,
609608
group_id: str | None,
610609
) -> str | None:
611-
"""Low-level function to put message to the queue"""
610+
"""Low-level function to put message to the queue."""
612611
# if queue name ends with .fifo, then according to the AWS specs,
613612
# it's a FIFO queue, and requires group_id.
614613
# Otherwise group_id can be set to None
@@ -654,7 +653,7 @@ def process_message(self, message: Any) -> bool:
654653

655654
def process_messages(self, messages: list[Any]) -> bool:
656655
"""
657-
Sends a list of messages to the call handler
656+
Sends a list of messages to the call handler.
658657
659658
Return True if processing went successful for all messages in the batch.
660659
"""

0 commit comments

Comments
 (0)