I'm trying to incorporate the Black formatter for Python code as part of my pre-commit workflow. I also use flake8 as a linter. There seems to be a formatting discrepancy between flake8 and Black when it comes to multi-line SQL strings.
Consider a simple file called dbtools.py:
import sqlite3
conn= sqlite3.connect("test.db")
cursor= conn.cursor()
def getResults(targetNumber):
cursor.execute(
"""
with participants_join as (select chat_id, participant from participants where participant != %(targetNumber)s),
message_count as (select chat_id, sms_body from messages),
contact_names as (select rowid, phone_number, name, alias, source, notes from aliases),
> >distinct_chats as (select distinct chat_id from participants)
select p.chat_id, pa.participant, count(mc.sms_body) as count, c.name as name, c.alias as alias, c.source as source, c.notes as notes, c.rowid as aliasID from distinct_chats p
left join participants_join pa on pa.chat_id = p.chat_id
left join message_count mc on mc.chat_id = p.chat_id
left join contact_names c on c.phone_number = pa.participant
group by p.chat_id
""",
{"targetNumber": targetNumber},
)
Black fails to replace the tabs at the line beginning distinct_chats
but does replaces tabs with spaces everywhere else. That's obviously making flake8 throw E101
and W191
errors about mixing tabs and spaces and having tabs in the code. Can someone explain this behavior? Why would Black allow mixing of tabs and spaces and throw no errors or warnings?