Skip to content

Commit 28d7b37

Browse files
fsecada01claude
andcommitted
Fix E501 line length errors in docstrings
Break long docstring lines to comply with 80 char limit: - exceptions.py: 7 lines fixed - mixins.py: 2 lines fixed - transactions.py: 5 lines fixed - test_v0_2_0_features.py: 2 lines fixed Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent be8c667 commit 28d7b37

4 files changed

Lines changed: 63 additions & 29 deletions

File tree

sqlmodel_crud_utils/exceptions.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ class MultipleRecordsError(SQLModelCRUDError):
119119
... count=3,
120120
... filters={"email": "test@example.com"}
121121
... )
122-
MultipleRecordsError: Expected 1 User, found 3 (filters: {'email': 'test@example.com'})
122+
MultipleRecordsError: Expected 1 User, found 3
123+
(filters: {'email': 'test@example.com'})
123124
"""
124125

125126
def __init__(
@@ -174,7 +175,8 @@ class ValidationError(SQLModelCRUDError):
174175
... value=-5,
175176
... message="Age must be a positive integer"
176177
... )
177-
ValidationError: Validation failed for field 'age': Age must be a positive integer (value: -5)
178+
ValidationError: Validation failed for field 'age':
179+
Age must be a positive integer (value: -5)
178180
179181
Multiple field errors:
180182
>>> raise ValidationError(
@@ -324,8 +326,10 @@ class TransactionError(SQLModelCRUDError):
324326
- Connection issues during transaction
325327
326328
Attributes:
327-
operation: The transaction operation that failed (e.g., "commit", "rollback").
328-
original_error: The underlying exception that caused the failure.
329+
operation: The transaction operation that failed
330+
(e.g., "commit", "rollback").
331+
original_error: The underlying exception that caused the
332+
failure.
329333
330334
Example:
331335
>>> try:
@@ -335,7 +339,8 @@ class TransactionError(SQLModelCRUDError):
335339
... operation="commit",
336340
... original_error=e
337341
... )
338-
TransactionError: Transaction operation 'commit' failed: IntegrityError(...)
342+
TransactionError: Transaction operation 'commit' failed:
343+
IntegrityError(...)
339344
"""
340345

341346
def __init__(
@@ -471,11 +476,16 @@ def __init__(
471476
full_message = message
472477
elif query and original_error:
473478
full_message = (
474-
f"Query execution failed: {type(original_error).__name__}({original_error})\n"
475-
f"Query: {query[:200]}{'...' if len(query) > 200 else ''}"
479+
f"Query execution failed: "
480+
f"{type(original_error).__name__}({original_error})\n"
481+
f"Query: {query[:200]}"
482+
f"{'...' if len(query) > 200 else ''}"
476483
)
477484
elif query:
478-
full_message = f"Query execution failed: {query[:200]}{'...' if len(query) > 200 else ''}"
485+
full_message = (
486+
f"Query execution failed: {query[:200]}"
487+
f"{'...' if len(query) > 200 else ''}"
488+
)
479489
elif original_error:
480490
full_message = f"Query execution failed: {original_error}"
481491
else:
@@ -546,7 +556,9 @@ def validation_error(
546556
A configured ValidationError instance.
547557
548558
Example:
549-
>>> raise validation_error("Invalid email", field="email", value="not-an-email")
559+
>>> raise validation_error(
560+
... "Invalid email", field="email", value="not-an-email"
561+
... )
550562
"""
551563
return ValidationError(
552564
message=message, field=field, value=value, errors=errors

sqlmodel_crud_utils/mixins.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class AuditMixin:
2323
2424
Attributes:
2525
created_at: Timestamp when the record was created (auto-set)
26-
updated_at: Timestamp when the record was last updated (auto-set on update)
26+
updated_at: Timestamp when the record was last updated
27+
(auto-set on update)
2728
created_by: Optional username/ID of creator
2829
updated_by: Optional username/ID of last updater
2930
@@ -158,11 +159,13 @@ class SoftDeleteMixin:
158159
def soft_delete(self, user: Optional[str] = None) -> None:
159160
"""Mark this record as deleted.
160161
161-
Sets the is_deleted flag to True, records the deletion timestamp,
162-
and optionally tracks which user performed the deletion.
162+
Sets the is_deleted flag to True, records the deletion
163+
timestamp, and optionally tracks which user performed the
164+
deletion.
163165
164166
Args:
165-
user: Optional username or user ID of the person performing the deletion
167+
user: Optional username or user ID of the person
168+
performing the deletion
166169
167170
Example:
168171
>>> product.soft_delete(user="admin")

sqlmodel_crud_utils/transactions.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
def transaction(session: Session) -> Generator[Session, None, None]:
1919
"""Context manager for synchronous database transactions.
2020
21-
Automatically commits the transaction on successful completion or rolls back
22-
on any exception. The original exception is wrapped in a TransactionError
23-
to provide additional context while preserving the exception chain.
21+
Automatically commits the transaction on successful completion or
22+
rolls back on any exception. The original exception is wrapped in a
23+
TransactionError to provide additional context while preserving the
24+
exception chain.
2425
2526
Args:
2627
session: An active SQLModel Session instance
@@ -29,8 +30,9 @@ def transaction(session: Session) -> Generator[Session, None, None]:
2930
Session: The same session instance for use within the context
3031
3132
Raises:
32-
TransactionError: Wraps any exception that occurs during the transaction,
33-
with the original exception available via __cause__
33+
TransactionError: Wraps any exception that occurs during
34+
the transaction, with the original exception available
35+
via __cause__
3436
3537
Example:
3638
Basic usage with automatic commit:
@@ -43,7 +45,9 @@ def transaction(session: Session) -> Generator[Session, None, None]:
4345
>>> with Session(engine) as session:
4446
... with transaction(session) as tx:
4547
... user = write_row(User(name="Alice"), tx)
46-
... update_row(user.id, {"email": "alice@example.com"}, User, tx)
48+
... update_row(
49+
... user.id, {"email": "alice@example.com"}, User, tx
50+
... )
4751
... # Automatically commits here if no exceptions
4852
4953
Error handling with automatic rollback:
@@ -93,18 +97,22 @@ async def a_transaction(
9397
) -> AsyncGenerator[AsyncSession, None]:
9498
"""Context manager for asynchronous database transactions.
9599
96-
Asynchronous version of the transaction() context manager. Provides the same
97-
automatic commit/rollback behavior for async database operations.
100+
Asynchronous version of the transaction() context manager. Provides
101+
the same automatic commit/rollback behavior for async database
102+
operations.
98103
99104
Args:
100-
session: An active AsyncSession instance from sqlmodel.ext.asyncio.session
105+
session: An active AsyncSession instance from
106+
sqlmodel.ext.asyncio.session
101107
102108
Yields:
103-
AsyncSession: The same session instance for use within the async context
109+
AsyncSession: The same session instance for use within the
110+
async context
104111
105112
Raises:
106-
TransactionError: Wraps any exception that occurs during the transaction,
107-
with the original exception available via __cause__
113+
TransactionError: Wraps any exception that occurs during
114+
the transaction, with the original exception available
115+
via __cause__
108116
109117
Example:
110118
Basic async usage with automatic commit:
@@ -117,8 +125,13 @@ async def a_transaction(
117125
>>> engine = create_async_engine("sqlite+aiosqlite:///database.db")
118126
>>> async with AsyncSession(engine) as session:
119127
... async with a_transaction(session) as tx:
120-
... user = await a_write_row(User(name="Alice"), tx)
121-
... await a_update_row(user.id, {"email": "alice@example.com"}, User, tx)
128+
... user = await a_write_row(
129+
... User(name="Alice"), tx
130+
... )
131+
... await a_update_row(
132+
... user.id, {"email": "alice@example.com"},
133+
... User, tx
134+
... )
122135
... # Automatically commits here if no exceptions
123136
124137
Error handling with automatic rollback:

tests/test_v0_2_0_features.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def test_multiple_records_error_with_count(self):
129129
def test_multiple_records_error_with_filters(self):
130130
"""Test MultipleRecordsError with filters."""
131131
filters = {"email": "test@example.com", "active": True}
132-
exc = MultipleRecordsError(model=AuditTestModel, count=3, filters=filters)
132+
exc = MultipleRecordsError(
133+
model=AuditTestModel, count=3, filters=filters
134+
)
133135

134136
assert exc.filters == filters
135137
assert "filters:" in str(exc)
@@ -722,7 +724,11 @@ def test_multiple_soft_deletes(self):
722724

723725
assert model.is_deleted is True
724726
assert model.deleted_by == "user2"
725-
assert second_deleted_at is not None and first_deleted_at is not None and second_deleted_at >= first_deleted_at
727+
assert (
728+
second_deleted_at is not None
729+
and first_deleted_at is not None
730+
and second_deleted_at >= first_deleted_at
731+
)
726732

727733

728734
# ============================================================================

0 commit comments

Comments
 (0)