GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-151128: Improve SyntaxError message for cross language keywords by zang-langyan · Pull Request #151129 · python/cpython

Conversation

@zang-langyan

@zang-langyan zang-langyan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
image

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

edvilme and Oxicid reacted with heart emoji
All reactions
  • ❤️ 2 reactions
zang-langyan added 2 commits June 9, 2026 15:58
@zang-langyan
pythongh-151128 Improve SyntaxError message for match
ba55af2
@zang-langyan
suggestion does not compute full match distance
bb0200a
@bedevere-app bedevere-app Bot added the awaiting review label Jun 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jun 9, 2026
Improve SyntaxError message for match #151128
Closed
@serhiy-storchaka

serhiy-storchaka commented Jun 9, 2026

Copy link
Copy Markdown
Member

I do not think that it is needed to add 'switch' to keywords.

Even if we only add one special case, it is worth to write more general code which will allow to add more keywords in future. See #146407 as example.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

IvyXu420

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zang-langyan

zang-langyan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

I do not think that it is needed to add 'switch' to keywords.

Even if we only add one special case, it is worth to write more general code which will allow to add more keywords in future. See #146407 as example.

Thank you for the reference, it is really a good example. I will look into it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zang-langyan
add cross language keyword hints list as a general implementation
3a2926f
@zang-langyan
zang-langyan requested review from lysnikolaou and pablogsal as code owners June 9, 2026 12:59
@zang-langyan zang-langyan changed the title gh-151128: Improve SyntaxError message for match gh-151128: Improve SyntaxError message for cross language keywords Jun 9, 2026
@zang-langyan
trim trailing whitespace
27b89b6
edvilme
edvilme reviewed Jun 10, 2026
View reviewed changes
Comment thread Lib/traceback.py Outdated
Comment on lines +1890 to +1891
hint = _CROSS_LANGUAGE_KEYWORD_HINTS.get(wrong_name)
return hint

This comment was marked as resolved.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jun 10, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You can split this on two features -- for keywords and for operators.

Anyway, it needs a NEWS entry, a What's New entry, and tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Grammar/python.gram Outdated
| a=expression ':=' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
| a=expression '&''&' b=expression {

@serhiy-storchaka serhiy-storchaka Jun 10, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nice. This is actually a different feature. You can even open a separate issue and PR for this (if there is no already open). Anyway, this is a nice improvement.

I suggest to add also cases for <> ("not equal" in Pascal and Python 2), "=<", "=>" and "=!" (typo in "<=", ">=" and "!="), "===" ("is" in JavaScript and PHP).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@IvyXu420 IvyXu420 Jun 11, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually there is already a PR for improving SyntaxError message of && and ||: #150906

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zang-langyan zang-langyan Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you for review, great suggestion, I will add those~

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Jun 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Then let's focus on keywords in this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
IvyXu420
IvyXu420 reviewed Jun 11, 2026
View reviewed changes
Comment thread Lib/traceback.py Outdated
suggestion = _suggestions._generate_suggestions(keyword.kwlist + keyword.softkwlist, wrong_name)
if suggestion:
matches.append(suggestion)
matches.extend(difflib.get_close_matches(wrong_name, keyword.kwlist, n=max_matches, cutoff=0.5))

@IvyXu420 IvyXu420 Jun 11, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
matches.extend(difflib.get_close_matches(wrong_name, keyword.kwlist, n=max_matches, cutoff=0.5))
matches.extend(difflib.get_close_matches(wrong_name, keyword.kwlist+keyword.softkwlist, n=max_matches, cutoff=0.5))

Maybe we should add softkwlist here too?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zang-langyan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@serhiy-storchaka serhiy-storchaka mentioned this pull request Jun 11, 2026
gh-146495: Improve SyntaxError message for && and || operators #150906
Merged
@Aniketsy Aniketsy mentioned this pull request Jun 11, 2026
Improve SyntaxError suggestions for common operator typos and cross-language mistakes #151303
Open
@zang-langyan
focus on keyword suggestion
f3cdecc
@zang-langyan
zang-langyan requested a review from serhiy-storchaka June 11, 2026 16:23
@zang-langyan
remove trailing whitespace
2cdd76e
serhiy-storchaka
serhiy-storchaka reviewed Jun 11, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Could you please add also tests for soft keywords? And document this change in the NEWS entry.

Why aliases for None were removed? Were there issues with them?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zang-langyan

zang-langyan commented Jun 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Could you please add also tests for soft keywords? And document this change in the NEWS entry.

Why aliases for None were removed? Were there issues with them?

Sure, I will add the tests for soft keywords.

I removed the aliases for None because I realized that names like Null, nil, etc. don't work well for keyword syntax detection. I can't think of a situation where these tokens would be correctly identified as keywords. Any suggestions?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zang-langyan
add test for soft keywords
bca2327
@serhiy-storchaka

serhiy-storchaka commented Jun 11, 2026

Copy link
Copy Markdown
Member

You are right. Maybe they can be handled where NameError is handed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jun 11, 2026
View reviewed changes
Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

edvilme
edvilme reviewed Jun 11, 2026
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

edvilme
edvilme reviewed Jun 11, 2026
View reviewed changes
Comment thread Lib/traceback.py
max_matches = 3
matches = []

hint = _get_cross_language_keyword_hint(wrong_name)

@edvilme edvilme Jun 11, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
hint = _get_cross_language_keyword_hint(wrong_name)
hint = _CROSS_LANGUAGE_KEYWORD_HINTS.get(wrong_name)

If it is only used once, and is marked as a "private" method, I would suggest calling the body directly

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zang-langyan zang-langyan Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not sure about this. I still think a get method looks nicer..

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
zang-langyan added 2 commits June 12, 2026 11:36
@zang-langyan
add tests for keyword lazy and add void as another crosslang case
9e13d74
@zang-langyan
remove whitespace
896dd06
@zang-langyan
zang-langyan requested a review from serhiy-storchaka June 15, 2026 17:33
serhiy-storchaka
serhiy-storchaka approved these changes Jun 15, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zang-langyan reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jun 15, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 5ea1e90 into python:main Jun 15, 2026
55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 15, 2026
philthompson10 pushed a commit to philthompson10/cpython that referenced this pull request Jun 17, 2026
@zang-langyan @philthompson10
pythongh-151128: Improve SyntaxError message for cross language keywo…
82394ff
…rds (pythonGH-151129)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@pablogsal pablogsal Awaiting requested review from pablogsal
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou
+2 more reviewers
@edvilme edvilme edvilme left review comments
@IvyXu420 IvyXu420 IvyXu420 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@zang-langyan @serhiy-storchaka @edvilme @IvyXu420
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.