Skip to content
Advertisement

How to write a test that checks if was added type annotation in function?

I have a function.

JavaScript

And I want to add a test that checks that function and parameters have a type annotation. It is needed by other developers don’t change input and output types.

Any idea how to do that? I want to use pytest, maybe mocks?

Advertisement

Answer

You can use the get_type_hints function from typing:

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement