Skip to content

Commit 41a8495

Browse files
Dev-iLclaude
andcommitted
Fix linter violations surfaced by updated ruff and mypy
psqlpy-stress: - migrations/versions: add `# ruff: noqa: INP001` (Alembic version files are intentionally outside a package); modernize Union[X, None] → X | None - mocker.py: correct generate_random_array return type list[str] → list[int]; add # noqa: S311 for non-cryptographic random use; wrap overlong INSERT string - models/sqlalchemy.py: add type: ignore[misc, valid-type] on declarative_base subclasses — Base is typed as Any because sqlalchemy lacks installed stubs - models/piccolo.py: add type: ignore[call-arg] — tablename kwarg goes to Table.__init_subclass__ which mypy can't see through Any - settings.py: remove `: str` annotations from StrEnum members (mypy 2.x requires enum members to be unannotated) python/tests: - conftest.py: fix PLW1508 — os.environ.get default must be str, not int - test_binary_copy.py: extend existing noqa comments with ASYNC240 (os.path use inside async functions; the paths are compile-time constants so anyio would add no value here) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8cae7f5 commit 41a8495

8 files changed

Lines changed: 25 additions & 23 deletions

File tree

psqlpy-stress/psqlpy_stress/migrations/versions/06d989926550_basic_user_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: INP001
12
"""basic user table
23
34
Revision ID: 06d989926550
@@ -7,17 +8,16 @@
78
"""
89

910
from collections.abc import Sequence
10-
from typing import Union
1111

1212
import sqlalchemy as sa
1313
from alembic import op
1414

1515

1616
# revision identifiers, used by Alembic.
1717
revision: str = "06d989926550"
18-
down_revision: Union[str, None] = None
19-
branch_labels: Union[str, Sequence[str], None] = None
20-
depends_on: Union[str, Sequence[str], None] = None
18+
down_revision: str | None = None
19+
branch_labels: str | Sequence[str] | None = None
20+
depends_on: str | Sequence[str] | None = None
2121

2222

2323
def upgrade() -> None:

psqlpy-stress/psqlpy_stress/migrations/versions/d162c084f522_big_af_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: INP001
12
"""big af table
23
34
Revision ID: d162c084f522
@@ -7,7 +8,6 @@
78
"""
89

910
from collections.abc import Sequence
10-
from typing import Union
1111

1212
import sqlalchemy as sa
1313
from alembic import op
@@ -16,9 +16,9 @@
1616

1717
# revision identifiers, used by Alembic.
1818
revision: str = "d162c084f522"
19-
down_revision: Union[str, None] = "06d989926550"
20-
branch_labels: Union[str, Sequence[str], None] = None
21-
depends_on: Union[str, Sequence[str], None] = None
19+
down_revision: str | None = "06d989926550"
20+
branch_labels: str | Sequence[str] | None = None
21+
depends_on: str | Sequence[str] | None = None
2222

2323

2424
def upgrade() -> None:

psqlpy-stress/psqlpy_stress/mocker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ async def fill_users() -> None:
2525
)
2626

2727

28-
def generate_random_array() -> list[str]:
29-
return [random.randint(50, 500) for _ in range(random.randint(50, 500))]
28+
def generate_random_array() -> list[int]:
29+
return [random.randint(50, 500) for _ in range(random.randint(50, 500))] # noqa: S311
3030

3131

3232
def generate_random_dict() -> dict[str, str]:
33-
return {str(uuid.uuid4()): str(uuid.uuid4()) for _ in range(random.randint(50, 500))}
33+
return {str(uuid.uuid4()): str(uuid.uuid4()) for _ in range(random.randint(50, 500))} # noqa: S311
3434

3535

3636
async def fill_big_table() -> None:
@@ -39,10 +39,12 @@ async def fill_big_table() -> None:
3939
connection = await pool.connection()
4040
for _ in range(big_table_amount):
4141
await connection.execute(
42-
"INSERT INTO big_table (string_field, integer_field, json_field, array_field) VALUES($1, $2, $3, $4)",
42+
"INSERT INTO big_table"
43+
" (string_field, integer_field, json_field, array_field)"
44+
" VALUES($1, $2, $3, $4)",
4345
parameters=[
4446
str(uuid.uuid4()),
45-
random.randint(1, 99999999),
47+
random.randint(1, 99999999), # noqa: S311
4648
generate_random_dict(),
4749
generate_random_array(),
4850
],

psqlpy-stress/psqlpy_stress/models/piccolo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from piccolo.table import Table
33

44

5-
class User(Table, tablename="users"):
5+
class User(Table, tablename="users"): # type: ignore[call-arg]
66
user_id = Serial(primary_key=True)
77
username = Varchar(null=False)
88

99

10-
class SomeBigTable(Table, tablename="big_table"):
10+
class SomeBigTable(Table, tablename="big_table"): # type: ignore[call-arg]
1111
big_table_id = Integer(primary_key=True)
1212
string_field = Varchar(null=False)
1313
integer_field = Integer(null=False)

psqlpy-stress/psqlpy_stress/models/sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
Base = declarative_base()
77

88

9-
class User(Base):
9+
class User(Base): # type: ignore[misc, valid-type]
1010
__tablename__ = "users"
1111

1212
user_id = Column(Integer, primary_key=True, autoincrement=True)
1313
username = Column(String, unique=True, nullable=False)
1414

1515

16-
class SomeBigTable(Base):
16+
class SomeBigTable(Base): # type: ignore[misc, valid-type]
1717
__tablename__ = "big_table"
1818
big_table_id = Column(Integer, primary_key=True, autoincrement=True)
1919
string_field = Column(String, unique=False, nullable=False)

psqlpy-stress/psqlpy_stress/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
class DriversEnum(enum.StrEnum):
7-
PSQLPY: str = "psqlpy"
8-
ASYNCPG: str = "asyncpg"
9-
PSYCOPG: str = "psycopg"
7+
PSQLPY = "psqlpy"
8+
ASYNCPG = "asyncpg"
9+
PSYCOPG = "psycopg"
1010

1111

1212
class Settings(BaseSettings):

python/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def postgres_password() -> str:
5656

5757
@pytest.fixture
5858
def postgres_port() -> int:
59-
return int(os.environ.get("POSTGRES_PORT", 5432))
59+
return int(os.environ.get("POSTGRES_PORT", "5432"))
6060

6161

6262
@pytest.fixture

python/tests/test_binary_copy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def test_binary_copy_to_table_in_connection(
3737
)
3838

3939
arrow_table = parquet.read_table(
40-
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100
40+
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100, ASYNC240
4141
)
4242
encoder = ArrowToPostgresBinaryEncoder(arrow_table.schema)
4343
buf = BytesIO()
@@ -90,7 +90,7 @@ async def test_binary_copy_to_table_in_transaction(
9090
)
9191

9292
arrow_table = parquet.read_table(
93-
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100
93+
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100, ASYNC240
9494
)
9595
encoder = ArrowToPostgresBinaryEncoder(arrow_table.schema)
9696
buf = BytesIO()

0 commit comments

Comments
 (0)