Hi,
as Python documentation there says:
The site module [...] adds several constants to the built-in namespace.
They are useful for the interactive interpreter shell and should not be used in programs.
I try to follow this recommendation, and I succeed to disable the default site path search, and I have no reference on these functions during Python runtime.
However, when I try from sys import exit, I got from Pylint the following warning W0622: Redefining built-in 'exit' (redefined-builtin). This behaviour seems wrong to me in my context and I have found no way to disable this warning in Pylint configuration.
Is this behaviour should be improved, or is there a way to silent Pylint ?
Have a good day !
I'm sorry, I don't quite follow. Do you have a minimal test case to reproduce this problem? If you want to disable the said message, you can just do disable=W0622 in your configuration file or run pylint with --disable=W0622.
EDIT: long and complicated explanation for nothing, the next comment has a very clear and short test-case !
I agree, but I don't want to disable all other checks on builtin redefine.
My previous point was that I succeed to prevent the load of these constants with the following code :
#! /usr/bin/python3 -S
from sys import path
from site import abs_paths, addsitepackages, execsitecustomize, removeduppaths
def lightSiteLoad():
""" site module load has been disable, this method provide a more tiny load of
site module than the default `site.main` method
"""
origPath = path[:]
knownPaths = removeduppaths()
if origPath != path:
abs_paths()
addsitepackages(knownPaths)
execsitecustomize()
lightSiteLoad()
# exit builtin function does not exists at this point
from sys import exit # pylint: disable=redefined-builtin
Note that -S option is used. Here in this code, the Pylint redefined-builtin is triggered during the from sys import exit, but as there is no exit builtin, it should not trigger.
My initial question was in fact: How can I inform Pylint that I have disabled the load of constants added by the site module (quit, exit, license, copyright, credits), so I can use these varibales without Pylint triggered the redefined-builtin warning (and without disable all other redefined-builtin)
However, I think I made also a little misunderstanding of Python documentation. Here is the entire part of the doc:
The site module (which is imported automatically during startup, except if the -S command-line option is given) adds several constants to the built-in namespace.
They are useful for the interactive interpreter shell and should not be used in programs.
I understood that Python doc invite devs to use the -S command-line to prevent the import of constants added by the site module. In fact, now I think they just said: "the constants are always available, don't call them".
Anyway, it's a tiny edge-case, I don't know if it worth to spend more time for this hacky code.
Smaller and better test case:
import builtins
del builtins.exit
from sys import exit #pylint: disable=redefined-builtin
redefined-builtin Pylint's warning should not occur, exit builtin function does not exists anymore
I tried init-hook="import builtins; del builtins.exit in Pylint configuration file, but it does not work ^^
@SamyCookie This has a super easy fix you can use today:
pylint a.py --redefining-builtins-modules=sys
This will tell pylint that sys can be a module that redefines builtins, such as exit.
Thanks, this fix is good enough for my use case.
Have a good day !
Most helpful comment
Smaller and better test case:
redefined-builtinPylint's warning should not occur,exitbuiltin function does not exists anymore