jendrikseipp: The file looks good. Now we only need a test case under `tests/test_whitelist_python.py`. It should check that whitelist_python.py can be run by Python without errors and that code using the `default_factory` attribute is not marked as unused. You can look at `tests/test_script.py` to find out how to test Python files.
RJ722: HI! @jendrikseipp 
Is the current approach in testing (adding an example file and running vulture on it) feasible?

jendrikseipp: This is the only way to test whitelist files. However, normal code 
snippets should be tested in the same way as in `test_scavenging.py`. If 
you're adding multiple tests that belong together, you may consider 
adding a separate test file for that, like `test_format_strings.py`.

RJ722: Thanks! :smile: 

Also, one thing I thought was necessary to bring to your attention was that I have named the example file with a `.txt` extension, because otherwise with the `.py`, it will cause the tests to fail as it would try to run vulture over example file without taking whitelist into consideration!

Also, do we need extra test_cases here?
RJ722: Hi! @jendrikseipp 
Does this looks all right or do we need further enhancements?
diff --git a/whitelist_python.py b/whitelist_python.py
new file mode 100644
index 0000000..8e459e6
--- /dev/null
+++ b/whitelist_python.py
@@ -0,0 +1,4 @@
+import collections
+
+collections.defaultdict(list).default_factory = None
+collections.defaultdict(list).default_factory

Whitelist defaultdict.default_factory
Originally reported by: **bitserver (Bitbucket: [bitserver](https://bitbucket.org/bitserver), GitHub: [bitserver](https://github.com/bitserver))**

----------------------------------------

I have a collections.defaultdict(). After I have finished populating it, I have to set its default_factory attribute to None. vulture then tells me that default_factory is an unused attribute, but I can't help it, as that's how defaultdict works.

----------------------------------------
- Bitbucket: https://bitbucket.org/jendrikseipp/vulture/issue/21

diff --git a/tests/test_whitelist_python.py b/tests/test_whitelist_python.py
new file mode 100644
index 0000000..3529af0
--- /dev/null
+++ b/tests/test_whitelist_python.py
@@ -0,0 +1,15 @@
+import subprocess
+import sys
+
+from .test_script import call_vulture, REPO
+
+whitelist_file = 'whitelist_python.py'
+
+
+def test_whitelist_python_with_python():
+    assert subprocess.call(
+        [sys.executable, whitelist_file], cwd=REPO) == 0
+
+
+def test_whitelist_python_with_vulture():
+    assert call_vulture([whitelist_file]) == 0

pip install -e .
parse_log_pytest
pytest
pytest pytest-cov
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
coverage==7.8.0
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
pytest-cov==6.0.0
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
-e git+https://github.com/jendrikseipp/vulture.git@bae51858abe19f3337e5e17cbb170533161d634a#egg=vulture

name: vulture
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==7.8.0
      - pytest-cov==6.0.0
prefix: /opt/conda/envs/vulture

tests/test_whitelist_python.py::test_whitelist_python_with_python tests/test_whitelist_python.py::test_whitelist_python_with_vulture
whitelist_python.py
whitelist_python.py