El sáb, 22 ene 2022 a las 16:23, Eric Traut (<eric@traut.com>) escribió:
Thanks for writing this proposal, Jelle.

I like the proposal for `assert_type`. It doesn't allow for checking the textual representation of a type, but that's not important for most target users of this functionality. I personally have a need for that in the pyright unit tests, but I can use a pyright-specific extension to handle that use case. Presumably other type checkers could do the same if they want to validate the textual representations of types they produce.

I'm pretty negative on the proposal for `assert_error`. This seems like an abuse of a context manager. As you point out, there is no precedent for type checkers using context managers in this manner. There are many potential type errors and warnings that could be reported, and the granularity and nature of these errors is not well specified in any PEP, so standardizing a mechanism that says "there must be a type error reported here" is fraught with challenges. My recommendation is to remove `assert_error` from the proposal. I don't see a way to overcome these challenges, and I don't think the use case is sufficiently compelling to introduce a mechanism that has no precedent.

Can you expand more on why you don't find the use case compelling? In my mind, one of the main points of type checking is statically finding code that doesn't follow some rule. Therefore, if you carefully write out types to catch code that doesn't follow the rules, it's important to be able to check that your types actually behave as intended.

That said, I do think `assert_type()` is useful on its own, so if there's consensus against `assert_error()`, I can proceed with implementing just `assert_type()`.

And just to reiterate: I think it's important that something like `assert_error()` exists, but it doesn't have to be through a context manager. If there's some alternative way to implement the idea, I'd be happy too.
 
 -Eric

--
Eric Traut
Contributor to Pyright & Pylance
Microsoft
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: jelle.zijlstra@gmail.com