flake8-pie
flake8-pie copied to clipboard
prefer-with
Basically, for things like DB clients, prefer using the with API instead of manually calling close
# err
conn = psycopg2.connect(dsn=dsn)
cursor = conn.cursor()
cursor.execute("SELECT 1")
cursor.close()
conn.close()
# ok
with psycopg2.connect(dsn=dsn) as conn, conn.cursor() as cursor:
cursor.execute("SELECT 1")
I think this requires type information since we need to check that the type has a close and has an __exit__, we may also need to manually specify the supported types for the lint since not all __exit__s will call close