pylint
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
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
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.
Doesn't sound too bad to me, but unfortunately I won't have time for this quite soon.
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,"
This regressed and can't be disabled at all, see #3973
@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.
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.
I commented before seeing that disable work for non empty file with invalid names. Let's close.
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.