3 ms·
> Um lol what do you think the error is here? This is widely accepted syntax for a stub. No it isn't. The accepted stub syntax is an ellipses (...). A compete
by veber-alex 3y ago
> Um lol what do you think the error is here? This is widely accepted syntax for a stub.
No it isn't.
The accepted stub syntax is an ellipses (...).
A competent type checker like pyright will error on this code.
Function with declared return type "int" must return value on all code paths
Type "None" cannot be assigned to type "int"
And if you need more proof that pycharm is useless as a type checker:
def foo(b) -> int:
if b:
return 1
A classic error where you forget to return a value from all paths and pycharm is silent.
- mathisfun123 3y agoI linked directly to the section of mypy docs that shows you are wrong - all you have to do is click the link to understand that you are wrong: >(Using stub file syntax at runtime). You may also occasionally need to elide actual logic in regular Python code... You can also elide default arguments as long as the function body also contains no runtime logic: the function body only contains a single ellipsis, the pass statement, or a raise NotImplementedError(). It is also acceptable for the function body to contain a docstring. For example:
- veber-alex 3y agoAnd why would I care about mypy docs? pyright does the correct thing by showing an error. In any case, the second example is definitely not a stub.
- mathisfun123 3y agothis is the weirdest "head in sand" moment; you literally called out mypy as a desirable alternative >And to add insult to injury Pycharm doesn't even have a pyright plugin and the mypy plugin is extremely slow and buggy. ie you recognize that aligning with mypy is desirable.