Skip to content

bugfix: Uniswap constructor and "check_approval" decorator throwing whenever passing kwargs. Issue #218 #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

RoscoeTheDog
Copy link

Asked the chatbot to come up with a solution. Seems to work fine. I'm not too familiar with all the internal relationships, so someone should review before merging. 👍

When creating a wrapper class for this API, I encountered issues passing down a flattened dict of kwargs to the constructor of Uniswap() class due to it not having *args, **kwargs in it's constructors signature. Any extra arguments that were not explicitily in the constructors signature would throw an error, which makes it less friendly for other software systems to wrap it's code with.

Simply adding *args and **kwargs to the constructor fixes this issue and doesn't intrtoduce any negative effects.
@RoscoeTheDog
Copy link
Author

Also added *args, **kwargs to Uniswap constructor

When creating a wrapper class for this API, I encountered issues passing down a flattened dict of kwargs to the constructor of Uniswap() class due to it not having *args, **kwargs in it's constructors signature. Any extra arguments that were not explicitily in the constructors signature would throw an error, which makes it less friendly for other software systems to wrap it's code with.

Simply adding *args and **kwargs to the constructor fixes this issue and doesn't intrtoduce any negative effects.

@RoscoeTheDog RoscoeTheDog changed the title bugfix: "check_approval" decorator throwing when using kwargs. Issue #218 bugfix: Uniswap constructor and "check_approval" decorator throwing whenever passing kwargs. Issue #218 Dec 24, 2023
Simulate can now be specified to return an estimate of the gas fees as well as some other useful metadata for the transaction. Does NOT take into account slippage or price impact for a transaction!!

This was mostly needed so I could find the gas fees ahead of time before pushing an order on-chain and allows me to adjust the amount of network fee token buyback prior to it.
bug fixes when building and pushing transactions
Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any extra arguments that were not explicitily in the constructors signature would throw an error

That is intended. Don't pass things that aren't going to be used.

which makes it less friendly for other software systems to wrap it's code with.

No, it just makes you have to clean up your args (as you should anyway).

Simply adding *args and **kwargs to the constructor fixes this issue and doesn't intrtoduce any negative effects.

It's not a bug, it's a feature. Adding unused args and kwargs does introduce negative effects. It ruins typecheckers ability to spot misspelled keyword arguments and otherwise unused args, among other things.

As explained above, this PR breaks typing in several places (see CI), so it will not get merged.

Comment on lines +95 to +96
*args,
**kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused. Don't do this, clean up your args instead.

Comment on lines -23 to +29
def check_approval(
method: Callable[Concatenate["Uniswap", P], T]
) -> Callable[Concatenate["Uniswap", P], T]:
"""Decorator to check if user is approved for a token. It approves them if they
def check_approval(method: Callable[..., T]) -> Callable[..., T]:
"""Decorator to check if the user is approved for a token. It approves them if they
need to be approved."""

@functools.wraps(method)
def approved(self: "Uniswap", *args: P.args, **kwargs: P.kwargs) -> T:
def approved(self: "Uniswap", *args: Union[AddressLike, int], **kwargs: AddressLike) -> T:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ruins typing (and is not even valid, *args has to be an iterable and **kwargs a mapping) for any function annotated with check_approval. The ParamSpec is used for a reason.

@ErikBjare ErikBjare closed this Jul 4, 2024
@ErikBjare
Copy link
Member

ErikBjare commented Jul 4, 2024

If you want a fix for #218, feel free to submit a PR that checks the kwargs for the token in addition to the args (or just skip the kwargs) as I explained in #218 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy