I'm overriding a method in my parent class, and I don't intend to use its only argument.
In a similar vein to this question, I want to use the underscore so my type checker (Pyright/Pylance in VSCode) doesn't give me a message:
class Parent:
def foo(self, bar):
raise NotImplementedError
class WithWarning(Parent):
def foo(self, bar): # 'bar' is not accessed
print("Hello world")
class WithoutWarning(Parent):
def foo(self, *_, **_):
print("Hello world")
This seems to say "ignore any positional or keyword arguments" (I don't know whether bar
gets passed positionally or with a keyword.)
But I've never seen **_
be used anywhere and my instinct tells me that if you've never seen it, you probably shouldn't be using it.
Can anyone give me evidence of some respectable Python code (standard library or similar) which uses this? If not, I'll get rid of it and just live with the error.
Update
As mentioned in the comments, to ignore positional arguments, and keyword arguments, you'd actually have to do something like:
def foo(self, *_, *__): # <- TWO underscores!
Now this looks really mad. Which only makes my question more pertinent: what's the accepted way of doing this?