McCabe complexity for just changed files in a commit?

Kushal Kumaran kushal at
Tue Oct 5 01:36:25 EDT 2021

On Tue, Oct 05 2021 at 03:55:22 PM, Chris Angelico <rosuav at> wrote:
> On Tue, Oct 5, 2021 at 3:44 PM Kushal Kumaran <kushal at> wrote:
>> On Sat, Oct 02 2021 at 09:05:47 PM, Dan Stromberg <drsalists at> wrote:
>> > Hi folks.
>> >
>> > Is there a way of getting the McCabe Complexity of just the functions and
>> > methods (in Python) changed in a git commit?
>> >
>> > I found radon, and it looks good.  But I think it wants to do entire files,
>> > no?
>> >
>> Calculate your metric for this commit, calculate metric for parent
>> commit, and take the difference?  That's how we do coverage metrics to
>> report stuff like "change increases/decreases coverage by N%".
> What if it has multiple parents, like a merge commit that resolves conflicts?
> (A merge that doesn't make any other changes won't affect coverage or
> complexity, since it's all done by the commits on either side.)

In my usecases, merges are asymmetric: one of the parents is useful for
reporting metric changes, and the others are not.  The parent of
interest will be whichever parent was on the mainline branch (first
parent).  Whether the merge commit resolved conflicts or not makes no
difference here.

In practice, this does not involve doing commit math.  The point where
this kind of thing is done is in context of a pull request, where it is
clearer what commits you're interested in comparing.  When merging
branch X into branch Y, the tools only need to look at the heads of
those branches. is a random
example of the kind of thing I'm thinking of.


More information about the Python-list mailing list