Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-131507: Clean up tests and type checking for_pyrepl#131509

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 6 commits intopython:mainfromambv:pyrepl-sh-refactor-tests
Mar 21, 2025

Conversation

ambv
Copy link
Contributor

@ambvambv commentedMar 20, 2025
edited by bedevere-appbot
Loading

This is a prerequisite for the syntax highlighting change, but a separate PR so that this can be backported to 3.13 for ease of maintenance in the future.

The separate commits explain the separate steps:

  • remove a hack for zero-width escape code bracketing
  • refactor tests to allowassert_screen_equal in more places
  • make_colorize better: enumerate all ANSI colors, make type checking pass
  • upgrade mypy checks to use 3.13 and allow usingLib/_colorize.py in the checks (via aMisc/mypy/ trick with symlinks, let's see how that works out)

@ambvambv added skip news needs backport to 3.13bugs and security fixes labelsMar 20, 2025
ambv added a commit to ambv/cpython that referenced this pull requestMar 20, 2025
ambv added a commit to ambv/cpython that referenced this pull requestMar 20, 2025
ambv added a commit to ambv/cpython that referenced this pull requestMar 20, 2025
Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

Looks good in general, minor nit in docstring

Comment on lines +426 to +428
The prompt string has the zero-width brackets recognized by shells
(\x01 and \x02) removed. The length ignores anything between those
brackets as well as any ANSI escape sequences.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Thepromptstringhasthezero-widthbracketsrecognizedbyshells
(\x01and \x02)removed.Thelengthignoresanythingbetweenthose
bracketsaswellasanyANSIescapesequences.
Thepromptstringhasthezero-widthbrackets(\x01and \x02)
recognizedbyshellsremoved.Thelengthignoresanythingbetween
thosebracketsaswellasanyANSIescapesequences.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Is this an improvement? There are many kinds of zero-width brackets, the ones I am interested in are those recognized by shells (\x01 and \x02). The original docstring uses that ordering then.

return length - sum(len(i) for i in sequence) + ctrl_z_cnt


def unbracket(s: str, including_content: bool = False) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

👍 I like this approach. I was concerned about the regular expressions performance but couldn't find anything too bad when testing



def multiline_input(reader: ReadlineAlikeReader, namespace: dict | None = None):
saved = reader.more_lines
try:
reader.more_lines = partial(more_lines, namespace=namespace)
reader.ps1 = reader.ps2 = ">>>"
reader.ps3 = reader.ps4 = "..."
reader.ps1 = reader.ps2 = ">>> "
Copy link
Member

Choose a reason for hiding this comment

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

Why the extra space?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Because that's how the real prompts are in production. I didn't want the difference in tests since it was confusing for syntax highlighting later.

@@ -421,42 +421,15 @@ def calc_screen(self) -> list[str]:

@staticmethod
def process_prompt(prompt: str) -> tuple[str, int]:
Copy link
Member

Choose a reason for hiding this comment

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

I may be missing something but looks like the old function was tracking nested ANSI escape seas outside\x01 and\x02 brackets but this one drops this no? What is the rationale?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

There are three things the old function was trying to do (badly):

  • ignore anything between \001 and \002 for length calculation; and
  • remove \001 and \002 characters from the emitted prompt; and
  • also ignore any ANSI escape sequences from length calculation.

Since wlen() is already doing 3., a contributor here needed to recreate this function to not do that, because we were doing that later anyway. But it's simpler to just use the main wlen() with a string stripped of \001 .. \002 bracketed content.

I find the new form much easier on the eyes.

Copy link
Member

@pablogsalpablogsal left a comment

Choose a reason for hiding this comment

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

LGTM left some comments

@ambvambv merged commit5d8e981 intopython:mainMar 21, 2025
51 checks passed
@miss-islington-app
Copy link

Thanks@ambv for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@ambv, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 5d8e981c8477ce483374b2fe6cd309a08c956299 3.13
ambv reacted with eyes emoji

ambv added a commit to ambv/cpython that referenced this pull requestMar 21, 2025
pythonGH-131509)(cherry picked from commit5d8e981)Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@bedevere-app
Copy link

GH-131546 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMar 21, 2025
ambv added a commit to ambv/cpython that referenced this pull requestMar 21, 2025
@ambvambv deleted the pyrepl-sh-refactor-tests branchMarch 21, 2025 14:59
ambv added a commit that referenced this pull requestMar 21, 2025
ambv added a commit that referenced this pull requestMar 21, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 21, 2025
…thonGH-131547)This is based offpythonGH-131509.(cherry picked from commit4cc82ff)Co-authored-by: Łukasz Langa <lukasz@langa.pl>
ambv added a commit that referenced this pull requestMar 21, 2025
…H-131547) (GH-131557)gh-131507: Refactor screen and cursor position calculations (GH-131547)This is based offGH-131509.(cherry picked from commit4cc82ff)Co-authored-by: Łukasz Langa <lukasz@langa.pl>
seehwan pushed a commit to seehwan/cpython that referenced this pull requestApr 16, 2025
seehwan pushed a commit to seehwan/cpython that referenced this pull requestApr 16, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@pablogsalpablogsalpablogsal approved these changes

@hugovkhugovkAwaiting requested review from hugovkhugovk is a code owner

@lysnikolaoulysnikolaouAwaiting requested review from lysnikolaoulysnikolaou is a code owner

Assignees

@ambvambv

Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ambv@pablogsal@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp