Skip to content

Commit cede667

Browse files
committed
fix: resolve ruff static analysis issues (F821, E721, E722, F401, F811, B007)
- Add missing imports in TYPE_CHECKING blocks (PostgresJsonPath, SQLTypeAdapter) - Add jsonb_path_* functions to __all__ exports - Remove unused imports (logging) - Fix type comparisons: use 'is' instead of '==' - Replace bare except with specific exception types - Remove duplicate imports - Rename unused loop variable to _method_name - Split long lines for readability
1 parent 4613954 commit cede667

9 files changed

Lines changed: 33 additions & 18 deletions

File tree

‎src/rhosocial/activerecord/backend/impl/postgres/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,8 @@
343343
'json_path_index',
344344
'json_path_wildcard',
345345
'json_path_filter',
346+
'jsonb_path_query',
347+
'jsonb_path_query_first',
348+
'jsonb_path_exists',
349+
'jsonb_path_match',
346350
]

‎src/rhosocial/activerecord/backend/impl/postgres/__main__.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ def get_protocol_support_methods(protocol_class: type) -> List[str]:
210210
"""
211211
methods = []
212212
for name, member in inspect.getmembers(protocol_class):
213-
if callable(member) and (name.startswith('supports_') or name.startswith('is_') and name.endswith('_available')):
213+
is_supports = name.startswith('supports_')
214+
is_available = (name.startswith('is_') and name.endswith('_available'))
215+
if callable(member) and (is_supports or is_available):
214216
methods.append(name)
215217
return sorted(methods)
216218

@@ -336,7 +338,7 @@ def display_info(verbose: int = 0, output_format: str = 'table',
336338
# For methods with parameters: value is dict with 'supported', 'total', 'args'
337339
supported_count = 0
338340
total_count = 0
339-
for method_name, value in support_methods.items():
341+
for _method_name, value in support_methods.items():
340342
if isinstance(value, dict):
341343
supported_count += value['supported']
342344
total_count += value['total']
@@ -440,7 +442,13 @@ def _display_info_rich(info: Dict, verbose: int, version_display: str,
440442

441443
if verbose >= 2 and "methods" in stats:
442444
for method, value in stats["methods"].items():
443-
method_display = method.replace("supports_", "").replace("_", " ").replace("is_", "").replace("_available", "")
445+
# Format method name for display
446+
method_display = (
447+
method.replace("supports_", "")
448+
.replace("_", " ")
449+
.replace("is_", "")
450+
.replace("_available", "")
451+
)
444452
if isinstance(value, dict):
445453
# Method with parameters - show each arg's support
446454
console.print(f" [dim]{method_display}:[/dim]")

‎src/rhosocial/activerecord/backend/impl/postgres/adapters/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def from_database(self, value: Any, target_type: Type, options: Optional[Dict[st
6161
# For string target type, serialize dict/list back to JSON string
6262
# This is needed because psycopg auto-deserializes JSON to dict,
6363
# but model fields may be defined as str type
64-
if target_type == str:
64+
if target_type is str:
6565
if isinstance(value, (dict, list)):
6666
return json.dumps(value)
6767
return value

‎src/rhosocial/activerecord/backend/impl/postgres/adapters/json.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def from_database(self, value: Any, target_type: Type, options: Optional[Dict[st
4747
# For string target type, serialize dict/list back to JSON string
4848
# This is needed because psycopg auto-deserializes JSON to dict,
4949
# but model fields may be defined as str type
50-
if target_type == str:
50+
if target_type is str:
5151
if isinstance(value, (dict, list)):
5252
return json.dumps(value)
5353
return value

‎src/rhosocial/activerecord/backend/impl/postgres/adapters/monetary.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def to_database(
7373
if isinstance(value, PostgresMoney):
7474
return str(value.amount)
7575

76-
from decimal import Decimal
76+
from decimal import Decimal, InvalidOperation
7777
if isinstance(value, Decimal):
7878
return str(value)
7979

@@ -84,8 +84,8 @@ def to_database(
8484
try:
8585
Decimal(value)
8686
return value
87-
except:
88-
raise ValueError(f"Invalid money value: {value}")
87+
except (ValueError, InvalidOperation) as e:
88+
raise ValueError(f"Invalid money value: {value}") from None
8989

9090
raise TypeError(f"Cannot convert {type(value).__name__} to MONEY")
9191

@@ -140,7 +140,7 @@ def _parse_money_string(self, value: str):
140140
Decimal amount
141141
"""
142142
import re
143-
from decimal import Decimal
143+
from decimal import Decimal, InvalidOperation
144144

145145
value = value.strip()
146146

@@ -179,8 +179,8 @@ def _parse_money_string(self, value: str):
179179

180180
try:
181181
return Decimal(cleaned)
182-
except:
183-
raise ValueError(f"Cannot parse money value: {value}")
182+
except (ValueError, InvalidOperation):
183+
raise ValueError(f"Cannot parse money value: {value}") from None
184184

185185
def to_database_batch(
186186
self,

‎src/rhosocial/activerecord/backend/impl/postgres/adapters/object_identifier.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def from_database(
166166
if isinstance(value, int):
167167
return target_type(str(value), oid=value)
168168

169-
if target_type == int:
169+
if target_type is int:
170170
if isinstance(value, int):
171171
return value
172172
if isinstance(value, str):
173173
return int(value)
174174

175-
if target_type == str:
175+
if target_type is str:
176176
return str(value)
177177

178178
raise TypeError(f"Cannot convert {type(value).__name__} to {target_type.__name__}")
@@ -272,7 +272,7 @@ def from_database(
272272
if isinstance(value, str):
273273
return target_type(int(value))
274274

275-
if target_type == int:
275+
if target_type is int:
276276
if isinstance(value, int):
277277
return value
278278
if isinstance(value, str):
@@ -375,14 +375,14 @@ def from_database(
375375
if isinstance(value, (tuple, list)):
376376
return TID(int(value[0]), int(value[1]))
377377

378-
if target_type == tuple:
378+
if target_type is tuple:
379379
if isinstance(value, TID):
380380
return (value.block, value.offset)
381381
if isinstance(value, str):
382382
tid = TID.from_postgres_string(value)
383383
return (tid.block, tid.offset)
384384

385-
if target_type == str:
385+
if target_type is str:
386386
if isinstance(value, TID):
387387
return value.to_postgres_string()
388388
return str(value)

‎src/rhosocial/activerecord/backend/impl/postgres/backend/base.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
This module provides the base mixin class for PostgreSQL backend implementations,
55
containing methods that are shared between sync and async backends.
66
"""
7-
from typing import Dict, Optional, Tuple, Type
7+
from typing import Dict, Optional, Tuple, Type, TYPE_CHECKING
88
import logging
99

10+
if TYPE_CHECKING:
11+
from rhosocial.activerecord.backend.type_adapter import SQLTypeAdapter
12+
1013

1114
class PostgresBackendMixin:
1215
"""PostgreSQL backend shared methods mixin.

‎src/rhosocial/activerecord/backend/impl/postgres/functions/json.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from rhosocial.activerecord.backend.dialect import SQLDialectBase
18+
from ..types.json import PostgresJsonPath
1819

1920

2021
# Path builder utility functions

‎src/rhosocial/activerecord/backend/impl/postgres/mixins.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
This module contains only dialect-related mixins.
66
"""
77
from typing import Dict, Optional, Tuple, List
8-
import logging
98
from .protocols import PostgresExtensionInfo
109

1110

0 commit comments

Comments
 (0)