Hey team, for python dependency inference, is ther...
# general
f
Hey team, for python dependency inference, is there any way to configure it to ignore imports from underneath
if TYPE_CHECKING:
blocks? (I'm not actually sure if we want to do this yet but wanted to check if it's even possible.)
w
Not sure if this works for blocks, or just lines:
# pants: no-infer-dep
f
Right! I've been using that in some places but it would be a bit messy and onerous to manually add that to every place where we do imports for type checking only.
w
Ah
a
keep in mind that ignoring these dependencies means that mypy might not detect a failure (you change a class from
if TYPE_CHECKING
block, and then a consumer of it isn't rechecked even though it should be)
f
Yeahhhh thinking about this a bit more, we probably don't want to do this ...
Always interested in what level of control we have over this feature though 🙂
w
Yeah, overall, I hate "if TYPE_CHECKING" and would absolutely never use it
f
I suspect it is often used to avoid circular dependency issues
Lots of uses of the pattern in our monorepo though:
Copy code
ACAM-M-DVHW: acam$ rg -l 'if TYPE_CHECKING:' | grep -v third-party | wc -l
     269
ACAM-M-DVHW: acam$
😱 1
🤮 1
s
I use it often when retrofitting code with types, because circular dependencies. Doesn't really cause an import problem until those deps cross deployable boundaries.