-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
split long function parameter type hints without parentheses #3930
Conversation
diff-shades results comparing this PR (c1bdad7) to main (738c278). The full diff is available in the logs under the "Generate HTML diff report" step.
|
Hmm, looking at the preview diffs I think I might always want a newline after the colon. So we get extLst: Typed[ExtensionList, Literal[True]]
__elements__: ClassVar[tuple[str, ...]]
def __init__(
self,
custUnit: _HasTagAndGet[_ConvertibleToFloat | None] | _ConvertibleToFloat | None = None,
builtInUnit:
_HasTagAndGet[_DisplayUnitsLabelListBuiltInUnit]
| _DisplayUnitsLabelListBuiltInUnit
| Literal["none"]
| None
= None,
dispUnitsLbl: DisplayUnitsLabel | None = None,
extLst: Unused = None,
) -> None: ...
class NumericAxis(_BaseAxis): though I'm also personally starting to lean towards this maybe not being much of an improvement, if at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but several of the test cases look quite bad to me. I'd prefer option (1) in Sebastian's issue: parenthesize it.
None, title="Some long title", description="Some long description" | ||
) | ||
q: str | ||
| None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old style was much better here.
), | ||
max_jobs: int | ||
| None | ||
= Option( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
| loooooooooooooooooooooooooooong | ||
| looooooooooong | ||
| looooooooooong | ||
= 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these examples with defaults look bad. It's as if we're doing long division.
Sounds like we're all in agreement - a shame to toss out the work I did on this, but I'm quite comfortable in the black codebase now at least! Closing the PR~ |
Description
Resolves #2316 according to the
nextline
strategy. The poll is currently 10 to 6 of favor of this style, which certainly isn't a slam-dunk, but enough for me to implement it and we can progress the discussion after seeing impacts on existing code.This is a pretty messy implementation, as can be seen by the sheer length and the complexity check having made me reformat my code several times to break out functions.
I don't love the existence of
_split_first_typehint
and feel like that should be handled on a second pass bydelimiter_split
or something. And likewise I ideally wouldn't need any changes invisit_tname
after #3899 - I don't really remember why I gave up on resolving it while keeping invisible lpars.I started out with
append_to_line
being a subfunction like indelimiter_split
andstandalone_comment_split
, but when the complexity check for good reason wanted me to break up_split_tname
I ended up having to add some helper functions toLine
andBracketTracker
, and while this is not super pretty it's probably better than havingappend_to_line
repeated three times over in the code - and the other uses of it should probably be changed to use_append_to_line
as well.I stumbled upon #3834 just as I thought myself done, and realized that case should clearly also be handled without parentheses. I'm not entirely sure why it isn't, but will probably add that to this PR.derp, it can't use thenextline
strategy as per normal type hints since they're not inside parentheses and nottname
s. This differentiation being one of the downsides of special-casing parameter lists.Checklist - did you ...
CHANGES.md
if necessary?