9
When to use typing.TYPE_CHECKING
(feddit.de)
Welcome to the Python community on the programming.dev Lemmy instance!
October 2023
November 2023
Past
July 2023
August 2023
September 2023
You should have part of your test harness perform a separate import of every module. If your module is idempotent (most good code is) you could do this in a single process by cleaning
sys.modules
I guess ... but it still won't be part of yourpytest
process.Static analyzers can only detect some cases, so can't be fully trusted.
I've also found there are a lot of cases where performant Python code has to be implemented in a distinct way from what the type-checker sees. You can do this with aggressive
type: ignore
but I often find it cleaner to use separateif
blocks.