ImportError: cannot import name ‘_unicodefun’ from ‘click’

if running our lint checks with the python black pkg. an error comes up

ImportError: cannot import name '_unicodefun' from 'click' (/Users/robot/.cache/pre-commit/repo3u71ccm2/py_env-python3.9/lib/python3.9/site-packages/click/__init__.py)

related issues:

https://github.com/psf/black/issues/2976
https://github.com/dask/distributed/issues/6013

 

Answer 1

This has been fixed by Black 22.3.0. Versions before that won’t work with click 8.1.0.

https://github.com/psf/black/issues/2964

E.g.: black.yml

 

          python-version: 3.8
      - name: install black
        run: |
-          pip install black==20.8b1
+          pip install black==22.3.0
      - name: run black
        run: |
          black . --check --line-length 100

https://github.com/Clinical-Genomics/cgbeacon2/pull/221/files

As a workaround pin click to last version via pip install --upgrade click==8.0.2