summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kolbus <peter.kolbus@gmail.com>2020-11-29 07:57:39 -0600
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-03-09 09:13:05 +0100
commit12beaa0d3fa050b68dff092520966c63d2f0e437 (patch)
tree43db9ce6bb831103042cc9c19e56145c7781ce25
parentf17007b55e79af1e36d4aad5ec1802fe1ba51662 (diff)
downloadpylint-git-12beaa0d3fa050b68dff092520966c63d2f0e437.tar.gz
Add extension-pkg-allow-list option
Add an option extension-pkg-allow-list to the main checker. This is an alternate name for extension-pkg-whitelist.
-rw-r--r--doc/technical_reference/c_extensions.rst8
-rw-r--r--examples/pylintrc6
-rw-r--r--man/pylint.14
-rw-r--r--pylint/checkers/typecheck.py2
-rw-r--r--pylint/lint/pylinter.py23
-rw-r--r--pylintrc2
6 files changed, 36 insertions, 9 deletions
diff --git a/doc/technical_reference/c_extensions.rst b/doc/technical_reference/c_extensions.rst
index fbf25ec41..1bc7475c2 100644
--- a/doc/technical_reference/c_extensions.rst
+++ b/doc/technical_reference/c_extensions.rst
@@ -9,11 +9,11 @@ Linting C extension modules is not supported out of the box, especially since
pylint has no way to get an AST object out of the extension module.
But **pylint** actually has a mechanism which you might use in case you
-want to analyze C extensions. **pylint** has a flag, called **extension-pkg-whitelist**,
-through which you can tell it to import that module and to build an AST from that
-imported module::
+want to analyze C extensions. **pylint** has a flag, called **extension-pkg-allow-list**
+(formerly **extension-pkg-whitelist**), through which you can tell it to
+import that module and to build an AST from that imported module::
- $ pylint --extension-pkg-whitelist=your_c_extension
+ $ pylint --extension-pkg-allow-list=your_c_extension
Be aware though that using this flag means that extensions are loaded into the
active Python interpreter and may run arbitrary code, which you may not want. This
diff --git a/examples/pylintrc b/examples/pylintrc
index 211796fa9..1a98ef656 100644
--- a/examples/pylintrc
+++ b/examples/pylintrc
@@ -3,6 +3,12 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
+extension-pkg-allow-list=
+
+# A comma-separated list of package or module names from where C extensions may
+# be loaded. Extensions are loading into the active Python interpreter and may
+# run arbitrary code. (This is an alternative name to extension-pkg-allow-list
+# for backward compatibility.)
extension-pkg-whitelist=
# Specify a score threshold to be exceeded before program exits with error.
diff --git a/man/pylint.1 b/man/pylint.1
index d823428b5..00a25712a 100644
--- a/man/pylint.1
+++ b/man/pylint.1
@@ -60,8 +60,10 @@ Specify a score threshold to be exceeded before program exits with error. [defau
Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the number of processors available to use. [default: 1]
.IP "--limit-inference-results=<number-of-results>"
Control the amount of potential inferred values when inferring a single object. This can help the performance when dealing with large functions or complex, nested conditions. [default: 100]
-.IP "--extension-pkg-whitelist=<pkg[,pkg]>"
+.IP "--extension-pkg-allow-list=<pkg[,pkg]>"
A comma-separated list of package or module names from where C extensions may be loaded. Extensions are loading into the active Python interpreter and may run arbitrary code. [default: none]
+.IP "--extension-pkg-whitelist=<pkg[,pkg]>"
+A comma-separated list of package or module names from where C extensions may be loaded. Extensions are loading into the active Python interpreter and may run arbitrary code. (This is an alternative name to extension-pkg-allow-list for backward compatibility.) [default: none]
.IP "--suggestion-mode=<yn>"
When enabled, pylint would attempt to guess common misconfiguration and emit user-friendly hints instead of false-positive error messages. [default: yes]
.IP "--exit-zero"
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index acbf7d4bc..30b6f4e12 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -260,7 +260,7 @@ MSGS = {
),
"I1101": (
"%s %r has no %r member%s, but source is unavailable. Consider "
- "adding this module to extension-pkg-whitelist if you want "
+ "adding this module to extension-pkg-allow-list if you want "
"to perform analysis based on run-time introspection of living objects.",
"c-extension-no-member",
"Used when a variable is accessed for non-existent member of C "
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 502109347..1f7b528a5 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -367,7 +367,7 @@ class PyLinter(
},
),
(
- "extension-pkg-whitelist",
+ "extension-pkg-allow-list",
{
"type": "csv",
"metavar": "<pkg[,pkg]>",
@@ -381,6 +381,21 @@ class PyLinter(
},
),
(
+ "extension-pkg-whitelist",
+ {
+ "type": "csv",
+ "metavar": "<pkg[,pkg]>",
+ "default": [],
+ "help": (
+ "A comma-separated list of package or module names"
+ " from where C extensions may be loaded. Extensions are"
+ " loading into the active Python interpreter and may run"
+ " arbitrary code. (This is an alternative name to"
+ " extension-pkg-allow-list for backward compatibility.)"
+ ),
+ },
+ ),
+ (
"suggestion-mode",
{
"type": "yn",
@@ -1106,7 +1121,11 @@ class PyLinter(
self.stats = {"by_module": {}, "by_msg": {}}
MANAGER.always_load_extensions = self.config.unsafe_load_any_extension
MANAGER.max_inferable_values = self.config.limit_inference_results
- MANAGER.extension_package_whitelist.update(self.config.extension_pkg_whitelist)
+ MANAGER.extension_package_whitelist.update(self.config.extension_pkg_allow_list)
+ if self.config.extension_pkg_whitelist:
+ MANAGER.extension_package_whitelist.update(
+ self.config.extension_pkg_whitelist
+ )
for msg_cat in MSG_TYPES.values():
self.stats[msg_cat] = 0
diff --git a/pylintrc b/pylintrc
index 47b7d28cc..c00c27eb2 100644
--- a/pylintrc
+++ b/pylintrc
@@ -29,7 +29,7 @@ unsafe-load-any-extension=no
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
-extension-pkg-whitelist=
+extension-pkg-allow-list=
[MESSAGES CONTROL]