Skip to content

Commit

Permalink
Extend doc for redefined-builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlyj committed Jan 4, 2025
1 parent 0d5439b commit 4e9c09b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/data/messages/r/redefined-builtin/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The `allowed-redefined-builtins <https://pylint.readthedocs.io/en/stable/user_guide/configuration/all-options.html#allowed-redefined-builtins>`_
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.

0 comments on commit 4e9c09b

Please sign in to comment.