Repository navigation
Conversation
…oogle#733) When a function parameter is explicitly annotated with str or an optional string type (Optional[str] / str | None), prevent DefaultParseValue from coercing version strings, floats, and numeric representations (e.g. 1.10) into loat(1.1) or int. - Add IsStringAnnotation and AllowsNone helpers in inspectutils.py to identify string annotations across direct types, typing constructs, and union expressions. - Pass argspec �nnotations into _ParseArgs and _ParseValue in core.py, preserving the original string when literal evaluation would otherwise coerce the value away from str. - Preserve custom parse function decorator precedence and standard literal parsing for untyped or non-string arguments. - Add regression test coverage in inspectutils_test.py and ire_test.py. Signed-off-by: Aryan Sachin <aryansachinixd@gmail.com>
Aryan9891
added a commit
to Aryan9891/Aryan9891
that referenced
this pull request
Nov 10, 2026
…google/python-fire#734 Signed-off-by: Aryan Sachin <aryansachinixd@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #733.
When a callable command function defines an argument with a string type hint (e.g., �rg: str or �rg: Optional[str]), passing a numerical or version-formatted string such as 1.10 or 123 causes DefaultParseValue to coerce the value via _LiteralEval into a float (1.1) or integer (123).
This is particularly problematic when handling software release versions, identifiers, zip codes, or semver strings where 1.1 has a fundamentally different meaning from 1.10.
Solution
Annotation Inspection (ire/inspectutils.py):
Targeted String Preservation (ire/core.py):
Regression Tests: