You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Pydriller中'FunctionInfo'对象无'fan_in'属性的AttributeError?

Fixing AttributeError: 'FunctionInfo' object has no attribute 'fan_in' in Pydriller

You're hitting this error when running your Pydriller code to fetch commit details including DMM metrics:

Your Code:

from pydriller import RepositoryMining
for commit in RepositoryMining (path_to_repo='https://github.com/openssl/openssl', only_commits=['9cedfc90cebc905b20275d534699a1070bba65a4']).traverse_commits():
    commit_row = {
        'hash': str(commit.hash),
        'msg': str(commit.msg),
        'author_date': str(commit.author_date),
        'merge': str(commit.merge),
        'dmm_unit_size': str(commit.dmm_unit_size)
    }
print(commit_row)

Error Output:

Traceback (most recent call last):
File "/Volumes/GoogleDrive/Shared drives/guru_shared/guru_research/CVE-code-extraction/Code/example_extraction.py", line 30, in <module>
    'dmm_unit_size': str(commit.dmm_unit_size)
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 687, in dmm_unit_size
    return self._delta_maintainability(DMMProperty.UNIT_SIZE)
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 735, in _delta_maintainability
    delta_profile = self._delta_risk_profile(dmm_prop)
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 752, in _delta_risk_profile
    deltas = [mod._delta_risk_profile(dmm_prop) for mod in supported_modifications]
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 752, in <listcomp>
    deltas = [mod._delta_risk_profile(dmm_prop) for mod in supported_modifications]
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 386, in _delta_risk_profile
    low_before, high_before = self._risk_profile(self.methods_before, dmm_prop)
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 336, in methods_before
    self._calculate_metrics(include_before=True)
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 406, in _calculate_metrics
    self._function_list.append(Method(func))
File "/usr/local/lib/python3.8/site-packages/pydriller/domain/commit.py", line 80, in __init__
    self.fan_in = func.fan_in
AttributeError: 'FunctionInfo' object has no attribute 'fan_in'

What's Causing This?

This is a compatibility clash between Pydriller and the radon library it uses to calculate code maintainability metrics:

  • Radon is the tool Pydriller relies on to compute values like fan-in/fan-out for DMM metrics
  • Starting with Radon v5.2.0, the attribute name for fan-in changed from fan_in (with underscore) to fanin (no underscore)
  • Your installed version of Pydriller hasn't been updated to recognize this name change, so it's still trying to access the old fan_in attribute that no longer exists.

Solutions

Pick one of these fixes based on your dependency preferences:

1. Downgrade Radon to a Compatible Version

This is the fastest fix if you don't want to update Pydriller. Install the last Radon version that uses the original attribute name:

pip install radon==5.1.0

After downgrading, re-run your code—it should work without the AttributeError.

2. Upgrade Pydriller to the Latest Version

If you prefer keeping dependencies up-to-date, upgrade Pydriller to a version that's been patched to support both old and new Radon attribute names:

pip install --upgrade pydriller

Most recent Pydriller releases (v3.4.0+) include this fix, so this should resolve the issue cleanly.

3. Temporary Workaround (Skip DMM Metrics)

If you don't need the dmm_unit_size field right now, simply remove that line from your commit_row dictionary. Your code will run perfectly fine without it:

from pydriller import RepositoryMining
for commit in RepositoryMining (path_to_repo='https://github.com/openssl/openssl', only_commits=['9cedfc90cebc905b20275d534699a1070bba65a4']).traverse_commits():
    commit_row = {
        'hash': str(commit.hash),
        'msg': str(commit.msg),
        'author_date': str(commit.author_date),
        'merge': str(commit.merge)
        # Removed dmm_unit_size temporarily
    }
print(commit_row)

内容的提问来源于stack exchange,提问作者Guru Bhandari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:32:27