Repository navigation
Description
Numbers are the most used value objects and the base that later families build on: Port is an Int with two bounds, CvssScore and Money reuse the decimal parsing and places, and Percentage.of() scales Money. This block rebuilds them on the 1.0 core in one module, pyvalueobjects/numeric.py: an abstract Numeric base whose operators keep the left operand's concrete type and re-validate every result, the Int, Float and DecimalNumber families (each with its four sign variants as one-line Bounds declarations), and Percentage. Text goes through the core's ASCII literal() grammars, so from_str is exact for big integers and never accepts '1_000', '١٢', 'nan' or '1e3' for an int. Every Decimal operation runs in the library's own DECIMAL_CONTEXT, never in the caller's thread-local context. The last commit exports the new classes from the package root and deletes the 0.x number modules and their unittest suites, together with the Nullable* number classes.
Fixes items C09, C10, C11, C12, C13, C16, X02, X03, X04 and C14/C46/C54 of #34.
Tasks
- Add
Numericand theIntfamily (5 classes), with samples andtests/test_numeric.py. (ebf9872, cd2c88e, 750b31a, b141674, 7a8a34a) - Add the
Floatfamily (5 classes). (599951d, 1031aaa, 8953619) - Add
DECIMAL_CONTEXT,quantize_exactand theDecimalNumberfamily (5 classes, withplaces). (60e463f, f349545, 06080e9, 3b6593b) - Add
Percentagewithratioandof. (435f4b1) - Export the new numbers. Delete the legacy
numbers/modules and tests;_legacy/numbers/int.pysurvives because the legacy list tests import it. (0d135a8, 2aaaab0)
Related bugs
- Bugs: numeric parsing and validation (0.28.1) #34 C09:
Int.from_strparses throughfloatand silently changes integers above 2**53. - Bugs: numeric parsing and validation (0.28.1) #34 C10:
Int.from_straccepts non-integer strings that round or underflow to an integer ('0.99999999999999999','1e-400'). - Bugs: numeric parsing and validation (0.28.1) #34 C11:
Int.from_strrejects large integer strings that the constructor accepts ('1' * 400). - Bugs: numeric parsing and validation (0.28.1) #34 C12:
Int.from_strhas no input type check (bool,bytes,int,float,Decimal,IntEnum). - Bugs: numeric parsing and validation (0.28.1) #34 C13:
Int.from_str/from_floatreplace subclass validation errors with misleading format messages. - Bugs: numeric parsing and validation (0.28.1) #34 C16: bounded int constructors and
Int.from_float(inf/nan)report misleading messages. - Bugs: numeric parsing and validation (0.28.1) #34 X02:
Int.from_str/Float.from_straccept underscore-grouped, exponent (for ints) and non-ASCII-digit strings. - Bugs: numeric parsing and validation (0.28.1) #34 X03:
Float.from_intsilently rounds integers that are not exactly representable. - Bugs: numeric parsing and validation (0.28.1) #34 X04:
Intaccepts integers whose text form then raises a plainValueError(int max-str-digits limit). - Bugs: numeric parsing and validation (0.28.1) #34 C14/C46/C54: the
*from_str*_with_decimalstests callfrom_float, and the zero test passes aninttofrom_str, sofrom_strdecimal handling is untested.
Activity
Evaluate contract reprs against the public names of the package root. #…
Add Numeric and the Int family with its four sign variants. #41
Add Int.from_str on the exact ASCII integer grammar. #41
Add the Numeric operators and Int floor division and modulo. #41
Reject an Int with more digits than the interpreter can print. #41
Group the numeric tests by family, with the shared helpers first. #41
Add the Float family with its four sign variants. #41
Refuse an int that no float holds exactly in Float. #41
Add DECIMAL_CONTEXT and the DecimalNumber family with its sign varian…
Refuse a DecimalNumber that DECIMAL_CONTEXT cannot hold exactly. #41
Add quantize_exact, the places knob and DecimalNumber.rounded. #41
Print and format DecimalNumber in DECIMAL_CONTEXT. #41
Add Percentage with its exact ratio and of(). #41
Export the 1.0 numbers from the package root. #41
Delete the 0.x number classes and their unittest suites. #41