On Thu, 2023-03-16 at 14:30 -0700, Daniel Latypov wrote:
100% agree, just the concern is about trying to keep two different checkers happy when they might have conflicting demands. Pytype has been able to catch some relatively subtle errors, so I've prioritized it.
Sure. Maybe I'll just switch to pytype too ;-)
But since commit b7e0b983ff13 ("kunit: tool: fix pre-existing python type annotation errors") onwards, I've been trying to fix up all the issues we've had with either.
OK.
One footgun I ran into was that mypy seemed like it wasn't even touching functions if they didn't have an argument or the return type annotated. See 09641f7c7d8f ("kunit: tool: surface and address more typing issues") Maybe --strict is better.
It might not be, I have no idea.
Pytype takes a lot longer and caught issues that normal `mypy` didn't. I haven't compared them w/ strict --strict. But given pytype is still a lot slower, I assume (hope) it's doing more work.
Hehe :-)
think both tools will insist that you place the comment on the same line as the error, and that doesn't really work since you can only have one comment on that line :-) However, it looks like pytype would also accept "# type: ignore" according to the docs.
That's true, but `type: ignore` disables all type checking on the line.
In this case, I think it's moot given the whole line is just sys.stdin.reconfigure(errors='backslashreplace') so I'd basically turned off all type-checking already.
Right, pytype looks a bit more controlled there.
I think you got that annotation wrong, at least as far as mypy is concerned?
sys.stdin.reconfigure(errors='backslashreplace') #pytype: disable=attribute-error
kunit_output = sys.stdin
kunit_output = sys.stdin # type[Iterable[str]]
Doing
kunit_output: Iterable[str] = sys.stdin
actually fixes it for me, and you don't even need the second one:
D'oh, I forgot the ": " Ugh, magic comments :) Doing "# type: Iterable[str]` on just the first one works for me.
Right, not sure I like the magic comments better than the inline type in the code, but YMMV.
Note: we'd been avoiding the `var: T = 42` syntax to try and be more compatible with old versions of python.
Well, OK, I gave up on non-controlled versions of python long ago. In my case it's all running in a nix-shell environment so I control it very precisely :-)
Ack, yeah, the fact it dumps anything directly to stdout is annoying.
The argument is that
- it wants to print in real time
- it needs access to the tty to know if it should include colors or not
Right.
This patch might be of interest to you: https://kunit-review.git.corp.google.com/c/linux/+/5730/1 With that, you could pass in a kunit_printer.BufferPrinter to parse_tests() and keep stdout pristine.
Heh. Sounds like a useful patch but I can't see that link given the lack of corp.google.com login :P
I could split out the concurrency support from that patch and try to get submitted. There just wasn't motivation to do so since there was no use case for suppressing output yet. Given you're using it, that might be sufficient.
I honestly don't care much now. Basically decided that redirecting stdout to /dev/null was sufficient, since anyway the real output I need happens to a file. I might've designed it to print the JSON on stdout instead if it wasn't getting all that output from kunit, but it really doesn't matter now.
Anyway, thanks for the discussion! I've been playing with kunit only for like 48 hours now, so we'll see where I can go from here :-)
johannes