projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Random cleanups and type safety. Created ml subdir.
[python_utils.git]
/
conversion_utils.py
diff --git
a/conversion_utils.py
b/conversion_utils.py
index 10908c54637c143ab6d58da1db95c4ec451c5e6e..b83d62e4daf50ec76850e047672069a8e9f47c7b 100644
(file)
--- a/
conversion_utils.py
+++ b/
conversion_utils.py
@@
-15,15
+15,15
@@
class Converter(object):
unit: str) -> None:
self.name = name
self.category = category
unit: str) -> None:
self.name = name
self.category = category
- self.to_canonical = to_canonical
- self.from_canonical = from_canonical
+ self.to_canonical
_f
= to_canonical
+ self.from_canonical
_f
= from_canonical
self.unit = unit
def to_canonical(self, n: Number) -> Number:
self.unit = unit
def to_canonical(self, n: Number) -> Number:
- return self.to_canonical(n)
+ return self.to_canonical
_f
(n)
def from_canonical(self, n: Number) -> Number:
def from_canonical(self, n: Number) -> Number:
- return self.from_canonical(n)
+ return self.from_canonical
_f
(n)
def unit_suffix(self) -> str:
return self.unit
def unit_suffix(self) -> str:
return self.unit
@@
-75,7
+75,7
@@
conversion_catalog = {
def convert(magnitude: Number,
from_thing: str,
def convert(magnitude: Number,
from_thing: str,
- to_thing: str) ->
Number
:
+ to_thing: str) ->
float
:
src = conversion_catalog.get(from_thing, None)
dst = conversion_catalog.get(to_thing, None)
if src is None or dst is None:
src = conversion_catalog.get(from_thing, None)
dst = conversion_catalog.get(to_thing, None)
if src is None or dst is None:
@@
-87,10
+87,10
@@
def convert(magnitude: Number,
def _convert(magnitude: Number,
from_unit: Converter,
def _convert(magnitude: Number,
from_unit: Converter,
- to_unit: Converter) ->
Number
:
+ to_unit: Converter) ->
float
:
canonical = from_unit.to_canonical(magnitude)
converted = to_unit.from_canonical(canonical)
canonical = from_unit.to_canonical(magnitude)
converted = to_unit.from_canonical(canonical)
- return
converted
+ return
float(converted)
def sec_to_min(s: float) -> float:
def sec_to_min(s: float) -> float: