black
black copied to clipboard
Fix 4399 `ASTSafetyError` on comment in return type annotation
Description
Resolves #4399
Added an extra check before adding commas to the elements in the body of a bracket split.
The check ensures that there is more than just one non-comment item in the list of return elements. It only performs this check for a bracket split in return annotations as it's non-problematic for parameter annotations.
The extra comment was causing the ASTSafetyError (it led to the return type being interpreted as a tuple).
Checklist - did you ...
- [x] Add an entry in
CHANGES.mdif necessary? - [x] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?