python-corekit 0.6.3__tar.gz → 0.6.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. {python_corekit-0.6.3/python_corekit.egg-info → python_corekit-0.6.4}/PKG-INFO +1 -1
  2. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/__init__.py +6 -0
  3. python_corekit-0.6.4/corekit/data/arithmetic/__init__.py +97 -0
  4. python_corekit-0.6.4/corekit/data/arithmetic/expression.py +449 -0
  5. python_corekit-0.6.4/corekit/data/arithmetic/keys.py +38 -0
  6. python_corekit-0.6.4/corekit/data/arithmetic/operator.py +44 -0
  7. python_corekit-0.6.4/corekit/data/expressions/__init__.py +96 -0
  8. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/expressions/comparison.py +78 -1
  9. python_corekit-0.6.4/corekit/data/expressions/expression.py +147 -0
  10. python_corekit-0.6.4/corekit/data/expressions/keys.py +34 -0
  11. python_corekit-0.6.4/corekit/data/expressions/operator.py +61 -0
  12. {python_corekit-0.6.3 → python_corekit-0.6.4}/pyproject.toml +1 -1
  13. {python_corekit-0.6.3 → python_corekit-0.6.4/python_corekit.egg-info}/PKG-INFO +1 -1
  14. {python_corekit-0.6.3 → python_corekit-0.6.4}/python_corekit.egg-info/SOURCES.txt +6 -0
  15. python_corekit-0.6.4/tests/test_arithmetic.py +125 -0
  16. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_expressions.py +69 -2
  17. python_corekit-0.6.3/corekit/data/expressions/__init__.py +0 -56
  18. python_corekit-0.6.3/corekit/data/expressions/expression.py +0 -71
  19. python_corekit-0.6.3/corekit/data/expressions/operator.py +0 -40
  20. {python_corekit-0.6.3 → python_corekit-0.6.4}/LICENSE +0 -0
  21. {python_corekit-0.6.3 → python_corekit-0.6.4}/README.md +0 -0
  22. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/__init__.py +0 -0
  23. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/__init__.py +0 -0
  24. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/application.py +0 -0
  25. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/handler.py +0 -0
  26. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/lifespan.py +0 -0
  27. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/middleware.py +0 -0
  28. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/responses.py +0 -0
  29. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/api/routers.py +0 -0
  30. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/concurrency/__init__.py +0 -0
  31. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/concurrency/decorators.py +0 -0
  32. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/concurrency/thread_local.py +0 -0
  33. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/concurrency/worker.py +0 -0
  34. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/config/__init__.py +0 -0
  35. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/config/loader.py +0 -0
  36. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/config/settings.py +0 -0
  37. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/config/sources.py +0 -0
  38. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/__init__.py +0 -0
  39. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/connectable.py +0 -0
  40. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/decorators.py +0 -0
  41. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/redis/__init__.py +0 -0
  42. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/redis/connection.py +0 -0
  43. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/registry.py +0 -0
  44. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/__init__.py +0 -0
  45. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/connection.py +0 -0
  46. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/fields/__init__.py +0 -0
  47. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/fields/jsonb.py +0 -0
  48. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/migration/__init__.py +0 -0
  49. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/migration/base.py +0 -0
  50. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/migration/operations.py +0 -0
  51. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/migration/registry.py +0 -0
  52. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/migration/table.py +0 -0
  53. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/operations/__init__.py +0 -0
  54. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/operations/base.py +0 -0
  55. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/operations/statements.py +0 -0
  56. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/query.py +0 -0
  57. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/connections/sql/table.py +0 -0
  58. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/crypto/__init__.py +0 -0
  59. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/crypto/constants.py +0 -0
  60. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/crypto/enum.py +0 -0
  61. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/crypto/hasher.py +0 -0
  62. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/dataset.py +0 -0
  63. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/expressions/target.py +0 -0
  64. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/record.py +0 -0
  65. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/data/stats.py +0 -0
  66. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/decorators/__init__.py +0 -0
  67. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/decorators/exception_handling.py +0 -0
  68. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/decorators/warnings.py +0 -0
  69. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/__init__.py +0 -0
  70. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/client.py +0 -0
  71. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/constants.py +0 -0
  72. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/disk/__init__.py +0 -0
  73. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/disk/constants.py +0 -0
  74. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/disk/inspector.py +0 -0
  75. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/disk/models.py +0 -0
  76. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/docker/watchdog.py +0 -0
  77. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/__init__.py +0 -0
  78. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/connection.py +0 -0
  79. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/extract/__init__.py +0 -0
  80. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/extract/extractor.py +0 -0
  81. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/extract/schemas.py +0 -0
  82. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/load/__init__.py +0 -0
  83. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/load/loader.py +0 -0
  84. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/load/schemas.py +0 -0
  85. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/orchestrator.py +0 -0
  86. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/schemas.py +0 -0
  87. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/transform/__init__.py +0 -0
  88. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/transform/schemas.py +0 -0
  89. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/etl/transform/transformer.py +0 -0
  90. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/__init__.py +0 -0
  91. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/enum.py +0 -0
  92. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/frames.py +0 -0
  93. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/models.py +0 -0
  94. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/publisher.py +0 -0
  95. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/reader.py +0 -0
  96. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/sse.py +0 -0
  97. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/events/websocket.py +0 -0
  98. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/__init__.py +0 -0
  99. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/actions.py +0 -0
  100. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/asgi.py +0 -0
  101. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/constants.py +0 -0
  102. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/exceptionator.py +0 -0
  103. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/fingerprint.py +0 -0
  104. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/guard.py +0 -0
  105. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/jobs.py +0 -0
  106. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptionator/models.py +0 -0
  107. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/__init__.py +0 -0
  108. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/base.py +0 -0
  109. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/custom/__init__.py +0 -0
  110. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/enum.py +0 -0
  111. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/http/__init__.py +0 -0
  112. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/exceptions/types.py +0 -0
  113. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/__init__.py +0 -0
  114. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/base.py +0 -0
  115. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/disk.py +0 -0
  116. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/enum.py +0 -0
  117. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/json.py +0 -0
  118. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/files/toml.py +0 -0
  119. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/__init__.py +0 -0
  120. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/client.py +0 -0
  121. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/models.py +0 -0
  122. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/parser.py +0 -0
  123. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/scraper.py +0 -0
  124. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/settings.py +0 -0
  125. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/html/state.py +0 -0
  126. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/__init__.py +0 -0
  127. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/api.py +0 -0
  128. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/client.py +0 -0
  129. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/exceptions.py +0 -0
  130. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/exponential_backoff.py +0 -0
  131. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/response.py +0 -0
  132. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/status.py +0 -0
  133. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/http/stream.py +0 -0
  134. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/__init__.py +0 -0
  135. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/adapter.py +0 -0
  136. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/loader.py +0 -0
  137. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/normalizer.py +0 -0
  138. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/pipeline.py +0 -0
  139. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/integrations/schemas.py +0 -0
  140. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/jobs/__init__.py +0 -0
  141. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/jobs/registry.py +0 -0
  142. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/jobs/runner.py +0 -0
  143. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/jobs/task.py +0 -0
  144. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/__init__.py +0 -0
  145. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/client.py +0 -0
  146. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/enum.py +0 -0
  147. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/events.py +0 -0
  148. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/messages.py +0 -0
  149. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/prompts/__init__.py +0 -0
  150. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/prompts/enum.py +0 -0
  151. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/prompts/exceptions.py +0 -0
  152. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/prompts/loader.py +0 -0
  153. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/prompts/template.py +0 -0
  154. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/protocols.py +0 -0
  155. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/streaming.py +0 -0
  156. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/tools/__init__.py +0 -0
  157. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/tools/base.py +0 -0
  158. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/tools/detection.py +0 -0
  159. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/tools/loop.py +0 -0
  160. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/tools/registry.py +0 -0
  161. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/llm/wire.py +0 -0
  162. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/log_monitor/__init__.py +0 -0
  163. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/log_monitor/constants.py +0 -0
  164. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/log_monitor/models.py +0 -0
  165. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/log_monitor/service.py +0 -0
  166. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/notifications/__init__.py +0 -0
  167. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/notifications/base.py +0 -0
  168. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/notifications/models.py +0 -0
  169. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/__init__.py +0 -0
  170. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/benchmarkable.py +0 -0
  171. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/loggable.py +0 -0
  172. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/request_context.py +0 -0
  173. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/timing/__init__.py +0 -0
  174. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/timing/constants.py +0 -0
  175. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/timing/split.py +0 -0
  176. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/observability/timing/timer.py +0 -0
  177. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/process/__init__.py +0 -0
  178. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/process/runner.py +0 -0
  179. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/py.typed +0 -0
  180. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/registry/__init__.py +0 -0
  181. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/registry/ordered.py +0 -0
  182. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/registry/registry.py +0 -0
  183. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/__init__.py +0 -0
  184. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/dataclasses/__init__.py +0 -0
  185. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/enum.py +0 -0
  186. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/models/__init__.py +0 -0
  187. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/models/arbitrary.py +0 -0
  188. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/models/date_models.py +0 -0
  189. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/pydantic/__init__.py +0 -0
  190. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/pydantic/fields.py +0 -0
  191. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/size.py +0 -0
  192. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/types.py +0 -0
  193. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/schemas/version.py +0 -0
  194. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/serialization/__init__.py +0 -0
  195. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/serialization/enum.py +0 -0
  196. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/serialization/pickle_file.py +0 -0
  197. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/serialization/serializable.py +0 -0
  198. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/serialization/serializer.py +0 -0
  199. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/__init__.py +0 -0
  200. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/coercion.py +0 -0
  201. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/collections.py +0 -0
  202. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/ids.py +0 -0
  203. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/parsers.py +0 -0
  204. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/payload.py +0 -0
  205. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/raise_exc.py +0 -0
  206. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/text.py +0 -0
  207. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/time.py +0 -0
  208. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/validators.py +0 -0
  209. {python_corekit-0.6.3 → python_corekit-0.6.4}/corekit/utils/void.py +0 -0
  210. {python_corekit-0.6.3 → python_corekit-0.6.4}/python_corekit.egg-info/dependency_links.txt +0 -0
  211. {python_corekit-0.6.3 → python_corekit-0.6.4}/python_corekit.egg-info/requires.txt +0 -0
  212. {python_corekit-0.6.3 → python_corekit-0.6.4}/python_corekit.egg-info/top_level.txt +0 -0
  213. {python_corekit-0.6.3 → python_corekit-0.6.4}/setup.cfg +0 -0
  214. {python_corekit-0.6.3 → python_corekit-0.6.4}/setup.py +0 -0
  215. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_api.py +0 -0
  216. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_application.py +0 -0
  217. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_architecture.py +0 -0
  218. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_concurrency.py +0 -0
  219. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_config.py +0 -0
  220. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_connections.py +0 -0
  221. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_data.py +0 -0
  222. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_docker.py +0 -0
  223. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_etl.py +0 -0
  224. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_events.py +0 -0
  225. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_exceptionator.py +0 -0
  226. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_exceptions.py +0 -0
  227. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_expressions_sqlalchemy.py +0 -0
  228. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_files.py +0 -0
  229. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_html.py +0 -0
  230. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_imports.py +0 -0
  231. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_imports_are_top_level.py +0 -0
  232. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_integrations.py +0 -0
  233. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_jobs.py +0 -0
  234. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_lifespan.py +0 -0
  235. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_llm.py +0 -0
  236. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_log_monitor.py +0 -0
  237. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_middleware_stack.py +0 -0
  238. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_migration.py +0 -0
  239. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_notifications.py +0 -0
  240. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_observability.py +0 -0
  241. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_operations.py +0 -0
  242. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_ordered_registry.py +0 -0
  243. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_process.py +0 -0
  244. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_redis.py +0 -0
  245. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_registry.py +0 -0
  246. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_request_context.py +0 -0
  247. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_requests.py +0 -0
  248. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_schemas_arbitrary.py +0 -0
  249. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_schemas_enum.py +0 -0
  250. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_schemas_size.py +0 -0
  251. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_serialization.py +0 -0
  252. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_sql.py +0 -0
  253. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils.py +0 -0
  254. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_coercion.py +0 -0
  255. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_collections.py +0 -0
  256. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_ids.py +0 -0
  257. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_parsers.py +0 -0
  258. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_payload.py +0 -0
  259. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_text.py +0 -0
  260. {python_corekit-0.6.3 → python_corekit-0.6.4}/tests/test_utils_time.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-corekit
3
- Version: 0.6.3
3
+ Version: 0.6.4
4
4
  Summary: Shared foundations for Python projects: logging, benchmarking, registries, FastAPI application and routers, SQL statements and migrations, background tasks, ETL, LLM chat/tool primitives, and HTML scraping
5
5
  Author: Steven Jacobsen
6
6
  License-Expression: MIT
@@ -27,6 +27,9 @@ from corekit.data.expressions import (
27
27
  Dialect,
28
28
  Equals,
29
29
  Expression,
30
+ ExpressionField,
31
+ ExpressionKey,
32
+ ExpressionType,
30
33
  FieldExpression,
31
34
  GreaterThan,
32
35
  GreaterThanOrEquals,
@@ -67,6 +70,9 @@ __all__ = [
67
70
  "DatasetStats",
68
71
  "Equals",
69
72
  "Expression",
73
+ "ExpressionField",
74
+ "ExpressionKey",
75
+ "ExpressionType",
70
76
  "Field",
71
77
  "FieldDescription",
72
78
  "FieldExpression",
@@ -0,0 +1,97 @@
1
+ """
2
+ Composable arithmetic expression trees.
3
+
4
+ Build with ``Field`` / ``Literal`` and operator overloads, evaluate against a
5
+ context, and round-trip with ``to_dict`` / ``from_dict``::
6
+
7
+ from corekit.data.arithmetic import Field
8
+
9
+ total = ((Field("pad_cost") * Field("pad_qty")) + (Field("labor_rate") * Field("hours"))).round()
10
+ """
11
+
12
+ from typing import Annotated, Any
13
+
14
+ from pydantic import GetCoreSchemaHandler
15
+ from pydantic_core import core_schema
16
+
17
+ from corekit.data.arithmetic.expression import (
18
+ Abs,
19
+ Add,
20
+ ArithmeticExpression,
21
+ Ceil,
22
+ Divide,
23
+ Field,
24
+ Floor,
25
+ Literal,
26
+ Max,
27
+ Min,
28
+ Modulo,
29
+ Multiply,
30
+ Negate,
31
+ Percent,
32
+ PercentOf,
33
+ Power,
34
+ Round,
35
+ Subtract,
36
+ UnknownArithmeticFieldError,
37
+ coerce,
38
+ )
39
+ from corekit.data.arithmetic.keys import ArithmeticKey, ArithmeticType
40
+ from corekit.data.arithmetic.operator import ArithmeticOperator
41
+
42
+
43
+ class _ArithmeticExpressionPydanticAnnotation:
44
+ """
45
+ Pydantic marker so ``ArithmeticExpression`` nests in BaseModels.
46
+ """
47
+
48
+ @classmethod
49
+ def __get_pydantic_core_schema__(
50
+ cls,
51
+ _source_type: Any,
52
+ _handler: GetCoreSchemaHandler,
53
+ ) -> core_schema.CoreSchema:
54
+ def validate(value: Any) -> ArithmeticExpression:
55
+ if isinstance(value, ArithmeticExpression):
56
+ return value
57
+ if isinstance(value, dict):
58
+ return ArithmeticExpression.from_dict(value)
59
+ raise TypeError(f"Expected ArithmeticExpression or dict, got {type(value)!r}")
60
+
61
+ return core_schema.no_info_plain_validator_function(
62
+ validate,
63
+ serialization=core_schema.plain_serializer_function_ser_schema(
64
+ lambda value: value.to_dict(),
65
+ when_used="always",
66
+ ),
67
+ )
68
+
69
+
70
+ ArithmeticExpressionField = Annotated[ArithmeticExpression, _ArithmeticExpressionPydanticAnnotation]
71
+
72
+ __all__ = [
73
+ "Abs",
74
+ "Add",
75
+ "ArithmeticExpression",
76
+ "ArithmeticExpressionField",
77
+ "ArithmeticKey",
78
+ "ArithmeticOperator",
79
+ "ArithmeticType",
80
+ "Ceil",
81
+ "Divide",
82
+ "Field",
83
+ "Floor",
84
+ "Literal",
85
+ "Max",
86
+ "Min",
87
+ "Modulo",
88
+ "Multiply",
89
+ "Negate",
90
+ "Percent",
91
+ "PercentOf",
92
+ "Power",
93
+ "Round",
94
+ "Subtract",
95
+ "UnknownArithmeticFieldError",
96
+ "coerce",
97
+ ]
@@ -0,0 +1,449 @@
1
+ """
2
+ Composable arithmetic expression trees.
3
+
4
+ Evaluate against a context (mapping / object) to a ``float``. Serialize with
5
+ ``to_dict`` / ``from_dict``. Build trees with operator overloads on ``Field`` /
6
+ ``Literal``::
7
+
8
+ from corekit.data.arithmetic import Field
9
+
10
+ total = (
11
+ (Field("pad_cost") * Field("pad_qty"))
12
+ + (Field("labor_rate") * Field("hours"))
13
+ ).round()
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import math
19
+ from typing import Any
20
+
21
+ from corekit.data.arithmetic.keys import ArithmeticKey, ArithmeticType
22
+ from corekit.data.arithmetic.operator import ArithmeticOperator
23
+ from corekit.exceptions import InternalCoreException
24
+ from corekit.utils import parse_float
25
+
26
+ UNSET = object()
27
+ _DEFAULT_ROUND_DIGITS = 2
28
+
29
+
30
+ class UnknownArithmeticFieldError(InternalCoreException):
31
+ """
32
+ Raised when an arithmetic field names a key the context does not have.
33
+ """
34
+
35
+
36
+ class ArithmeticExpression:
37
+ """
38
+ Base for numeric expression nodes. Subclasses implement ``__call__`` and
39
+ ``to_dict``.
40
+ """
41
+
42
+ def __call__(self, context: Any = None) -> float:
43
+ raise NotImplementedError
44
+
45
+ def to_dict(self) -> dict[str, Any]:
46
+ raise NotImplementedError
47
+
48
+ @classmethod
49
+ def from_dict(cls, data: dict[str, Any] | ArithmeticExpression) -> ArithmeticExpression:
50
+ if isinstance(data, ArithmeticExpression):
51
+ return data
52
+ if not isinstance(data, dict):
53
+ raise TypeError(f"ArithmeticExpression.from_dict expected a dict, got {type(data)!r}")
54
+
55
+ kind = data.get(ArithmeticKey.TYPE)
56
+ if kind == ArithmeticType.FIELD:
57
+ return Field.from_dict(data)
58
+ if kind == ArithmeticType.LITERAL:
59
+ return Literal.from_dict(data)
60
+ if kind == ArithmeticType.NEGATE:
61
+ return Negate.from_dict(data)
62
+ if kind == ArithmeticType.ABS:
63
+ return Abs.from_dict(data)
64
+ if kind == ArithmeticType.PERCENT:
65
+ return Percent.from_dict(data)
66
+ if kind == ArithmeticType.ROUND:
67
+ return Round.from_dict(data)
68
+ if kind == ArithmeticType.FLOOR:
69
+ return Floor.from_dict(data)
70
+ if kind == ArithmeticType.CEIL:
71
+ return Ceil.from_dict(data)
72
+ return BinaryOperation.from_dict(data)
73
+
74
+ def __add__(self, other: Any) -> Add:
75
+ return Add(self, coerce(other))
76
+
77
+ def __radd__(self, other: Any) -> Add:
78
+ return Add(coerce(other), self)
79
+
80
+ def __sub__(self, other: Any) -> Subtract:
81
+ return Subtract(self, coerce(other))
82
+
83
+ def __rsub__(self, other: Any) -> Subtract:
84
+ return Subtract(coerce(other), self)
85
+
86
+ def __mul__(self, other: Any) -> Multiply:
87
+ return Multiply(self, coerce(other))
88
+
89
+ def __rmul__(self, other: Any) -> Multiply:
90
+ return Multiply(coerce(other), self)
91
+
92
+ def __truediv__(self, other: Any) -> Divide:
93
+ return Divide(self, coerce(other))
94
+
95
+ def __rtruediv__(self, other: Any) -> Divide:
96
+ return Divide(coerce(other), self)
97
+
98
+ def __mod__(self, other: Any) -> Modulo:
99
+ return Modulo(self, coerce(other))
100
+
101
+ def __rmod__(self, other: Any) -> Modulo:
102
+ return Modulo(coerce(other), self)
103
+
104
+ def __pow__(self, other: Any) -> Power:
105
+ return Power(self, coerce(other))
106
+
107
+ def __rpow__(self, other: Any) -> Power:
108
+ return Power(coerce(other), self)
109
+
110
+ def __neg__(self) -> Negate:
111
+ return Negate(self)
112
+
113
+ def __abs__(self) -> Abs:
114
+ return Abs(self)
115
+
116
+ def min(self, other: Any) -> Min:
117
+ return Min(self, coerce(other))
118
+
119
+ def max(self, other: Any) -> Max:
120
+ return Max(self, coerce(other))
121
+
122
+ def percent_of(self, base: Any) -> PercentOf:
123
+ """
124
+ ``self`` as a percent of ``base`` (e.g. ``Field("rate").percent_of(Field("price"))``).
125
+ """
126
+ return PercentOf(self, coerce(base))
127
+
128
+ def percent(self) -> Percent:
129
+ """
130
+ Convert a percentage number to a ratio (``20`` → ``0.2``).
131
+ """
132
+ return Percent(self)
133
+
134
+ def round(self, digits: int = _DEFAULT_ROUND_DIGITS) -> Round:
135
+ return Round(self, digits=digits)
136
+
137
+ def floor(self, digits: int = _DEFAULT_ROUND_DIGITS) -> Floor:
138
+ return Floor(self, digits=digits)
139
+
140
+ def ceil(self, digits: int = _DEFAULT_ROUND_DIGITS) -> Ceil:
141
+ return Ceil(self, digits=digits)
142
+
143
+
144
+ def coerce(value: Any) -> ArithmeticExpression:
145
+ if isinstance(value, ArithmeticExpression):
146
+ return value
147
+ if isinstance(value, (int, float)) and not isinstance(value, bool):
148
+ return Literal(value)
149
+ raise TypeError(f"Cannot use {type(value)!r} in an arithmetic expression")
150
+
151
+
152
+ class Literal(ArithmeticExpression):
153
+ def __init__(self, value: Any) -> None:
154
+ self.value = value
155
+
156
+ def __repr__(self) -> str:
157
+ return f"{self.value!r}"
158
+
159
+ def __call__(self, context: Any = None) -> float:
160
+ parsed = parse_float(self.value)
161
+ if not parsed.success:
162
+ raise ValueError(f"Arithmetic literal must be numeric, got {self.value!r}")
163
+ return parsed.value
164
+
165
+ def to_dict(self) -> dict[str, Any]:
166
+ return {
167
+ ArithmeticKey.TYPE: ArithmeticType.LITERAL,
168
+ ArithmeticKey.VALUE: self.value,
169
+ }
170
+
171
+ @classmethod
172
+ def from_dict(cls, data: dict[str, Any]) -> Literal:
173
+ return cls(data.get(ArithmeticKey.VALUE))
174
+
175
+
176
+ class Field(ArithmeticExpression):
177
+ def __init__(self, name: str) -> None:
178
+ self.name = name
179
+
180
+ def __repr__(self) -> str:
181
+ return f"Field({self.name!r})"
182
+
183
+ def __call__(self, context: Any = None) -> float:
184
+ raw = self.resolve(context)
185
+ parsed = parse_float(raw)
186
+ if not parsed.success:
187
+ raise ValueError(f"Arithmetic field {self.name!r} must be numeric, got {raw!r}")
188
+ return parsed.value
189
+
190
+ def resolve(self, context: Any = None) -> Any:
191
+ if context is None:
192
+ raise UnknownArithmeticFieldError(f"No context to resolve field {self.name!r}")
193
+
194
+ getter = getattr(context, "__getitem__", None)
195
+ if getter is not None:
196
+ try:
197
+ return getter(self.name)
198
+ except (KeyError, IndexError, TypeError):
199
+ pass
200
+
201
+ value = getattr(context, self.name, UNSET)
202
+ if value is UNSET:
203
+ raise UnknownArithmeticFieldError(f"{context!r} has no field {self.name!r}")
204
+ return value
205
+
206
+ def to_dict(self) -> dict[str, Any]:
207
+ return {
208
+ ArithmeticKey.TYPE: ArithmeticType.FIELD,
209
+ ArithmeticKey.NAME: self.name,
210
+ }
211
+
212
+ @classmethod
213
+ def from_dict(cls, data: dict[str, Any]) -> Field:
214
+ name = data.get(ArithmeticKey.NAME)
215
+ if not isinstance(name, str) or not name:
216
+ raise ValueError("Arithmetic field requires a non-empty string name")
217
+ return cls(name)
218
+
219
+
220
+ class BinaryOperation(ArithmeticExpression):
221
+ """
222
+ Base for binary arithmetic nodes. Subclasses set ``operator`` and ``evaluate``.
223
+ """
224
+
225
+ operator: ArithmeticOperator
226
+
227
+ def __init__(self, left: ArithmeticExpression, right: ArithmeticExpression) -> None:
228
+ self.left = left
229
+ self.right = right
230
+
231
+ def __repr__(self) -> str:
232
+ return f"({self.left!r} {self.operator.symbol} {self.right!r})"
233
+
234
+ def evaluate(self, left: float, right: float) -> float:
235
+ raise NotImplementedError
236
+
237
+ def __call__(self, context: Any = None) -> float:
238
+ return self.evaluate(self.left(context), self.right(context))
239
+
240
+ def to_dict(self) -> dict[str, Any]:
241
+ return {
242
+ ArithmeticKey.TYPE: self.operator.serialized,
243
+ ArithmeticKey.LEFT: self.left.to_dict(),
244
+ ArithmeticKey.RIGHT: self.right.to_dict(),
245
+ }
246
+
247
+ @classmethod
248
+ def from_dict(cls, data: dict[str, Any]) -> BinaryOperation:
249
+ operator = ArithmeticOperator.from_serialized(data[ArithmeticKey.TYPE])
250
+ for subclass in cls.__subclasses__():
251
+ if subclass.operator is operator:
252
+ return subclass(
253
+ ArithmeticExpression.from_dict(data[ArithmeticKey.LEFT]),
254
+ ArithmeticExpression.from_dict(data[ArithmeticKey.RIGHT]),
255
+ )
256
+ raise ValueError(f"No arithmetic class registered for operator {operator!r}")
257
+
258
+
259
+ class Add(BinaryOperation):
260
+ operator = ArithmeticOperator.ADD
261
+
262
+ def evaluate(self, left: float, right: float) -> float:
263
+ return left + right
264
+
265
+
266
+ class Subtract(BinaryOperation):
267
+ operator = ArithmeticOperator.SUBTRACT
268
+
269
+ def evaluate(self, left: float, right: float) -> float:
270
+ return left - right
271
+
272
+
273
+ class Multiply(BinaryOperation):
274
+ operator = ArithmeticOperator.MULTIPLY
275
+
276
+ def evaluate(self, left: float, right: float) -> float:
277
+ return left * right
278
+
279
+
280
+ class Divide(BinaryOperation):
281
+ operator = ArithmeticOperator.DIVIDE
282
+
283
+ def evaluate(self, left: float, right: float) -> float:
284
+ if right == 0:
285
+ raise ValueError("Division by zero")
286
+ return left / right
287
+
288
+
289
+ class Modulo(BinaryOperation):
290
+ operator = ArithmeticOperator.MODULO
291
+
292
+ def evaluate(self, left: float, right: float) -> float:
293
+ if right == 0:
294
+ raise ValueError("Modulo by zero")
295
+ return left % right
296
+
297
+
298
+ class Power(BinaryOperation):
299
+ operator = ArithmeticOperator.POWER
300
+
301
+ def evaluate(self, left: float, right: float) -> float:
302
+ return left**right
303
+
304
+
305
+ class Min(BinaryOperation):
306
+ operator = ArithmeticOperator.MIN
307
+
308
+ def evaluate(self, left: float, right: float) -> float:
309
+ return min(left, right)
310
+
311
+
312
+ class Max(BinaryOperation):
313
+ operator = ArithmeticOperator.MAX
314
+
315
+ def evaluate(self, left: float, right: float) -> float:
316
+ return max(left, right)
317
+
318
+
319
+ class PercentOf(BinaryOperation):
320
+ """
321
+ ``left`` percent of ``right`` → ``right * left / 100``.
322
+ """
323
+
324
+ operator = ArithmeticOperator.PERCENT_OF
325
+
326
+ def evaluate(self, left: float, right: float) -> float:
327
+ return right * left / 100.0
328
+
329
+
330
+ class UnaryOperation(ArithmeticExpression):
331
+ type_tag: ArithmeticType
332
+
333
+ def __init__(self, expr: ArithmeticExpression) -> None:
334
+ self.expr = expr
335
+
336
+ def evaluate(self, value: float) -> float:
337
+ raise NotImplementedError
338
+
339
+ def __call__(self, context: Any = None) -> float:
340
+ return self.evaluate(self.expr(context))
341
+
342
+ def to_dict(self) -> dict[str, Any]:
343
+ return {
344
+ ArithmeticKey.TYPE: self.type_tag,
345
+ ArithmeticKey.EXPR: self.expr.to_dict(),
346
+ }
347
+
348
+ @classmethod
349
+ def from_dict(cls, data: dict[str, Any]) -> UnaryOperation:
350
+ return cls(ArithmeticExpression.from_dict(data[ArithmeticKey.EXPR]))
351
+
352
+
353
+ class Negate(UnaryOperation):
354
+ type_tag = ArithmeticType.NEGATE
355
+
356
+ def __repr__(self) -> str:
357
+ return f"-{self.expr!r}"
358
+
359
+ def evaluate(self, value: float) -> float:
360
+ return -value
361
+
362
+
363
+ class Abs(UnaryOperation):
364
+ type_tag = ArithmeticType.ABS
365
+
366
+ def __repr__(self) -> str:
367
+ return f"abs({self.expr!r})"
368
+
369
+ def evaluate(self, value: float) -> float:
370
+ return abs(value)
371
+
372
+
373
+ class Percent(UnaryOperation):
374
+ """
375
+ Convert a percentage number to a ratio (``20`` → ``0.2``).
376
+ """
377
+
378
+ type_tag = ArithmeticType.PERCENT
379
+
380
+ def __repr__(self) -> str:
381
+ return f"percent({self.expr!r})"
382
+
383
+ def evaluate(self, value: float) -> float:
384
+ return value / 100.0
385
+
386
+
387
+ class RoundedOperation(ArithmeticExpression):
388
+ """
389
+ Round / floor / ceil to a fixed number of decimal places (default 2).
390
+ """
391
+
392
+ type_tag: ArithmeticType
393
+
394
+ def __init__(self, expr: ArithmeticExpression, digits: int = _DEFAULT_ROUND_DIGITS) -> None:
395
+ self.expr = expr
396
+ self.digits = int(digits)
397
+
398
+ def apply(self, value: float) -> float:
399
+ raise NotImplementedError
400
+
401
+ def scale(self) -> float:
402
+ return 10.0**self.digits
403
+
404
+ def __call__(self, context: Any = None) -> float:
405
+ return self.apply(self.expr(context))
406
+
407
+ def to_dict(self) -> dict[str, Any]:
408
+ return {
409
+ ArithmeticKey.TYPE: self.type_tag,
410
+ ArithmeticKey.EXPR: self.expr.to_dict(),
411
+ ArithmeticKey.DIGITS: self.digits,
412
+ }
413
+
414
+ @classmethod
415
+ def from_dict(cls, data: dict[str, Any]) -> RoundedOperation:
416
+ digits = data.get(ArithmeticKey.DIGITS, _DEFAULT_ROUND_DIGITS)
417
+ return cls(ArithmeticExpression.from_dict(data[ArithmeticKey.EXPR]), digits=int(digits))
418
+
419
+
420
+ class Round(RoundedOperation):
421
+ type_tag = ArithmeticType.ROUND
422
+
423
+ def __repr__(self) -> str:
424
+ return f"round({self.expr!r}, {self.digits})"
425
+
426
+ def apply(self, value: float) -> float:
427
+ return round(value, self.digits)
428
+
429
+
430
+ class Floor(RoundedOperation):
431
+ type_tag = ArithmeticType.FLOOR
432
+
433
+ def __repr__(self) -> str:
434
+ return f"floor({self.expr!r}, {self.digits})"
435
+
436
+ def apply(self, value: float) -> float:
437
+ factor = self.scale()
438
+ return math.floor(value * factor) / factor
439
+
440
+
441
+ class Ceil(RoundedOperation):
442
+ type_tag = ArithmeticType.CEIL
443
+
444
+ def __repr__(self) -> str:
445
+ return f"ceil({self.expr!r}, {self.digits})"
446
+
447
+ def apply(self, value: float) -> float:
448
+ factor = self.scale()
449
+ return math.ceil(value * factor) / factor
@@ -0,0 +1,38 @@
1
+ """
2
+ Stable serialization tags and dict keys for arithmetic expression trees.
3
+ """
4
+
5
+ from corekit.schemas.enum import StringEnum
6
+
7
+ __all__ = ["ArithmeticKey", "ArithmeticType"]
8
+
9
+
10
+ class ArithmeticType(StringEnum):
11
+ """
12
+ Node kind for non-binary arithmetic nodes.
13
+
14
+ Binary ops use ``ArithmeticOperator.serialized`` instead.
15
+ """
16
+
17
+ FIELD = "field"
18
+ LITERAL = "literal"
19
+ NEGATE = "negate"
20
+ ABS = "abs"
21
+ PERCENT = "percent"
22
+ ROUND = "round"
23
+ FLOOR = "floor"
24
+ CEIL = "ceil"
25
+
26
+
27
+ class ArithmeticKey(StringEnum):
28
+ """
29
+ Dict keys used by ``ArithmeticExpression.to_dict`` / ``from_dict``.
30
+ """
31
+
32
+ TYPE = "type"
33
+ LEFT = "left"
34
+ RIGHT = "right"
35
+ EXPR = "expr"
36
+ NAME = "name"
37
+ VALUE = "value"
38
+ DIGITS = "digits"
@@ -0,0 +1,44 @@
1
+ """
2
+ Binary arithmetic operators.
3
+ """
4
+
5
+ from corekit.data.expressions.operator import Dialect
6
+ from corekit.schemas.enum import ValidatingEnum
7
+
8
+ __all__ = ["ArithmeticOperator"]
9
+
10
+
11
+ class ArithmeticOperator(ValidatingEnum):
12
+ """
13
+ A binary arithmetic operator, identified by the node class that uses it.
14
+ """
15
+
16
+ ADD = Dialect("+", "add")
17
+ SUBTRACT = Dialect("-", "subtract")
18
+ MULTIPLY = Dialect("*", "multiply")
19
+ DIVIDE = Dialect("/", "divide")
20
+ MODULO = Dialect("%", "modulo")
21
+ POWER = Dialect("**", "power")
22
+ MIN = Dialect("min", "min")
23
+ MAX = Dialect("max", "max")
24
+ PERCENT_OF = Dialect("% of", "percent_of")
25
+
26
+ @property
27
+ def symbol(self) -> str:
28
+ return self.value.symbol
29
+
30
+ @property
31
+ def serialized(self) -> str:
32
+ """
33
+ Stable type tag for ``to_dict`` / ``from_dict`` (``Dialect.name``).
34
+
35
+ Named ``serialized`` so it does not shadow ``Enum.name``.
36
+ """
37
+ return self.value.name
38
+
39
+ @classmethod
40
+ def from_serialized(cls, name: str) -> "ArithmeticOperator":
41
+ for member in cls:
42
+ if member.serialized == name:
43
+ return member
44
+ raise ValueError(f"Unknown arithmetic operator serialization {name!r}")