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 — Boolean expression performs redundant bool check · Issue #3567 · RustPython/RustPython

Boolean expression performs redundant bool check #3567

New issue
Copy link
New issue
Copy link
Closed
#7176
Closed
Boolean expression performs redundant bool check#3567
#7176
Copy link

Description

@dimpolo
dimpolo
opened on Mar 11, 2022
Issue body actions
n = 0

class Test:
    def __bool__(self):
        global n
        n += 1
        return False

Test() and False or False
assert n == 1

CPython optimizes this check in:
https://github.com/python/cpython/blob/54ab9ad312ea53db40e31712454272e1d4c0315f/Python/compile.c#L8708-L8721

Reacted by Jeong, YunWon and Snowapril

Activity

  1. crazymerlyn commented on Sep 7, 2024

    @crazymerlyn
    crazymerlyn
    on Sep 7, 2024
    Contributor
    More actions

    Looks like the assertion fails again since python 3.12: https://godbolt.org/z/qoKcdvz4T

  2. moreal commented on Feb 14, 2026

    @moreal
    moreal
    on Feb 14, 2026
    Contributor
    More actions

    In CPython 3.14, the assertion has started to pass again.

    https://godbolt.org/z/1Genzf9sE

    Image
  3. moreal
    added 2 commits that reference this issue on Feb 15, 2026

    Add runtime test for redundant __bool__ check (issue RustPython#3567)

    42e08bd

    Add runtime test for redundant __bool__ check (issue RustPython#3567)

    d8ccc98
  4. youknowone
    closed this as completedin #7176on Feb 17, 2026
  5. youknowone
    added a commit that references this issue on Feb 17, 2026

    Optimize redundant bool check (#7176)

    d07d522
  6. youknowone
    added a commit that references this issue on Mar 22, 2026

    Optimize redundant bool check (RustPython#7176)

    18f5812
  7. youknowone
    added a commit that references this issue on Sep 16, 2026

    Optimize redundant bool check (#7176)

    4b292f4
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.