Skip to content

gh-151471: colorizer the type when it start a statement - #151700

Merged
serhiy-storchaka merged 7 commits into
python:mainfrom
Locked-chess-official:patch-1
Sep 23, 2026
Merged

serhiy-storchaka merged 7 commits into
python:mainfrom
Locked-chess-official:patch-1

Conversation

@Locked-chess-official

@Locked-chess-official Locked-chess-official commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

The news will be added.
I put type_softkw before builtin because of the afraid that builtin may cover the type_softkw in re.
Now there is no test. It will also be added after it passed on py PC.

The `news` will be added soon.
I put `type_softkw` before `builtin` because of the afraid that `builtin` may cover the `type_softkw` in re.
Now there is no test.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The pattern works for the cases I tried, including type = type(1) and type(x) staying builtins. Two things before merging:

  1. The lookahead [A-Za-z_] rejects non-ASCII names, so type Точка = int is not colored. Use [^\W\d] (an identifier start) instead.
  2. Please add a NEWS entry under Misc/NEWS.d/next/IDLE/ (blurb or blurb-it), and a test: add type Point = tuple[float, float] and type = type(1) to source in test_colorizer.py and the expected tags for those lines to test_recolorize_main — note the line numbers are those of the dedented source string, so currently 32 and 33.

@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Sep 17, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Works for me, including non-ASCII names, indented statements, and type = type(1) / type(x) staying builtins. One optional refinement and a NEWS wording suggestion inline. After merging I will close #155958 as a duplicate.

Comment thread Lib/idlelib/colorizer.py Outdated
Comment thread Misc/NEWS.d/next/IDLE/2026-09-17-08-53-12.gh-issue-151471.-yvE03.rst Outdated
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…03.rst

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@python python deleted a comment from bedevere-app Bot Sep 22, 2026
@terryjreedy terryjreedy added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 22, 2026
@terryjreedy

Copy link
Copy Markdown
Member

Serhiy, your last two change requests have been made. Do you want to merge (and close alt PR) or shall I? I added backports.

@serhiy-storchaka
serhiy-storchaka merged commit 68ed7a5 into python:main Sep 23, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @Locked-chess-official for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Sorry, @Locked-chess-official and @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 68ed7a50226f8981788f2673677e30f1431e18a9 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @Locked-chess-official and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 68ed7a50226f8981788f2673677e30f1431e18a9 3.13

@bedevere-app

bedevere-app Bot commented Sep 23, 2026

Copy link
Copy Markdown

GH-157991 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 23, 2026
@bedevere-app

bedevere-app Bot commented Sep 23, 2026

Copy link
Copy Markdown

GH-157992 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 Sep 23, 2026
@bedevere-app

bedevere-app Bot commented Sep 23, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Sep 23, 2026
serhiy-storchaka added a commit that referenced this pull request Sep 23, 2026
GH-157993)

`type` is now colored as a keyword when it starts a statement and is
followed by a name, as in `type Point = tuple[float, float]`.  It stays
a builtin elsewhere, for example in `type = type(1)`, `type(x)` or
`type in (int, str)`.

(cherry picked from commit 68ed7a5)

Co-authored-by: Locked-chess-official <13140752715@163.com>
serhiy-storchaka added a commit that referenced this pull request Sep 23, 2026
GH-157992)

`type` is now colored as a keyword when it starts a statement and is
followed by a name, as in `type Point = tuple[float, float]`.  It stays
a builtin elsewhere, for example in `type = type(1)`, `type(x)` or
`type in (int, str)`.

(cherry picked from commit 68ed7a5)

Co-authored-by: Locked-chess-official <13140752715@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants