4 ms·
And when it fails to infer the type of something you can add `assert isinstance(foo, T)`, and PyCharm will make use of that.
by quietbritishjim 5y ago
And when it fails to infer the type of something you can add `assert isinstance(foo, T)`, and PyCharm will make use of that.
- ramraj07 5y agoThis will throw an error in runtime for bad types, which might or might not be your intention (unless of course you build the package, which only makes it all the more harder to debug if this is where your program fails at this step). So, just don’t use assert outside of tests?
- quietbritishjim 5y agoFor sure, adding that line of code will affect the runtime as well as type hinting in the IDE. Certainly don't use it unless you're sure that the asserted condition is actually always true (or not sure and want to know if it isn't!).