I have a function that has to take two arguments, like:
def f(first_arg: int, unused_arg) -> int:
first_arg = 1
return first_arg
I want to type my function, what should be the type of unused_arg ? From this question I guess None
could be used.
For context, I'm using lax.scan
from jax
which needs a function with two arguments even when the second one is unused.
CodePudding user response:
You can use Any
?
from typing import Any
def f(first_arg: int, unused_arg: Any) -> int:
...
CodePudding user response:
The doc (https://jax.readthedocs.io/en/latest/_autosummary/jax.lax.scan.html) gives the type of f
as:
Callable[[~Carry, ~X], Tuple[~Carry, ~Y]]
so I'd maybe do it with a TypeVar
named X
if I didn't have a more specific type:
from typing import TypeVar
X = TypeVar("X")
def f(first_arg: int, _second_arg: X) -> int:
...
Note that per the doc it seems like your f
is expected to return a tuple of two items; I'm not sure if that matters for your use case.
The standard way (at least as enforced by linters I've used) of indicating an unused parameter is to prefix it with an underscore, so I'd do that instead of naming it unused_arg
).