What's the difference between granular and broad analysis scopes?

  • In Granular mode, issues will be reported only on newly added (or) modified lines and newly introduced issues on the file due to changed lines.

  • In Broad mode, all the issues of that file are raised. (new + existing)

Consider a file foo.py:

import sys


FOO = [(yield x) for x in range(3)]
BAR = ((yield x) for x in range(3))
print(sys.version)

When the file is analyzed for the very first time, issues raised in both Granular and Broad mode are the same.

PTC-W0025 at line 4 (`yield` statement inside a comprehension)
PTC-W0026 at line 5 (`yield` statement inside a generator expression)

Now, consider a PR is raised modifying foo.py as:

import sys


FOO = [(yield x) for x in range(3)]
BAR = ((yield x) for x in range(3))
CPU = os.cpucount()

When a new DeepSource check is created for this change, here are the issues reported in both modes:

Granular Mode:
PYL-W0611 at line 1 (Unused import `sys`)
PYL-E0602 at line 6 (Undefined variable `os`)

Since issues at line 4 and line 5 (PTC-W0025 and PTC-W0026) already exist, they aren’t reported.
Line 6 has been modified, which introduced PYL-E0602 at line 6 and PYL-W0611 at line 1.

Note: Even though line 1 was not modified, but a change at line 6 was the reason for making the import at line number 1 to be unused, hence the issue is reported.

Broad mode:
PYL-W0611 at line 1 (Unused import `sys`)
PTC-W0025 at line 4 (`yield` statement inside a comprehension)
PTC-W0026 at line 5 (`yield` statement inside a generator expression)
PYL-E0602 at line 6 (Undefined variable `os`)

This will always show all the issues raised for the whole file.

1 Like