Mypy: unable to supress 'already defined on line' errors in idiomatic behave

Created on 31 Jan 2019  路  5Comments  路  Source: python/mypy

Please provide more information to help us understand the issue:

The standard idiom for behave steps is to reuse the step_impl() function name for each step definition. Since step functions are looked up through a separate function this makes sense.

With mypy it seems impossible to supress the messages that occur

features/steps/add.py:11: error: Name 'step_impl' already defined on line 6
features/steps/add.py:16: error: Name 'step_impl' already defined on line 6
features/steps/add.py:21: error: Name 'step_impl' already defined on line 6

This means that code which is otherwise correct fails.

The actual behavior can be seen with the following commands

  • git clone -b pass_mypy [email protected]:mikedlr/behave_minimal_example.git
  • cd behave_minimal_example/
  • mypy features/steps/add.py

which outputs:

features/steps/add.py:11: error: Name 'step_impl' already defined on line 6
features/steps/add.py:16: error: Name 'step_impl' already defined on line 6
features/steps/add.py:21: error: Name 'step_impl' already defined on line 6

the expected behavior would be to show no errors.

$ python --version
Python 3.6.7
$ mypy --version
mypy 0.660

All 5 comments

step_impl is Work in Pycharm why in VScode isn't work ?
what we need to do ?
image

I don't think something as esoteric as this library will be supported in the near future. Don't other linters complain? You can probably write a mypy plugin to change this if you really wanted (head over to Gitter for help).

I don't think something as esoteric as this library will be supported in the near future. Don't other linters complain? You can probably write a mypy plugin to change this if you really wanted (head over to Gitter for help).

"something as esoteric as this library" - do you mean mypy or behave?

I presume I meant behave (which to this day I have never heard of outside this ticket).

I ran into this recently with functools.singledispatch, which often uses multiple functions with the name _.
A better solution that exists now is using mypy's error codes ([no-redef])

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericnchen picture ericnchen  路  3Comments

gregbedwell picture gregbedwell  路  3Comments

Stiivi picture Stiivi  路  3Comments

squarewave24 picture squarewave24  路  3Comments

ikonst picture ikonst  路  3Comments