Catching multiple return types

Is there a static checker which will catch multiple return types? Consider this dumb example: def func(a, b, c): if c: return (a, b) return 0 I thought pylint had a checker for that, but running with --rcfile=/dev/null didn't complain about the different types being returned. Is there perhaps a checker for that which isn't enabled by default? Or another static tool which will catch it? Thx, Skip

IINM, mypy can catch such things. But that's a different sort of tool of course. On Wed, Apr 18, 2018 at 1:25 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
Is there a static checker which will catch multiple return types? Consider this dumb example:
def func(a, b, c): if c: return (a, b) return 0
I thought pylint had a checker for that, but running with --rcfile=/dev/null didn't complain about the different types being returned. Is there perhaps a checker for that which isn't enabled by default? Or another static tool which will catch it?
Thx,
Skip _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
-- Dan Stromberg

Thanks, good to know. Yet another tool for the kit... S On Wed, Apr 18, 2018, 3:43 PM Dan Stromberg <strombrg@gmail.com> wrote:
IINM, mypy can catch such things. But that's a different sort of tool of course.
On Wed, Apr 18, 2018 at 1:25 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote:
Is there a static checker which will catch multiple return types? Consider this dumb example:
def func(a, b, c): if c: return (a, b) return 0
I thought pylint had a checker for that, but running with --rcfile=/dev/null didn't complain about the different types being returned. Is there perhaps a checker for that which isn't enabled by default? Or another static tool which will catch it?
Thx,
Skip _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
-- Dan Stromberg

На 19.04.2018 в 01:08, Skip Montanaro написа:
Thanks, good to know. Yet another tool for the kit...
S
On Wed, Apr 18, 2018, 3:43 PM Dan Stromberg <strombrg@gmail.com <mailto:strombrg@gmail.com>> wrote:
IINM, mypy can catch such things. But that's a different sort of tool of course.
On Wed, Apr 18, 2018 at 1:25 PM, Skip Montanaro <skip.montanaro@gmail.com <mailto:skip.montanaro@gmail.com>> wrote:
Is there a static checker which will catch multiple return types? Consider this dumb example:
def func(a, b, c): if c: return (a, b) return 0
I thought pylint had a checker for that, but running with --rcfile=/dev/null didn't complain about the different types being returned. Is there perhaps a checker for that which isn't enabled by default? Or another static tool which will catch it?
Sounds like _check_consistent_returns in checkers/refactoring.py needs to be updated to inspect the type of the value being returned. Please open a GitHub issue for that. At the top of my head I have no idea how hard or easy this is to implement. -- Alex
participants (3)
-
Alexander Todorov
-
Dan Stromberg
-
Skip Montanaro