@wrapt.decorator
def my_request(wrapped, instance, args, kwargs):
filtered_kwargs = {key: value for key, value in kwargs.items() if value is not None}
url = wrapped(*args, **filtered_kwargs)
response = requests.get(url, filtered_kwargs)
return response.content
class MyClass:
@my_request
def some_data(self, additional_data=None):
return "https://myurl.example.com"
The idea is to define available query parameters through non-None keyword arguments, so if I call obj.some_data() I expect the contents of "https://myurl.example.com" to be returned and on obj.some_data(additional_data="data"), "https://myurl.example.com?additional_data=data" should be called.
Now the problem is that ARG002 is triggered on additional_data, which is of course used, but only indirectly via the decorator. I don't know whether looking up what decorators are doing is in scope for ruff at all so I don't have high expectations that this is worth fixing, but would still appreciate it deeply.
This will be pretty tough to fix, my honest suggestion would be to try and restructure the code to avoid this kind of interception-via-decorator, but I know you didn't come here for those kinds of suggestions :)
My code goes something like this:
The idea is to define available query parameters through non-
None
keyword arguments, so if I callobj.some_data()
I expect the contents of "https://myurl.example.com" to be returned and onobj.some_data(additional_data="data")
, "https://myurl.example.com?additional_data=data" should be called.Now the problem is that
ARG002
is triggered onadditional_data
, which is of course used, but only indirectly via the decorator. I don't know whether looking up what decorators are doing is in scope forruff
at all so I don't have high expectations that this is worth fixing, but would still appreciate it deeply.