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

function created with partial gives invalid-name warning #1101

Closed
KennethNielsen opened this issue Sep 8, 2016 · 7 comments
Closed

function created with partial gives invalid-name warning #1101

KennethNielsen opened this issue Sep 8, 2016 · 7 comments

Comments

@KennethNielsen
Copy link

Steps to reproduce

  1. Type in a program such as:

    """Example of pylint behavior with partials"""
    
    from functools import partial
    import subprocess
    
    call = partial(subprocess.call, shell=True)
    
    call('echo "Not what I expected"')
  2. Run pylint on it

Current behavior

It will give you an invalid-name error on the line: call = partial(subprocess.call, shell=True)

Expected behavior

I don't think this should raise en error.

partial return a partial object, which is a function (see https://docs.python.org/2/library/functools.html) with a little extra information attached to it, but it is non the less a function. Therefore, I think, that if the return value of partial is assigned a name (even at the module level) it should just adhere to the function naming conventions not constant ones.

I realize that special cases are annoying for all the extra code they involve, but I think this one should be worth it.

pylint --version output

pylint 1.6.4
astroid 1.4.8
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1]

@PCManticore
Copy link
Contributor

The check that verifies invalid-name doesn't care what the RHS of an assignment is, it is quite dumb and adding additional tips such as this is not worth it at the end of the day. Feel free to customize the const-rgx variable for more lax rules or disable the error locally.

@KennethNielsen
Copy link
Author

This problem affects not only partial, but also e.g. types created with by namedtuple, which is a somewhat more central feature than partial. So I can't say that I agree, but thanks for the quick reply.

@mentalisttraceur
Copy link

Now that pylint does support proper logic for invalid-type when the RHS of an assignment is a namedtuple, can this be reopened to support partial? Maybe even the other similar constructs in the standard library? (operator.methodcaller and operator.attrgetter come to mind.)

@dandersson
Copy link

Pylint no longer complains about this case from version 2.5.0 and onward as a consequence of #3111 .

@mentalisttraceur
Copy link

@dandersson Cheers, that's good to hear, and thank you for posting an update about it on this issue!

@hippo91
Copy link
Contributor

hippo91 commented Oct 17, 2020

@dandersson thanks for this update!

@KennethNielsen
Copy link
Author

Great stuff, thanks

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

5 participants