Skip to content

Unexpected behaviour in test (if) on list when list index out of range #130426

@sbersier

Description

@sbersier

Bug report

Bug description:

Have a look at the minimal example below. Running this example, I would expect the following error: "IndexError: list index out of range" but it carries on, as if L[30] was a boolean ("False" or "True"). Is it the expected behaviour?
I'm using python 3.10.12

L=[0,1,2,3]
if True or L[30]: 
    print("That's OK despite the fact that I used an out of range index value of 30 for my test.")

But, if I use and "AND" instead of the "OR":

L=[0,1,2,3]
if True and L[30]:
    print("That's OK despite the fact that I used an out of range index value of 30 for my test.")

Then it throws the expected error: "IndexError: list index out of range"

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions