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

Exclude string type annotations from ESP #3462

Merged
merged 7 commits into from Dec 20, 2022

Conversation

yilei
Copy link
Contributor

@yilei yilei commented Dec 20, 2022

Description

This PR excludes string type annotations from ESP, and also fixes crash on mismatched brackets from ESP.

  1. Unfortunately pyright doesn't support stringified annotations that span multiple lines, e.g.:
def something(
    arg,
) -> (
    "VeryLongClassNameWithAwkwardGenericSubtype[int] |"
    "VeryLongClassNameWithAwkwardGenericSubtype[str]"
):
    ...

Even though other type checkers (mypy, pytype, pyre) do support them. To be safe, we can choose to exclude them from ESP for now. Note we could technically choose to try merging them into a single string when the result fits in the line-length, but this would be more complicated than simply excluding them from ESP.

  1. The crash is because of unmatched brackets. In ESP, it can process lines continued from earlier line breaks, e.g.:
def something(
    arg,
) -> "VeryLongClassNameWithAwkwardGenericSubtype[int] | VeryLongClassNameWithAwkwardGenericSubtype[str]":
    ...

The line can be ) -> "VeryLongClassNameWithAwkwardGenericSubtype[int] |VeryLongClassNameWithAwkwardGenericSubtype[str]": while processing. This PR makes BracketTracker.mark accept unmatched closing brackets.

Fixes #3435. Fixes #3457.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Dec 20, 2022

diff-shades reports zero changes comparing this PR (926bdd1) to main (9ce7572).


What is this? | Workflow run | diff-shades documentation

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

src/black/brackets.py Outdated Show resolved Hide resolved
src/black/brackets.py Outdated Show resolved Hide resolved
yilei and others added 2 commits December 19, 2022 22:49
@JelleZijlstra JelleZijlstra merged commit a44dc3d into psf:main Dec 20, 2022
hugovk pushed a commit to hugovk/black that referenced this pull request Jan 16, 2023
@yilei yilei deleted the stringannotations branch March 17, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants