Reputation: 733
I use the following format to document my Python code:
def my_function(param: str) -> dict:
some code
I can't figure out how to document a function passed to another function.
For example:
def my_function(my_other_function: ???) -> dict:
some code
How do I make a function annotation?
Upvotes: 4
Views: 234
Reputation: 25094
First Thoughts: "Everything in python is an object"
I couldn't find anything in the docs, but as everything in python is an object
i would shoot for object
.
def my_function(my_other_function: object) -> dict:
some code
To proof it:
if isinstance(my_function, my_function, object):
print("yes")
>yes
Anyhow, this might not be too explicit, therefore:
Seconds thoughts: Using proper type hints
Based on what COLDSPEED
commented, a more explicit type hint would be using typing
import typing
def my_function(my_other_function:typing.Callable):->dict:
pass
"The only way that annotations take on meaning is when they are interpreted by third-party libraries". Which means, for your source-code itself, it doesn't change anything. Just wanted to mention it.
Upvotes: 4