- Notifications
You must be signed in to change notification settings - Fork386
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
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. |
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
There was a problem hiding this 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 kwargsdoes 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.
*args, | ||
**kwargs |
There was a problem hiding this comment.
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.
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: |
There was a problem hiding this comment.
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 withcheck_approval
. TheParamSpec
is used for a reason.
ErikBjare commentedJul 4, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
If you want a fix for#218, feel free to submit a PR that checks the |
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. 👍