Problems when I try to commit
Harald Seiler
hws at denx.de
Tue Mar 10 11:57:46 CET 2020
Hello Daniel,
On Tue, 2020-03-10 at 11:45 +0100, Daniel Garcia wrote:
> I have a problem when i try to do a commit
>
> this is the message:
>
> --------------------------------------------------------------------
>
>
> mypy.....................................................................Failed
> - hook id: mypy
> - exit code: 1
>
> tbot_contrib/time_generic_testcases/time_tescases.py:8: error: Function
> is missing a type annotation for one or more arguments
> tbot_contrib/time_generic_testcases/time_tescases.py:18: error: Function
> is missing a type annotation for one or more arguments
>
>
> ----------------------------------------------------------------------
>
> this is the part in the file that has problems
>
>
> @tbot.testcase
> def testcase_clockTime(testcase, *args, **kwargs) -> float:
> """Return the time that the given testcase took
> you can pass any arguments that the testcase needs"""
> start = time.time()
> testcase(*args, **kwargs)
> finish = time.time()
> return finish - start
>
> -----------------------------------------------------------------------------
>
> the error is caused by this line : def testcase_clockTime(testcase,
> *args, **kwargs)
>
> because i did not define the types of (testcase, *args, **kwargs)
> because they are intended to be generic
>
>
> how can i avoid that check?
Avoiding checks is a bad attitude ;) Instead you should fix the issue
it is complaing about. In this case, you need to annotate the arguments
of your testcase function, for example like this:
import typing
@tbot.testcase
def testcase_clock_time(
testcase: typing.Callable,
*args: typing.Any,
**kwargs: typing.Any,
) -> float:
...
In plain words this means: `testcase` can be any "callable" (that is,
something like a function) and args, kwargs can be anything, we don't care
about the specific types.
`typing.Any` is a kind of wildcard that should only be used carefully. In
most cases it makes more sense to be explicit about the types you want to
allow but here it is ok: The specific types depend on the signature of the
testcase function so we can't know.
For more info on these 'type annotations', maybe take a look at this
blog-post [1].
Hope this helps!
[1]: https://www.caktusgroup.com/blog/2017/02/22/python-type-annotations/
--
Harald
More information about the tbot
mailing list