Skip to content

[BugFix] openbb-cli: Make Codegen Names That Start With a Digit or Are Keywords Valid - #7800

Open
drakeo338 wants to merge 2 commits into
openbq-org:developfrom
drakeo338:claude/7799-fix
Open

drakeo338 wants to merge 2 commits into
openbq-org:developfrom
drakeo338:claude/7799-fix

Conversation

@drakeo338

@drakeo338 drakeo338 commented Oct 19, 2026 •

Copy link
Copy Markdown

Pull Request OpenBB

Description

Fixes #7799.

_safe_segment in the CLI router generator returned names like 24hr or class unchanged, so the generated router contained async def 24hr( and unimportable module names. Names that start with a digit now get a leading underscore (_24hr), as the Fetcher, POST and test generators already do, and Python keywords get a trailing one (class_), as pydantic_gen does for field names.

  • Summary of the change/ bug fix.
  • Link # issue, if applicable.

How has this been tested?

Two new tests in cli/tests/test_codegen_router_gen.py fail on the unfixed source and pass with the fix; the file runs 21 passed. Other checkboxes are left unticked because I did not run them.

Checklist

  • I ensure I have self-reviewed my code.
  • Update our tests following these guidelines.

I used an AI coding assistant (Claude Code) for this change and reviewed and tested it myself.

…r Are Keywords

_safe_segment returned names such as "24hr" or "class" unchanged, so the
router generator emitted `async def 24hr(` and unimportable module names.
Prefix them with an underscore (Fixes openbq-org#7799).

@dlee-bq dlee-bq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, @drakeo338.

It fixes #7799. One change before merge: for Python keywords, please append the underscore (class → class_) rather than prefixing it. That matches how the generator already handles keywords in field names (pydantic_gen.safe_field_name / query_field_name give from_), and it keeps generated commands from looking private on the obb surface (obb.x.ticker._class).

Keep the _ prefix for names that start with a digit (_24hr), as you have it.

@drakeo338

Copy link
Copy Markdown
Author

Done in 45dd415: keywords now get a trailing underscore (class_), digit-leading names keep the _ prefix (_24hr), and the tests cover both

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@drakeo338 drakeo338 changed the title [BugFix] openbb-cli: Prefix Codegen Names That Start With a Digit or Are Keywords [BugFix] openbb-cli: Make Codegen Names That Start With a Digit or Are Keywords Valid Oct 19, 2026

This branch has not been deployed

No deployments
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.

[Bug] openbb-cli: router_gen Doesn't Handle names starting with a digit or Python keywords

3 participants