Python格式化程序黑色抛出8错误多行SQL字符串

2024-04-27 04:45:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图将Python代码的Black格式化程序合并为预提交工作流的一部分。我还使用flake8作为短绒。对于多行SQL字符串,flake8和Black之间似乎存在格式差异

考虑一个简单的文件名为<强> dToSoo.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},
    )

黑色无法替换行开头distinct_chats处的制表符,但会在其他地方用空格替换制表符。这显然让flake8抛出了关于混合制表符和空格以及在代码中使用制表符的E101W191错误。有人能解释这种行为吗?为什么黑色允许标签和空格的混合,并且不会抛出错误或警告


Tags: fromidflake8ascountchatselectcursor