Skip to content

Comments

Exclude string type annotations from ESP#3462

Merged
JelleZijlstra merged 7 commits intopsf:mainfrom
yilei:stringannotations
Dec 20, 2022
Merged

Exclude string type annotations from ESP#3462
JelleZijlstra merged 7 commits intopsf:mainfrom
yilei:stringannotations

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!

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