1111we've found in a wild; PRICE_PARSING_EXAMPLES_NEW is a list of tests for
1212new features. New tests should probably go these two lists.
1313"""
14- from typing import Optional
14+ from typing import Optional , Union
1515from decimal import Decimal
1616
1717import pytest
@@ -26,11 +26,13 @@ def __init__(self,
2626 price_raw : Optional [str ],
2727 currency : Optional [str ],
2828 amount_text : Optional [str ],
29- amount_float : Optional [float ]) -> None :
29+ amount_float : Optional [Union [ float , Decimal ] ]) -> None :
3030 self .currency_raw = currency_raw
3131 self .price_raw = price_raw
3232 amount_decimal = None # type: Optional[Decimal]
33- if amount_float is not None :
33+ if isinstance (amount_float , Decimal ):
34+ amount_decimal = amount_float
35+ elif amount_float is not None :
3436 # don't use Decimal(amount_float), as this is not what
3537 # one usually means, because of float precision
3638 amount_decimal = Decimal (str (amount_float ))
@@ -57,6 +59,8 @@ def __eq__(self, other):
5759 'GBP' , '34.992001' , 34.992001 ),
5860 Example ('GBP' , '29.1583' ,
5961 'GBP' , '29.1583' , 29.1583 ),
62+ Example (None , '1.11000000000000009770' ,
63+ None , '1.11000000000000009770' , Decimal ('1.11000000000000009770' )),
6064]
6165
6266
0 commit comments