Skip to content

How to limit line-length when creating outputs for doctest using --doctest-plus-generate-diff=overwrite #287

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

Open
d-chris opened this issue Mar 29, 2025 · 9 comments
Labels

Comments

@d-chris
Copy link
Contributor

d-chris commented Mar 29, 2025

Question

is it possible to limit the line-length of the output created, using --doctest-plus-generate-diff=overwrite

ruff complains about the total length and i didn't find a settings to wave E501 for doctest outputs.

python-validators/validators#417 (comment)

Solutions

  • automatically let doctest-plus add an optional noqa: E501
  • format the output in a way, linter does not complain

how do you guys handle this?

@pllim
Copy link
Contributor

pllim commented Mar 31, 2025

We cannot assume all packages that use this package follow that rule nor know how the max length they choose (I mean, we could but combing through all the possible settings for arbitrary repo is painful and out of scope). Can't downstream fix style manually after generating this diff? It doesn't have to be perfect on the first go.

@pllim pllim added the question label Mar 31, 2025
@bsipocz
Copy link
Member

bsipocz commented Mar 31, 2025

I would pass this on to ruff to deal with it and definitely would prefer not to pepper noqa into the generated outputs.

(a quick googling suggests that they have some dynamic rule sets that deals with long docstring lines. Otherwise, in my experience, this function already generates reasonable looking outputs for ellipsis included in the middle).

All that being said, if you add a new linelenght param I would consider adding it. --doctest-plus-generate-lineleght or a similar mouthful.

@d-chris
Copy link
Contributor Author

d-chris commented Mar 31, 2025

so basically you guys never had that kind of issue/problem? 🤔

@pllim
Copy link
Contributor

pllim commented Mar 31, 2025

I haven't come across the need to use this yet as it is pretty new feature and the docs I maintain were written long ago. So I'll defer to @bsipocz and @seberg . 😅

@bsipocz
Copy link
Member

bsipocz commented Mar 31, 2025

I often use this for astroquery/pyvo, and never run into the particular issue. I do deal a lot with long table rows but the outputs generated were always reasonably ellipsed so it never really triggered a code style check failure (but we also don't use ruff/black and such overly opinionated formatters for those packages).

@seberg
Copy link
Contributor

seberg commented Mar 31, 2025

Not sure, I have never actually used it myself (I was hoping to for NumPy to fix the scalar reprs, but since there will be some other quirks to fight with in NumPy, I never did...)

Some line-lenght option seems reasonable, although I am not quite sure if it is always obvious how to even wrap the lines?
(TBH, I am not even sure how to do this manually without failing doc-tests. Is there a "line continuation" for output?)

@bsipocz
Copy link
Member

bsipocz commented Mar 31, 2025

I am not quite sure if it is always obvious how to even wrap the lines?

I'm not sure we want to wrap lines ever, but to force ellipses into them?

@seberg
Copy link
Contributor

seberg commented Mar 31, 2025

Yeah, but then you need a heuristic for what to omit? We do allow hooking into the replacement, IIRC, so maybe this would be an example for such a hook? (I.e. even just modifying the existing example stub that came from my fight with numpy)
(Check the readme, the diff-hook can replace got with something containing an ellipsis if long.)

@bsipocz
Copy link
Member

bsipocz commented Mar 31, 2025

I would only support such a line-leght option if it is strictly opt-in. So ideally no change to the default behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants