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

docstring-code-line-length = "dynamic" not Working Correctly #14984

Closed
Bibo-Joshi opened this issue Dec 15, 2024 · 4 comments
Closed

docstring-code-line-length = "dynamic" not Working Correctly #14984

Bibo-Joshi opened this issue Dec 15, 2024 · 4 comments
Labels
formatter Related to the formatter needs-info More information is needed from the issue author

Comments

@Bibo-Joshi
Copy link

Hey. I found another instance where docstring-code-line-length = "dynamic" is not corking correctly. I've already seen #13358, but the fix for that apparently is not sufficient for the following example:

"""This is a module docstring


Example:
    .. code-block:: python

        SomeClass(long_param_name_1="long_param_value_1", a_very_long_param_name_2="long_param_value_2")
"""


class SampleClass:
    """This is a class docstring

    Example:
        .. code-block:: python

            SomeClass(
                long_param_name_1="long_param_value_1", a_very_long_param_name_2="long_param_value_2"
            )
    """

Output:

(.venv313) ~\PycharmProjects\chango git:[section-note]
ruff --version
ruff 0.8.3
(.venv313) ~\PycharmProjects\chango git:[section-note]
ruff format foo.py --line-length 99
1 file left unchanged
(.venv313) ~\PycharmProjects\chango git:[section-note]
ruff check foo.py --line-length 99
foo.py:7:100: E501 Line too long (104 > 99)
  |
5 |     .. code-block:: python
6 | 
7 |         SomeClass(long_param_name_1="long_param_value_1", a_very_long_param_name_2="long_param_value_2")
  |                                                                                                    ^^^^^ E501
8 | """
  |

foo.py:18:100: E501 Line too long (101 > 99)
   |
17 |             SomeClass(
18 |                 long_param_name_1="long_param_value_1", a_very_long_param_name_2="long_param_value_2"
   |                                                                                                    ^^ E501
19 |             )
20 |     """
   |

Found 2 errors.

Unfortunately, I don't know enough about rust to dig into this myself.

Thanks for the great tool, btw ❤

@MichaReiser MichaReiser added formatter Related to the formatter needs-info More information is needed from the issue author labels Dec 15, 2024
@MichaReiser
Copy link
Member

Hi.

Can you tell me more about what settings you're using (line lengths, preview mode?).

@Bibo-Joshi
Copy link
Author

Ah, damn, I forgot the --isolated … But Apparently you can't set docstring-code-format via the command line, so I reduced my config to this minimal set:

[tool.ruff]
line-length = 99

[tool.ruff.lint]
select = ["E501"]

[tool.ruff.format]
docstring-code-format = true

Sorry, should have thought of that

@MichaReiser
Copy link
Member

No worries and thanks for the details. I can reproduce your problem when format.preview = false. This makes sense to me because the fix for #13358 hasn't been promoted to the stable style yet, because it can change the formatting of existing code.

Can you try setting tool.ruff.format.preview = true but be careful to have a backup of your code (e.g. commit all your changes) because the preview style has a few experimental formattings that you might not like. Or you can try it in our Playground (here with preview = true).

You can subscribe to #13371 to be notified when we promote the fix to stable. We plan to do so in early January.

@Bibo-Joshi
Copy link
Author

Awesome, thanks for the explanation! I'll close, then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter needs-info More information is needed from the issue author
Projects
None yet
Development

No branches or pull requests

2 participants