black: Incompatible with click 8.1.0 (ImportError: cannot import name '_unicodefun' from 'click')
Please use Black 22.3.0 (or newer) which was just released to fix this issue or pin Click to 8.0.0, 8.0.1, 8.0.2, 8.0.3, or 8.0.4.
~ @ichard26 at March 28 3:15 PM EST
So hey y’all, CI is broken eh?
Anyway, we are aware the most recent release of Click, 8.1.0, is breaking Black. This is because Black imports an internal module so Python 3.6 users with misconfigured LANG continues to work mostly properly. The code that patches click was supposed to be resilient to the module disappearing but the code was catching the wrong exception.
To unbreak your CI, please pin Click to 8.0.0, 8.0.1, 8.0.2, 8.0.3, or 8.0.4. We are working on a more longterm fix (probably fixing the patching code or getting rid of it entirely) and will try to get a release out soon.
~ @ichard26 at March 28 2:29 PM EST
Describe the bug
The Github Action step:
- name: Run black
uses: psf/black@stable
with:
options: "--check --diff"
version: "22.1.0"
fails with the following trackeback:
Traceback (most recent call last):
File "/home/runner/work/_actions/psf/black/stable/.black-env/bin/black", line 8, in <module>
sys.exit(patched_main())
File "src/black/__init__.py", line 1423, in patched_main
File "src/black/__init__.py", line 1[40](https://github.com/stumpylog/paperless-ngx/runs/5724998040?check_suite_focus=true#step:7:40)9, in patch_click
ImportError: cannot import name '_unicodefun' from 'click' (/home/runner/work/_actions/psf/black/stable/.black-env/lib/python3.8/site-packages/click/__init__.py)
To Reproduce
Run the black action on a Github runner, configured as above.
Expected behavior
The action should only fail if files are not formatted.
Environment
OS: runs-on: ubuntu-20.04
Version: 22.1.0
Action: @stable
Python version: 3.8 I believe
Additional context
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 241
- Comments: 40 (2 by maintainers)
Links to this issue
Commits related to this issue
- setup: pin `click` Works around https://github.com/psf/black/issues/2964 — committed to pypa/pip-audit by woodruffw 2 years ago
- pip_audit/dependency_source: match candidate names against project (#249) * pip_audit/dependency_source: match candidate names against project See: https://github.com/pypa/packaging/issues/527. ... — committed to pypa/pip-audit by woodruffw 2 years ago
- Unbreak black Move to the stable release and pin click, as black used the wrong exception to work around a click interaction causing issues. See https://github.com/psf/black/issues/2964 — committed to aio-libs/yarl by mjpieters 2 years ago
- Unbreak black Move to the stable release and pin click, as black used the wrong exception to work around a click interaction causing issues. See https://github.com/psf/black/issues/2964 — committed to aio-libs/yarl by mjpieters 2 years ago
- Unbreak black Move to the stable release and pin click, as black used the wrong exception to work around a click interaction causing issues. See https://github.com/psf/black/issues/2964 — committed to aio-libs/yarl by mjpieters 2 years ago
- Unbreak black Move to the stable release and pin click, as black used the wrong exception to work around a click interaction causing issues. See https://github.com/psf/black/issues/2964 — committed to aio-libs/yarl by mjpieters 2 years ago
- Pin click to run black [noissue] Ref: https://github.com/psf/black/issues/2964 — committed to fao89/plugin_template by fao89 2 years ago
- ci: pin click dependency to fix black See https://github.com/psf/black/issues/2964 — committed to psycopg/psycopg by dvarrazzo 2 years ago
- Unbreak black (#701) Move to the stable release and pin click, as black used the wrong exception to work around a click interaction causing issues. See https://github.com/psf/black/issues/2964 — committed to aio-libs/yarl by mjpieters 2 years ago
- Pin click to run black [noissue] Ref: https://github.com/psf/black/issues/2964 — committed to pulp/plugin_template by fao89 2 years ago
- Fix _unicodefun patch code for Click 8.1.0 (#2966) Fixes #2964 — committed to psf/black by JelleZijlstra 2 years ago
- ci: Upgrade black version to 22.3.0 CI is currently broken due to the latest release of `click` breaking the `black` CLI. Details here: https://github.com/psf/black/issues/2964. — committed to getsentry/arroyo by lynnagara 2 years ago
- Update to black 22.3.0 because of incompatibility with click. See https://github.com/psf/black/issues/2964 — committed to Spacetown/gcovr by Spacetown 2 years ago
- Update references to NEXT version with current version in documentation. (#584) Update to black 22.3.0 because of incompatibility with click. See https://github.com/psf/black/issues/2964 — committed to gcovr/gcovr by Spacetown 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/awkward by henryiii 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/boost-histogram by henryiii 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/cabinetry by henryiii 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/decaylanguage by henryiii 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/hepunits by henryiii 2 years ago
- fix: bump black to 22.3.0 due to click 8.1 release\n\nSee https://github.com/psf/black/issues/2964 for details. Committed via https://github.com/asottile/all-repos — committed to scikit-hep/hist by henryiii 2 years ago
For those that are running
blackviapre-commit, you can pinclickto8.0.4via the following:Update - new version is available
I just came here to open a very similar issue.
The issue is caused by the release of click 8.1.0.
Install
click==8.0.4Why was black importing an internal module? I was not expecting this to be the change that caused issues. Sorry about that.
We just released Black 22.3.0 with the fix. Sorry for the disruption everyone!
(There are no compiled wheels with the release yet, we’ll upload those shortly.)
We should probably pin to <8.1.0 for now. I can help get a release out later today to do that.
Well good news at least, that whole patch isn’t needed anymore, since Click itself is now at the same point of not raising locale encoding errors. 😄
@stumpylog try with locking
clicktoclick==8.0.1When running locally, after updating versions, try following commands:
can confirm this issue is fixed in black
22.3.0.This is wrong, if we still support Click 8.0.0 until 8.0.4, as long as the python_requires metadata is right pip will install the older acceptable click keeping everything working. Take this as a lesson to not jump to conclusions in stressful situations 😃
Oh wow, Click 8.1.0 drops support for Python 3.6. We will have to either drop 3.6 soon or pin Click up to 8.0.4.very wrong, see below+1: We have a failure in
pip-audithere: https://github.com/trailofbits/pip-audit/pull/249(
clickis strictly a subdependency of ours, so pinning it isn’t an ideal workaround.)@iboates you have an outdated version of Black in your pre-commit environment. See this comment for a possible solution: https://github.com/psf/black/issues/2964#issuecomment-1083591334
@ehontoria we don’t provide bugfixes for old releases. You need to either update to 22.3.0 or pin Click 8.1.0 (as @angel-langdon already said).
Note that thanks to our stability policy (https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy), upgrading from 22.1.0 should not cause any formatting changes.
@Edwardx89 you are running
pip freezeon yourpipeappvenv, butblackis installed and running under your isolatedpre-commitvenvYou are not running the version you think you are
@ehontoria This bug is fixed in
black==22.3.0you should update itpip listdoesn’t tell you anything about what version pre-commit uses, because pre-commit has their own virtualenvs for hooks and sets the version from your hook configuration.You can see the virtualenv path pre-commit created for black in your traceback:
so you’d have to run
/home/ebsym/.cache/pre-commit/repomlzam_dy/py_env-python3/bin/python -m pip listto see what versions are installed there.Bottom line: Edit your
.pre-commit-config.yamlfile instead.It is still not working:
Traceback (most recent call last): File “/home/ebsym/.cache/pre-commit/repomlzam_dy/py_env-python3/bin/black”, line 8, in <module> sys.exit(patched_main()) File “/home/ebsym/.cache/pre-commit/repomlzam_dy/py_env-python3/lib/python3.8/site-packages/black/init.py”, line 1282, in patched_main patch_click() File “/home/ebsym/.cache/pre-commit/repomlzam_dy/py_env-python3/lib/python3.8/site-packages/black/init.py”, line 1268, in patch_click from click import _unicodefun # type: ignore ImportError: cannot import name ‘_unicodefun’ from ‘click’ (/home/ebsym/.cache/pre-commit/repomlzam_dy/py_env-python3/lib/python3.8/site-packages/click/init.py)
@Edwardx89 it is working across the board for me, I don’t think you’re running the version you think you are.
Mypyc compiled wheels are now also available 🚀
The import doesn’t raise
ModuleNotFoundError, only a plainImportError, becausefrom click import _unicodefunis used.The code would need to be changed to
import click._unicodefun(andimport click.core) or catch the correct exception.