3

I'm trying to fix all pylint warnings for my code, and there is just one that I cannot fix without disabling the warning or renaming the script:

C:  1, 0: Invalid module name "foo-bar" (invalid-name)

Renaming the script is not an option since its name is its public interface. The script is widely used under the current name.

That's a top-level program. The file is not intended to be used as a module. If I decide to import it as a module for unit tests, I can use __import__("foo-bar") but no other import is supported.

Is there any nice way to tell pylint that it's a top-level script, not a module?

1 Answer 1

2

You need to override the module-rgx option either at the CLI or in your pylintrc file to allow -s. For more on this check out the docs.

Sign up to request clarification or add additional context in comments.

3 Comments

That's a good suggestion. The downside is that - won't be detected in the files that are modules. But I can craft a regex to specifically allow known names. The correct and up-to-date URL is pylint.readthedocs.io/en/latest/user_guide/options.html
All python files are modules to pylint, including executables ... because they are modules to python. You are making a distinction which neither the language nor pylint makes.
Well actually python does make a distinction between top-level scripts and modules in that top level scripts are named 'main' and all other module are named based on their file name. This has other implications, e.g. the search path will include the containing directory...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.