pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Do not raise 'invalid module name` if there's a shebang indicating a file is a script and not a module

Open pylint-bot opened this issue 10 years ago • 4 comments

Originally reported by: Anonymous


Hi, sometimes I have a script in a directory which generates an error like:

1: Invalid module name "pre-commit" (C0103)

I'd like to disable checking of the file name, but not disable checking of all other names. There's no way to add a #pylint comment to line 1 of the file (it's a shebang), so please make the module name check its own code that I can disable.


  • Bitbucket: https://bitbucket.org/logilab/pylint/issue/516

pylint-bot avatar Apr 13 '15 08:04 pylint-bot

This is also an issue for me. The error may be locally disabled by adding # pylint: disable=invalid-name right under the shebang, but I don't think I should need to do this. The file in question is a script. It has a shebang, is marked as executable and is called directly. It is not a module and thus the label 'Invalid module name' seems to be erroneous.

brbsix avatar Dec 27 '15 16:12 brbsix

Doesn't sound too bad to me, but unfortunately I won't have time for this quite soon.

PCManticore avatar Dec 29 '15 16:12 PCManticore

brbsix writes: "The error may be locally disabled by adding # pylint: disable=invalid-name right under the shebang," I suspect that would be clearer as: "Maybe a special case could be added where in a line "# pylint: disable=invalid-name" immediately after the shebang,"

bhyde avatar Jun 01 '16 18:06 bhyde

This regressed and can't be disabled at all, see #3973

Pierre-Sassoulas avatar Sep 27 '21 17:09 Pierre-Sassoulas

@Pierre-Sassoulas Are we sure we want to do this? I feel like it makes more sense to require a disable comment than adding an exception to a rule that is already quite controversial and difficult to fully understand. Complicating with additional exceptions doesn't seem too good to me.

DanielNoord avatar Sep 04 '22 13:09 DanielNoord

I think you're right. Besides the issue's been opened for quite some time and there's no fix yet. The fact it can't be disabled is a problem though.. Probably not a big one as not following pep8 isn't that frequent. Also entrypoints exists and are easy to use.

Pierre-Sassoulas avatar Sep 04 '22 14:09 Pierre-Sassoulas

I commented before seeing that disable work for non empty file with invalid names. Let's close.

Pierre-Sassoulas avatar Sep 04 '22 14:09 Pierre-Sassoulas

I just checked:

#!/usr/local/opt/[email protected]/bin/python3.10 # pylint: disable=invalid-name

import sys

print(sys.version)

Also works. So you can actually disable on the same line as the shebang and still execute. Agreed that this can be closed, working as intended and the exception is not worth it.

DanielNoord avatar Sep 04 '22 14:09 DanielNoord