Skip to content

ddsidl: fix dead Python-keyword check in getAllowedName - #515

Merged
sschleemilch merged 3 commits into
COVESA:masterfrom
SoundMatt:fix/ddsidl-keyword-iskeyword-missing-call
May 26, 2026
Merged

ddsidl: fix dead Python-keyword check in getAllowedName#515
sschleemilch merged 3 commits into
COVESA:masterfrom
SoundMatt:fix/ddsidl-keyword-iskeyword-missing-call

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Problem

getAllowedName in src/vss_tools/exporters/ddsidl.py is meant to
prefix reserved-word identifiers (C, IDL, or Python) with a leading
underscore so the generated IDL is valid. The Python branch of the
check was dead:

if name.lower() in c_keywords or name.lower() in idl_keywords or keyword.iskeyword(name.lower):
                                                                                   ^^^^^^^^^^
                                                                            missing call parens

name.lower (without ()) is the bound-method object, not the
lowered string. keyword.iskeyword(<method object>) always returns
False, so VSS signal names that are Python keywords but NOT also
C/IDL keywords slipped through silently. Examples that bypass the
check: class, def, import, lambda, try, with, yield,
async, await.

The downstream effect is that the IDL exporter emits these names
unprefixed, producing syntactically invalid IDL.

Fix

Extract name.lower() to a local once and pass it explicitly to
keyword.iskeyword:

def getAllowedName(name):
    lower = name.lower()
    if lower in c_keywords or lower in idl_keywords or keyword.iskeyword(lower):
        return "_" + name
    else:
        return name

Behaviour-preserving for all inputs the current code handles
correctly; corrects the dead Python-keyword arm.

Test

Adds tests/test_ddsidl_naming.py with a regression test that
asserts getAllowedName("class") == "_class" (and similar for
def, import, lambda). With the original bug, that test fails.
Also covers normal names, IDL keywords, and C keywords to lock in
current behaviour.

Notes

  • Only getAllowedName and the new test file are touched. No other
    call sites or behaviour changed.
  • The redundant name.lower() call (three times in the original) is
    now called once, which is incidentally cleaner but the primary
    motivation is correctness.

`keyword.iskeyword(name.lower)` was missing its call parentheses, so
the bound-method object `name.lower` was passed to `iskeyword` instead
of the lowered string. `iskeyword` always returned False, leaving the
Python-keyword arm of the check effectively dead — VSS signal names
that are Python keywords but NOT also C/IDL keywords (e.g. 'class',
'def', 'import', 'lambda') were emitted unprefixed and produced
syntactically invalid IDL.

Compute `name.lower()` once into a local, pass it to `iskeyword`
explicitly, and add a regression test in tests/test_ddsidl_naming.py
covering both the bug case (Python-only keywords) and the existing
behaviour (C/IDL keywords, normal names).

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>

@erikbosch erikbosch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erikbosch

Copy link
Copy Markdown
Collaborator

Thanks for the PR. I think it looks good but will leave it open for a while to give others a chance to review/comment if they would like to.

Comment thread src/vss_tools/exporters/ddsidl.py Outdated
def getAllowedName(name):
if name.lower() in c_keywords or name.lower() in idl_keywords or keyword.iskeyword(name.lower):
lower = name.lower()
# `keyword.iskeyword(name.lower)` (without call parens) passed a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the verbose explanation of the past

@erikbosch

Copy link
Copy Markdown
Collaborator

MoM:

  • Presented at meeting
  • ok to merge after maintainer approval

@erikbosch

Copy link
Copy Markdown
Collaborator

@SoundMatt - will you take a look at the comments from Sebastian

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
@SoundMatt

Copy link
Copy Markdown
Contributor Author

Addressed — verbose comments removed.

…view

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
@erikbosch
erikbosch requested a review from sschleemilch May 26, 2026 14:06
@erikbosch

Copy link
Copy Markdown
Collaborator

@sschleemilch - do you want to take second look

@sschleemilch
sschleemilch merged commit 658ff43 into COVESA:master May 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants