@@ -1245,42 +1245,27 @@ def _validate_target_runtime_seconds(cls, value: Any, info: ValidationInfo) -> A
12451245 return validate_int_fmtstring_field (value , ge = 0 , context = context )
12461246
12471247
1248- # Redundant leading zeros in the integer digits of a numeric string, keeping any
1249- # sign and always leaving one digit behind: '02.50' -> '2.50', '007' -> '7',
1250- # '000' -> '0'. The lookahead is what leaves the last digit, and it also declines
1251- # to touch '0.50', whose single zero is not redundant.
1248+ # '02.50' -> '2.50', '007' -> '7', '000' -> '0'. The lookahead leaves the last
1249+ # digit, so '0.50' keeps the zero that is its integer part.
12521250_REDUNDANT_LEADING_ZEROS = re .compile (r"^([+-]?)0+(?=[0-9])" )
12531251
12541252
12551253def _normalized_range_element (elem : str , to_int : bool ) -> Any :
12561254 """The value an ``<intstring>``/``<floatstring>`` range element denotes.
12571255
1258- An ``<intstring>`` becomes the ``int`` it denotes. A ``<floatstring>`` keeps
1259- its source text, less any redundant leading zeros, because the number of
1260- fractional digits it was written with is part of what it asks for -- an
1261- element written ``'2.50'`` is asking for ``2.50`` on the command line, and a
1262- renderer told ``2.5`` instead has been given a different string. Returns the
1263- element unchanged when it does not denote a number.
1256+ An ``<intstring>`` becomes an ``int``. A ``<floatstring>`` keeps its text less
1257+ redundant leading zeros, so the decimal places it was written with survive
1258+ (§7.5). Returns the element unchanged when it does not denote a number.
12641259 """
12651260 try :
12661261 if to_int :
1267- # int() ignores leading zeros, and an <intstring> has no fractional
1268- # digits to preserve, so the parsed value carries everything.
1269- return int (elem )
1270- # A <floatstring> renders as text, so the parse is only a check that the
1271- # element denotes a float at all. Deliberately not carried in a Decimal:
1272- # rendering one requires choosing a notation, and every choice available
1273- # is either context-sensitive (``normalize`` and ``quantize`` round to
1274- # ``getcontext().prec``), notation-unstable (``str`` switches to an
1275- # exponent below 1e-6), or unbounded in the exponent (``format(v, 'f')``
1276- # expands '1e999999999' to ~10**9 characters). Text needs none of those
1277- # decisions: it renders as the author wrote it.
1262+ return int (elem ) # int() already drops leading zeros
1263+ # Parsed only to check it is a number; the text is what renders. Not a
1264+ # Decimal -- re-rendering one is context-sensitive and unbounded (§7.5).
12781265 float (elem )
12791266 except ValueError :
1280- # Not a number at all -- e.g. a format string that resolved to
1281- # non-numeric text. A literal range is already checked against its
1282- # element type at template parse time, so leave such a value to the
1283- # existing behaviour rather than adding a rejection path here.
1267+ # A resolved format string can be non-numeric. Literals are checked at
1268+ # template parse time, so carry it through rather than rejecting here.
12841269 return elem
12851270 return _REDUNDANT_LEADING_ZEROS .sub (r"\1" , elem )
12861271
@@ -1297,27 +1282,14 @@ class RangeListTaskParameterDefinition(OpenJDModel_v2023_09):
12971282 @field_validator ("range" , mode = "before" )
12981283 @classmethod
12991284 def _normalize_numeric_range_elements (cls , value : Any , info : ValidationInfo ) -> Any :
1300- # §3.4.1.1/§3.4.1.2: an <IntRangeList> element is `<integer> |
1301- # <intstring>` and a <FloatRangeList> element is `<float> |
1302- # <floatstring>`, where an <intstring>/<floatstring> is "a string whose
1303- # value is the string representation of" a number (§2.3, §2.4). Leading
1304- # zeros are not part of the number such an element denotes, and Python
1305- # was keeping them, which reaches a task command line as `--frame 02`.
1285+ # §7.5: a string-form range element loses redundant leading zeros and
1286+ # keeps its decimal places, so '02' is the value 2 and '02.50' renders
1287+ # `2.50`. Numeric literals carry no such request and are left as parsed;
1288+ # STRING and PATH ranges have no numeric form at all.
13061289 #
1307- # Trailing zeros are kept. They are the reason the string form exists:
1308- # a <floatstring> is how a template asks for a fixed number of decimal
1309- # places, so '2.50' must render `2.50` and not `2.5`. The already-landed
1310- # EXPR/jobs/expr1.3.4--float-passthrough fixture pins the same rule for
1311- # a FLOAT parameter default.
1312- #
1313- # Applied on the instantiation target so every inbound range path is
1314- # covered: a literal list, a range-expression expansion, and an RFC 0006
1315- # typed whole-field resolution all funnel through this model.
1316- #
1317- # Numeric elements are left exactly as parsed. A FLOAT range of [1.0]
1318- # renders 1.0, which openjd-rs also does and the conformance suite pins
1319- # (base/jobs/3.4--float-parameter). STRING and PATH ranges are text by
1320- # definition and are never touched.
1290+ # On the instantiation target so all three inbound paths are covered: a
1291+ # literal list, a range-expression expansion, and RFC 0006 whole-field
1292+ # resolution.
13211293 param_type = info .data .get ("type" )
13221294 if not isinstance (value , list ) or param_type not in (
13231295 TaskParameterType .INT ,
0 commit comments