Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update weight funcs, add typing and doc string
IKarbowiak0bfa032312ea
diff --git a/saleor/core/weight.py b/saleor/core/weight.pyindex f2d9001749..65458566a5 100644--- a/saleor/core/weight.py+++ b/saleor/core/weight.py@@ -35,7 +35,7 @@ def zero_weight():return Weight(kg=0)-def convert_weight(weight, unit):+def convert_weight(weight: Weight, unit: str) -> Weight:# Weight amount from the Weight instance can be retrived in serveral units# via its properties. eg. Weight(lb=10).kgconverted_weight = getattr(weight, unit)@@ -49,10 +49,12 @@ def get_default_weight_unit():return site.settings.default_weight_unit-def covert_weight_to_default_weight_unit(weight):+def covert_weight_to_default_weight_unit(weight: Weight) -> Weight:+ """Weight is kept in one unit, but should be returned in site default unit."""default_unit = get_default_weight_unit()- if weight and weight.unit != default_unit:- weight = convert_weight(weight, default_unit)- elif weight:- weight.value = round(weight.value, 3)+ if weight is not None:+ if weight.unit != default_unit:+ weight = convert_weight(weight, default_unit)+ else:+ weight.value = round(weight.value, 3)return weight