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 — Clarify SyntaxWarning with literal comparison · Issue #103492 · python/cpython

Clarify SyntaxWarning with literal comparison #103492

New issue
Copy link
New issue
Copy link
Closed
Closed
Clarify SyntaxWarning with literal comparison#103492
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@hauntsaninja
hauntsaninja
opened on Apr 13, 2023
Issue body actions

I had a coworker slightly confused about the following warning, since None is a literal and is not None is idiomatic:

>>> 'a' is not None
<stdin>:1: SyntaxWarning: "is not" with a literal. Did you mean "!="?
True

I think this would be better as:

>>> 'a' is not None
<stdin>:1: SyntaxWarning: "is not" with str literal. Did you mean "!="?
True

Linked PRs

  • gh-103492: Clarify SyntaxWarning with literal comparison #103493

Activity

  1. hauntsaninja
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Apr 13, 2023
  2. hauntsaninja
    added 2 commits that reference this issue on Apr 13, 2023

    pythongh-103492: Clarify SyntaxWarning with literal comparison

    5247c04

    Merge branch 'main' into pythongh-103492

    41c9ad9
  3. terryjreedy commented on Apr 13, 2023

    @terryjreedy
    terryjreedy
    on Apr 13, 2023
    Member
    More actions

    https://docs.python.org/3/reference/lexical_analysis.html#literals

    Literals are notations for constant values of some built-in types.
    In particular bytes, strings, and numbers are discussed in the following.
    https://docs.python.org/3/reference/expressions.html#literals is more specific.
    Python supports string and bytes literals and various numeric literals:
    Evaluation of a literal yields an object of the given type (string, bytes, integer, floating point number, complex number) with the given value.

    None is a constant, but not a 'literal' as defined in the sections above. This is only to say that the current message is not really ambiguous. Still, the added detail may help some.

    https://docs.python.org/3/reference/expressions.html#parenthesized-forms
    A tuple is a 'parenthesized form' that is either empty or has at least 1 comma. A constant tuple is not really a literal, but testing I see that one is already called a 'literal'.

    The test changes look good; can't review the c code.

  4. hauntsaninja
    added a commit that references this issue on Apr 24, 2023

    gh-103492: Clarify SyntaxWarning with literal comparison (#103493)

    ae25855
  5. carljm
    added 2 commits that reference this issue on Apr 24, 2023

    Merge branch 'main' into superopt

    dbe1665

    Merge branch 'superopt' into superopt_spec

    793a69a
  6. hauntsaninja
    closed this as completedon Apr 26, 2023
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

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — 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.