vulnerablecode icon indicating copy to clipboard operation
vulnerablecode copied to clipboard

fix: replace improper None comparisons and remove duplicate dict key

Open shbhmexe opened this issue 1 month ago • 0 comments

Summary

This PR fixes code quality issues identified during a repository audit, focusing on Python best practices (PEP 8) and code correctness.

Changes Made

1. Fixed Improper None Comparisons (PEP 8 E711)

Replaced == None and != None with is None and is not None in test files:

  • vulnerabilities/tests/pipelines/test_pipeline_id.py (line 56)
  • vulnerabilities/tests/test_improve_runner.py (line 210)
  • vulnerabilities/tests/pipelines/v2_importers/test_xen_importer_v2.py (line 102)

Reasoning: PEP 8 recommends using is or is not when comparing to None rather than equality operators. This is both a style issue and can prevent bugs since __eq__ can be overridden.

2. Fixed Duplicate Dictionary Key

Removed duplicate "references" key in test_improve_runner.py (line 185):

  • The dictionary had "references" defined on both line 182 and 185
  • The second occurrence overwrites the first, which is likely unintentional
  • Based on the value type (VulnerabilitySeverity), line 185 should use the key "severity"

Reasoning: This is a functional bug where the first "references" value was being silently overwritten by the duplicate key.

Impact

  • Scope: Test files only - no production code affected
  • Risk: Very low - these are safe, non-breaking changes
  • Benefits:
    • Improved code quality and PEP 8 compliance
    • Fixed potential bug in test helper function
    • Better maintainability

Testing

All changes are in test files. The affected tests validate:

  • Pipeline ID validation logic
  • Vulnerability and alias creation with empty inputs
  • Xen importer advisory parsing

The changes maintain the same test behavior - they just use the correct Python idioms for None comparisons and fix the dictionary key issue.

Checklist

  • [x] Changes follow PEP 8 style guidelines
  • [x] No functional changes to production code
  • [x] All changes are in test files only
  • [x] Commit message includes DCO sign-off
  • [x] Changes improve code quality without breaking existing functionality

shbhmexe avatar Nov 27 '25 10:11 shbhmexe