Replies: 2 comments 8 replies
-
Is it sufficient to test for "some error was reported", or do want to be more specific and verify that the correct error was reported and for the correct text range? I would think that you'd want the latter. If so, then my recommendation is to run the pyright CLI with |
Beta Was this translation helpful? Give feedback.
-
A follow up to this for people reading this threads looking for solutions to this. It turns out that you can configure pyright to raise on unnecessary Add to
This provides the exact mechanism that I am looking for to do contrapositive testing (i.e., testing guard against false negatives). Given the above configuration out = sqrt("hello") # type: ignore This will pass only if the type-checker sees a problem with this line. |
Beta Was this translation helpful? Give feedback.
-
This post is highly relevant to the Q&A at #2163, but that discussion gets at capabilities that are beyond what I am looking for; hopefully it is still appropriate for me to post this here. Please let me know if you'd like me to move this post to that thread.
I am hoping to check that an improper use of a function gets flagged by pyright, and to include this in my automated testing process.
Currently, I am only testing that my functions are producing the right types; I do so using
reveal_type
:This has worked great for me thus far. I love the ergonomics of
reveal_type
: getting to see if things pass right in VSCode, while also being able to leverage pyright's CLI in my automated tests has been great. I am especially grateful for this in light of the heavy machinery other libraries have stood up to validate their types (e.g. Hypothesis' infrastructure for mypy tests).What I would like is a utility comparable to
reveal_type
, but something that says "I expect pyright to mark this as invalid". Perhaps it would be calledxfail
. And I would use it asI realize that this sort of function would not cover the full range of functionality that was requested in #2163 , nor does it enable users to verify what the reported error is. That being said, it would make this sort of contrapositive testing possible and exceedingly simple.
I'd love to hear peoples' thoughts. Again, I am happy to move this to #2163 if it would be appropriate.
Beta Was this translation helpful? Give feedback.
All reactions