Mutable module level variables
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 123
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
Mutable module level variables might lead to bugs
file: a.py
SOME_CONSTANT = [1,5,7]
file: b.py
from a import SOME_CONSTANT
if bla:
SOME_CONSTANT.remove(5)
assert i in SOME_CONSTANT:
The correct thing to do would be to use:
a.py
SOME_CONSTANT = (1,5,7)
Mutable module level variables should be reported similar to B006: Do not use mutable data structures for argument defaults.
While this might lead to false positives we could either:
- Only signal on YELLING_CASE variables
- Make it an opinionated and thus disabled by default lint (in which case I would argue #57 belongs there as well)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing B006 implementation and the plugin's check registration and test entry points; the issue provides a.py and b.py examples to use as the initial cases. Decide and document the handling of false positives, including YELLING_CASE variables or an opt-in check, then add coverage showing that mutable module-level variables are reported as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100