Skip to content

CSP-P006: Deep Attribute Access in Loop

Category: Performance

Severity: LOW

Description

Repeated deep attribute access inside loops can be hoisted into a local variable.

Vulnerable Code Example

for item in items:
    value = item.user.profile.settings.theme
    handle(value)

Safer Code Example

for item in items:
    settings = item.user.profile.settings
    handle(settings.theme)

How to Suppress a Finding

# ignore
# or
# noqa: CSP-P006