Conversation
Closed
8ec24bf to
4e4c042
Compare
sbrodehl
reviewed
Nov 15, 2021
| self.converter = converter_fn | ||
|
|
||
| def __call__(self, value, unit): | ||
| if " in " in unit: |
Collaborator
There was a problem hiding this comment.
in can be a variable so that it can be set easier. Is a regex necessary, or is the str compare sufficient?
86f4401 to
df1b7be
Compare
sbrodehl
approved these changes
Dec 21, 2022
Closed
3829fae to
f81418a
Compare
tests: added conversion tests tests: adapted unit-feature tests
Owner
Author
|
I am quite confident and positive towards the current design decisions, having it tried already in a testing environment of larger scale. ;) Unfortunately, there is still one thing i am not very happy with, namely the length of the example in the documentation. Do you have possibly a easier solution using the current method-signature of the unit-definition, @sbrodehl ? |
sbrodehl
approved these changes
Feb 14, 2023
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.
Units
This MR introduces Units into miniflask.
Those are custom numbers that share multiple representations.
TODO:
Example
First, we define
timeto be a unit with four different representations.:In CLI, we can overwrite this unit using:
--time 1.5d(1.5 days)--time 24h(24 hour)--time 500m(500 minutes)Using
u in vNotation, we can specify the base unit to convert all calculations to.:--time 12h in d(0.5 days)--time 1.5d in h(18 hours)To register a unit, pass it to
register_defaultsas follows:Note, that the base unit is always the one that is passed last to the variable.
In the example below,
timeuses hours internally,time2andtime3use days internally.Querying other representations can be done easily, once defined:
Calculations works similarly:
Things done in this MR
Unit,UnitValue,UnitValueArgparse)mf.register_unitfuncitonCheck all before creating this PR: