Skip to content

Conversation

lukehinds
Copy link
Member

The B107 check was incorrectly flagging None default values as hardcoded passwords in function definitions. This is a false positive since None is a legitimate and commonly used within init initialization

This change modifies the hardcoded_password_default function to:

  • Skip None values in parameter defaults
  • Handle both ast.Constant (Python 3.8+) and ast.NameConstant (Python 3.7-) representations of None
  • Update documentation to clarify None handling behavior

Example of code that no longer triggers B107:
def init(self, auth_scheme, auth_password=None):
pass

Fixes: #1227

The B107 check was incorrectly flagging None default values as hardcoded
passwords in function definitions. This is a false positive since None is a
legitimate and commonly used within __init__ initialization

This change modifies the hardcoded_password_default function to:
- Skip None values in parameter defaults
- Handle both ast.Constant (Python 3.8+) and ast.NameConstant (Python 3.7-)
  representations of None
- Update documentation to clarify None handling behavior

Example of code that no longer triggers B107:
def __init__(self, auth_scheme, auth_password=None):
    pass

Fixes #PyCQA#1227
@ericwb ericwb merged commit def123a into PyCQA:main Feb 10, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False-positive B107:hardcoded_password_default with None parameter
3 participants