#4034·Nuitka

在 `**a, **{...}` 时,如果键是 `str` 子类,就会出现 `TypeError: keywords must be strings`

作者: thigger创建于 2026年9月9日更新于 2026年9月11日
标签bugexcellent_report

reprex_pkg/bug.py

from sqlalchemy.sql import quoted_name

class _StrSub(str): """A minimal str SUBCLASS (NOT a plain str)."""

class Bug: async def _create_entity(self, values, pk_col_key, entity_id, now): # THE BUGGY LINE: two **-unpacks in one call; the second literal's key is a # str subclass -- not a plain str. return dict(**values, **{pk_col_key: entity_id, "created_dtm": now, "updated_dtm": now})

async def _create_entity_fixed(self, values, pk_col_key, entity_id, now):
    # WORKAROUND: merge once, single **-unpack.
    merged = dict(values)
    merged[pk_col_key] = entity_id
    merged["created_dtm"] = now
    merged["updated_dtm"] = now
    return merged