Skip to content

Parse top-level complex literals consistently with nested values - #710

Open
Alex0AI wants to merge 1 commit into
google:masterfrom
Alex0AI:fix/complex-literal-parsing
Open

Alex0AI wants to merge 1 commit into
google:masterfrom
Alex0AI:fix/complex-literal-parsing

Conversation

@Alex0AI

@Alex0AI Alex0AI commented Oct 9, 2026

Copy link
Copy Markdown

Summary

Related to #97, whose maintainer discussion explicitly permits complex values while rejecting ordinary arithmetic.

DefaultParseValue("1+2j") returns a string, but DefaultParseValue("[1+2j]") returns a list containing a complex number. Consequently, Fire(lambda value: type(value).__name__, command=["1+2j"]) prints str instead of complex.

Remove the top-level BinOp rejection and let ast.literal_eval enforce literal-only parsing consistently at every nesting level. On the supported Python versions (>=3.7), it permits the real-plus/minus-imaginary form while rejecting ordinary arithmetic and calls. Python 3.7 implementation: https://github.com/python/cpython/blob/v3.7.17/Lib/ast.py#L77-L85

Add parser regressions, an actual Fire invocation test, and a short argument-parsing documentation note. Expressions such as 1+1, [1+1], {key: 1+1}, date-shaped strings, chained complex arithmetic, calls, and multiplication remain strings.

Verification

  • Before the fix: the new complex parser and Fire invocation tests fail; the non-literal expression test passes.
  • python -m pytest fire/parser_test.py fire/core_test.py -q: 52 passed.
  • Full suite on Windows/Python 3.13: 268 passed, 8 failed. The same 8 failures reproduce with the original parser (265 passed, 3 new tests deselected): six example temporary-file reopening failures, testArgPassing's unescaped Windows path regex, and testFileNameFire's temporary-file reopening failure. These are unrelated to this change; Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFire #693 also tracks the latter two.
  • Pylint for all three modified Python files: 10.00/10, no messages.
  • git diff --check passed.

AI assistance disclosure: OpenAI Codex investigated, implemented, tested, and drafted this description.

@google-cla

google-cla Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

1 participant