Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Consider specialized syntax error for && and || #146495

Description

@brianschubert

Feature or enhancement

Proposal:

Coming from other languages, it’s easy to accidentally write && or || in place of and or or. I've even seen experienced people reach for them when doing boolean operations on Numpy arrays and the like.

It could be helpful to add a specialized syntax error. Something like:

  File "<python-input-1>", line 1
    a && b
      ^^
SyntaxError: invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?

This might be a little tricky, since && and || are not their own tokens, so I don't think this can be done at the grammar level.

cc @pablogsal @lysnikolaou

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions