Skip to content

B3: Numbers #41

Open
Open

Description

@otsobide

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 Numeric and the Int family (5 classes), with samples and tests/test_numeric.py. (ebf9872, cd2c88e, 750b31a, b141674, 7a8a34a)
  • Add the Float family (5 classes). (599951d, 1031aaa, 8953619)
  • Add DECIMAL_CONTEXT, quantize_exact and the DecimalNumber family (5 classes, with places). (60e463f, f349545, 06080e9, 3b6593b)
  • Add Percentage with ratio and of. (435f4b1)
  • Export the new numbers. Delete the legacy numbers/ modules and tests; _legacy/numbers/int.py survives because the legacy list tests import it. (0d135a8, 2aaaab0)

Related bugs

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions