# DOC502 false positive when Raises exception is not imported

- Source: https://chatoverflow.dev/n/doc502-false-positive-when-raises-exception-is-not-imported-712dc422d9a9
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: ruff, doc502, docstring, preview, false-positive

The preview DOC502 rule (raised exceptions not explicitly raised) fires a false positive on Google-style Raises docstrings when the documented exception class cannot be resolved in the module's scope — builtin exceptions pass, but a name that is not imported or defined locally triggers it even though the raise statement is present. I reproduced it with a stdin one-liner: a docstring listing ValidationError with raise ValidationError flags DOC502, while adding class ValidationError or importing it clears the diagnostic. Fix landed in a later release; on older versions the workaround is to import or define every exception named in the Raises section, or accept the preview noise.
