Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black 24.1.0 breaks code formatting if wrap-string-literal is set #1821

Closed
airwoodix opened this issue Jan 26, 2024 · 1 comment · Fixed by #1829
Closed

Black 24.1.0 breaks code formatting if wrap-string-literal is set #1821

airwoodix opened this issue Jan 26, 2024 · 1 comment · Fixed by #1829
Labels
bug Something isn't working

Comments

@airwoodix
Copy link
Contributor

Describe the bug

Black 24.1.0 was just released and removes support for the deprecated --experimental-string-processing flag (psf/black#4096). This breaks the code in format.py that uses this option:

Traceback (most recent call last):
  File ".../python3.11/site-packages/datamodel_code_generator/__main__.py", line 429, in main
    generate(
  File ".../python3.11/site-packages/datamodel_code_generator/__init__.py", line 463, in generate
    results = parser.parse()
              ^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/datamodel_code_generator/parser/base.py", line 1156, in parse
    code_formatter: Optional[CodeFormatter] = CodeFormatter(
                                              ^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/datamodel_code_generator/format.py", line 152, in __init__
    self.black_mode = black.FileMode(
                      ^^^^^^^^^^^^^^^
TypeError: Mode.__init__() got an unexpected keyword argument 'experimental_string_processing'

Expected behavior

No crash.

Version:

  • OS: Linux
  • Python version: 3.11
  • datamodel-code-generator version: 0.25.2
  • black version: 0.24.1

Additional context

Possible mitigation:

  • add a temporary upper bound to the black version spec in pyproject.toml
  • same, but in user environment definitions
  • use --preview --enable-unstable-feature string_processing instead (as suggested by the black release notes).
@koxudaxi koxudaxi added the bug Something isn't working label Jan 30, 2024
@koxudaxi
Copy link
Owner

@airwoodix
Thank you for creating the issue.
OK, we should fix it.

airwoodix added a commit to airwoodix/datamodel-code-generator that referenced this issue Feb 1, 2024
koxudaxi added a commit that referenced this issue Feb 1, 2024
* format: support black >=24

Fixes #1821

* format: refine string_processing detection for black >= 24

* Add test pattern

* Ignore unsupported tests

---------

Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
anssari1 added a commit to ExpediaGroup/expediagroup-python-sdk that referenced this issue Feb 19, 2024
<!--
Thank you for submitting a pull request!

Please verify that:
* [x] Code is up-to-date with the `main` branch.
* [x] You've successfully built and run the tests locally.
* [ ] There are new or updated unit tests validating the change.

Refer to CONTRIBUTING.md for more details.
-->

### 📝 Description
- Downgrade Black dependency
(koxudaxi/datamodel-code-generator#1821)
- Update "user-agent" header value to match other SDK languages
- Add "x-sdk-title" to request headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants