Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefinition of _ function results in warning #1032

Closed
anntzer opened this issue Jul 21, 2016 · 3 comments
Closed

Redefinition of _ function results in warning #1032

anntzer opened this issue Jul 21, 2016 · 3 comments

Comments

@anntzer
Copy link

anntzer commented Jul 21, 2016

Steps to reproduce

The stdlib docs suggest defining specializations of singledispatch functions as _ (see second example of https://docs.python.org/3.5/library/functools.html#functools.singledispatch)
But pylint warns on

from functools import singledispatch

@singledispatch
def func(arg):
    pass

@func.register(int)
def _(arg):
    pass

@func.register(str)
def _(arg):
    pass

that the last definition redefines _ that has been defined 4 lines above.

Expected behavior

No warning.

pylint --version output

pylint 1.6.4,
astroid 1.4.7
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602]

@rogalski
Copy link
Contributor

rogalski commented Sep 2, 2016

PR #1094 contains function is_registered_in_singledispatch_function(node) which takes FunctionDef node as argument. If merged, it may be easily used to skip warning in this case. Possibly we may also yield error if name is not equal to underscore (if this naming convention is part of accepted PEP).

rogalski added a commit to rogalski/pylint that referenced this issue Nov 6, 2016
rogalski added a commit to rogalski/pylint that referenced this issue Nov 30, 2016
rogalski added a commit to rogalski/pylint that referenced this issue Dec 3, 2016
…implementations

Closes pylint-dev#1032 and pylint-dev#1034

fix python version guard

remove dead code

drop redundant exception caught, improve coverage
rogalski added a commit to rogalski/pylint that referenced this issue Dec 3, 2016
@eight04
Copy link

eight04 commented Feb 25, 2017

Is this fixed? I still get E: 12, 0: function already defined line 8 (function-redefined).

>py -3.5 -m pylint --version
No config file found, using default configuration
__main__.py 1.6.5,
astroid 1.4.9
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 15:51:26) [MSC v.1900 32 bit (In
tel)]

Also, is there a way to specify some function name allowing to be redefined? _ in this case.

@rogalski
Copy link
Contributor

@eight04 it's not yet released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants