flake8-pie
flake8-pie copied to clipboard
prefer-collapsed-with
# err
with psycopg2.connect(dsn=dsn) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT 1")
# ok
with psycopg2.connect(dsn=dsn) as conn, conn.cursor() as cursor:
cursor.execute("SELECT 1")
# err
async with asyncpg.create_pool(user="postgres", command_timeout=60) as pool:
async with pool.acquire() as con:
await con.execute(
"""
CREATE TABLE names (
id serial PRIMARY KEY,
name VARCHAR (255) NOT NULL)
"""
)
await con.fetch("SELECT 1")
# ok
async with asyncpg.create_pool(
user="postgres", command_timeout=60
) as pool, pool.acquire() as con:
await con.execute(
"""
CREATE TABLE names (
id serial PRIMARY KEY,
name VARCHAR (255) NOT NULL)
"""
)
await con.fetch("SELECT 1")
Partially implemented as SIM117 in flake8-simplify