Skip to content

Conversation

@chris-eibl
Copy link
Member

@chris-eibl chris-eibl commented Jan 5, 2026

@smontanaro This should fix your issue.

Sorry, I cannot test because I have no Mac.

Also, I don't know why CI and buildbots did not complain before, see

if self.is_apple_terminal:
os.write(self.output_fd, b"\033[?7h")

self.is_apple_terminal = (
platform.system() == "Darwin"
and os.getenv("TERM_PROGRAM") == "Apple_Terminal"

safe_patterns.append(r'\x1b\[\?12[hl]') # cursor blinking

# rmam - turn off automatic margins
rmam = ti.get("rmam")
Copy link
Member Author

Choose a reason for hiding this comment

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

I've taken rmam from https://man7.org/linux/man-pages/man5/terminfo.5.html.

@ambv Should I add

       enter_am_mode               smam      SA     turn on automatic margins

as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please.

Chris, this didn't fail because the terminfo database can be different between computers depending on where you got it. I've seen IDEs override it, too, to work around issues with their custom built-in terminal emulators. Finally, while (almost) nobody does that, technically the terminfo database is user-editable and even allows addition of custom user-defined capabilities. So we'll likely have to do some whackamole with stuff we missed for a time, but that's alright. I had the same worry with replacing ncurses with a hand-rolled terminfo parser, but so far, so good. The only report we got so far there was from NetBSD.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, my setup is a stock MacOS Tahoe (26.2) running on an M1 MacBook Pro. I don't do framework builds. Tests are run in a normal MacOS Terminal app with TERM defined as xterm256color. While I refer to TERM in my various shell startup files, I do not change its value, nor do I see a file in /etc containing TERM.

Are the Mac buildbots testing framework builds? If so, what kind of terminal environment exists there? Perhaps the pyrepl tests should be run a few times with different (common?) values for TERM.

Copy link
Member Author

Choose a reason for hiding this comment

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

Chris, this didn't fail because the terminfo database can be different between computers depending on [...]

Thank you for the detailed explanation ❤️

Copy link
Member Author

Choose a reason for hiding this comment

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

Yet, I do not understand why e.g. CI passed previous to this PR. We didn't do any filtering regarding \033[?7h before, but CI passed. I assume, because in CI and for our build bots is_apple_terminal is false, but obviously on @smontanaro's setup it returns true.

Setting is_apple_terminal manually to true immediately raised the problem for me on WSL and native Ubuntu ...

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the culprit, @chris-eibl: the Apple Terminal special case. I'll make sure to test that, too, when landing stuff. We can also look into running the main test_pyrepl stuff twice, the second time with is_apple_terminal mocked to return True. That way we won't regress in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

As someone who uses a Mac daily, are there changes to my environment I can make to mimic the environment of the Mac buildbots? I'm happy to add that to my mix. I routinely run tests for main and the two most recent older branches (currently 3.13 & 3.14).

Copy link
Member Author

Choose a reason for hiding this comment

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

Most probably is_apple_terminal is false on CI, because os.getenv("TERM_PROGRAM") == "Apple_Terminal" does not evaluate to true there, but idk why :(

At least #143461 takes care to enforce Apple_Terminal, so your use case is now handled, too.

You can set TERM_PROGRAM to something different than Apple_Terminal to mimic what happened in CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can set TERM_PROGRAM to something different than Apple_Terminal to mimic what happened in CI.

Excellent, I can just run in an xterm. (Hadn't occurred to me before, but then I didn't realize there were these kinds of environment diffs.)

@ambv
Copy link
Contributor

ambv commented Jan 5, 2026

I reproduced the problem with Apple Terminal and can confirm this PR fixes it.

@ambv ambv merged commit 04ace41 into python:main Jan 5, 2026
44 checks passed
@ambv ambv added the needs backport to 3.14 bugs and security fixes label Jan 5, 2026
@miss-islington-app
Copy link

Thanks @chris-eibl for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 5, 2026
…newline (pythonGH-143433)

(cherry picked from commit 04ace41)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Jan 5, 2026

GH-143459 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jan 5, 2026
ambv pushed a commit that referenced this pull request Jan 5, 2026
…_newline (GH-143433) (GH-143459)

(cherry picked from commit 04ace41)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@chris-eibl chris-eibl added the needs backport to 3.13 bugs and security fixes label Jan 6, 2026
@miss-islington-app
Copy link

Thanks @chris-eibl for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 6, 2026
…newline (pythonGH-143433)

(cherry picked from commit 04ace41)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Jan 6, 2026

GH-143478 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jan 6, 2026
ambv added a commit that referenced this pull request Jan 6, 2026
…_newline (GH-143433) (GH-143478)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@chris-eibl chris-eibl deleted the fix-test_no_newline branch January 7, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants