-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend documentation for
redefined-builtin
(#10167)
- Loading branch information
Showing
4 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The :ref:`allowed-redefined-builtins <variables-options>` option lets you specify names that are permitted to shadow built-ins. | ||
|
||
However, this option is not effective for redefinitions at the module level or for global variables. For example: | ||
|
||
Module-Level Redefinitions:: | ||
|
||
# module_level_redefine.py | ||
id = 1 # Shadows the built-in `id` | ||
|
||
Global Variable Redefinitions:: | ||
|
||
# global_variable_redefine.py | ||
def my_func(): | ||
global len | ||
len = 1 # Shadows the built-in `len` | ||
|
||
Rationale: | ||
|
||
Shadowing built-ins at the global scope is discouraged because it obscures their behavior | ||
throughout the entire module, increasing the risk of subtle bugs when the built-in is needed elsewhere. | ||
In contrast, local redefinitions are acceptable as their impact is confined to a specific scope, | ||
reducing unintended side effects and simplifying debugging. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[messages control] | ||
disable = invalid-name | ||
disable = invalid-name, global-variable-undefined | ||
[variables] | ||
allowed-redefined-builtins = dir, list | ||
allowed-redefined-builtins = dir, list, len |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
redefined-builtin:6:4:6:8:function:Redefining built-in 'dict':UNDEFINED | ||
redefined-builtin:9:0:9:4::Redefining built-in 'list':UNDEFINED | ||
redefined-builtin:14:4:14:7:global_variable_redefine:Redefining built-in 'len':UNDEFINED |