Skip to content

Commit 170bf31

Browse files
committed
fix: fixed lint complaints about non-exhaustive cases by raising ValueError, added 'pragma: no cover'
1 parent 0cc51ef commit 170bf31

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

uniswap/uniswap.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def __init__(
8686
)
8787

8888
self.version = version
89+
if self.version not in [1, 2, 3]:
90+
raise Exception(
91+
f"Invalid version '{self.version}', only 1, 2 or 3 supported"
92+
) # pragma: no cover
8993

9094
# TODO: Write tests for slippage
9195
self.default_slippage = default_slippage
@@ -104,7 +108,7 @@ def __init__(
104108
if self.netid in _netid_to_name:
105109
self.netname = _netid_to_name[self.netid]
106110
else:
107-
raise Exception(f"Unknown netid: {self.netid}")
111+
raise Exception(f"Unknown netid: {self.netid}") # pragma: no cover
108112
logger.info(f"Using {self.w3} ('{self.netname}', netid: {self.netid})")
109113

110114
self.last_nonce: Nonce = self.w3.eth.get_transaction_count(self.address)
@@ -164,10 +168,6 @@ def __init__(
164168
self.router = _load_contract(
165169
self.w3, abi_name="uniswap-v3/router", address=self.router_address
166170
)
167-
else:
168-
raise Exception(
169-
f"Invalid version '{self.version}', only 1, 2 or 3 supported"
170-
)
171171

172172
if hasattr(self, "factory_contract"):
173173
logger.info(f"Using factory contract: {self.factory_contract}")
@@ -234,6 +234,8 @@ def _get_eth_token_input_price(
234234
price = self._get_token_token_input_price(
235235
self.get_weth_address(), token, qty, fee=fee
236236
) # type: ignore
237+
else:
238+
raise ValueError # pragma: no cover
237239
return price
238240

239241
def _get_token_eth_input_price(
@@ -254,6 +256,8 @@ def _get_token_eth_input_price(
254256
price = self._get_token_token_input_price(
255257
token, self.get_weth_address(), qty, fee=fee
256258
)
259+
else:
260+
raise ValueError # pragma: no cover
257261
return price
258262

259263
def _get_token_token_input_price(
@@ -320,6 +324,8 @@ def _get_eth_token_output_price(
320324
self.get_weth_address(), token, qty, fee=fee
321325
)
322326
)
327+
else:
328+
raise ValueError # pragma: no cover
323329
return price
324330

325331
def _get_token_eth_output_price(
@@ -339,8 +345,11 @@ def _get_token_eth_output_price(
339345
price = self._get_token_token_output_price(
340346
token, self.get_weth_address(), qty, fee=fee
341347
)
348+
else:
349+
raise ValueError # pragma: no cover
342350
return price
343351

352+
@supports([2, 3])
344353
def _get_token_token_output_price(
345354
self,
346355
token0: AddressLike, # input token
@@ -385,7 +394,7 @@ def _get_token_token_output_price(
385394
token0, token1, fee, qty, sqrtPriceLimitX96
386395
).call()
387396
else:
388-
raise ValueError("function not supported for this version of Uniswap")
397+
raise ValueError # pragma: no cover
389398
return price
390399

391400
# ------ Make Trade ----------------------------------------------------------------
@@ -548,7 +557,7 @@ def _eth_to_token_swap_input(
548557
self._get_tx_params(value=qty),
549558
)
550559
else:
551-
raise ValueError
560+
raise ValueError # pragma: no cover
552561

553562
def _token_to_eth_swap_input(
554563
self,
@@ -637,9 +646,8 @@ def _token_to_eth_swap_input(
637646
self.router.functions.multicall([swap_data, unwrap_data]),
638647
self._get_tx_params(),
639648
)
640-
641649
else:
642-
raise ValueError
650+
raise ValueError # pragma: no cover
643651

644652
def _token_to_token_swap_input(
645653
self,
@@ -734,7 +742,7 @@ def _token_to_token_swap_input(
734742
self._get_tx_params(),
735743
)
736744
else:
737-
raise ValueError
745+
raise ValueError # pragma: no cover
738746

739747
def _eth_to_token_swap_output(
740748
self,

0 commit comments

Comments
 (0)