Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/semantic_index/member.rs (Rust)

Code before:
                        },
                        // Handle positive integer subscripts with explicit plus, like `x[+1]`.
                        ast::Expr::UnaryOp(ast::ExprUnaryOp {
                            op: ast::UnaryOp::UAdd,
                            operand,
                            ..
                        }) => match operand.as_ref() {
                            ast::Expr::NumberLiteral(ast::ExprNumberLiteral {
                                value: ast::Number::Int(index),
                                ..
                            }) => {
                                let _ = write!(path, "{index}");
                                segments.push(SegmentInfo::new(
                                    SegmentKind::IntSubscript,
                                    start_offset,
                                ));
                            }
                            _ => return None,
                        },
                        // Handle boolean subscripts, like `x[True]` or `x[False]`.
                        // In Python, `True` and `False` are equivalent to `1` and `0` for indexing.
                        ast::Expr::BooleanLiteral(ast::ExprBooleanLiteral { value, .. }) => {
                            let _ = write!(path, "{}", if *value { "True" } else { "False" });
                            segments
                                .push(SegmentInfo::new(SegmentKind::IntSubscript, start_offset));
                        }
                        ast::Expr::StringLiteral(string) => {
                            let _ = write!(path, "{}", string.value);
                            segments
                                .push(SegmentInfo::new(SegmentKind::StringSubscript, start_offset));
                        }
                        // Handle bytes literal subscripts, like `x[b"key"]`.
                        ast::Expr::BytesLiteral(bytes) => {
                            let bytes_vec: Vec<u8> = bytes.value.bytes().collect();
                            let _ = write!(path, "{}", String::from_utf8_lossy(&bytes_vec));
                            segments
                                .push(SegmentInfo::new(SegmentKind::StringSubscript, start_offset));
                        }
                        _ => {
                            return None;
                        }
                    }

                    Some((path, segments))
                }
                _ => None,
            }
        }

        let (path, segments) = visit(expression)?;


Review comment (suggestion):
as you say, `True.__index__()` returns the same thing as `(1).__index__()` and `hash(True)` returns the same thing as `hash(1)`. So maybe we should just treat this exactly the same way as an `int` subscript?

```suggestion
                        ast::Expr::BooleanLiteral(ast::ExprBooleanLiteral { value, .. }) => {
                            let _ = write!(path, "{}", u8::from(*value) });
                            segments
                                .push(SegmentInfo::new(SegmentKind::IntSubscript, start_offset));
                        }
```

with this patch applied, both the `reveal_type` calls here reveal `str` (on your branch currently, only the first one does):

```py
def f(x: tuple[object, object]):
    if isinstance(x[True], str):
        reveal_type(x[True])
        reveal_type(x[1])
```

Code after:
                        },
                        // Handle positive integer subscripts with explicit plus, like `x[+1]`.
                        ast::Expr::UnaryOp(ast::ExprUnaryOp {
                            op: ast::UnaryOp::UAdd,
                            operand,
                            ..
                        }) => match operand.as_ref() {
                            ast::Expr::NumberLiteral(ast::ExprNumberLiteral {
                                value: ast::Number::Int(index),
                                ..
                            }) => {
                                let _ = write!(path, "{index}");
                                segments.push(SegmentInfo::new(
                                    SegmentKind::IntSubscript,
                                    start_offset,
                                ));
                            }
                            _ => return None,
                        },
                        // Handle boolean subscripts, like `x[True]` or `x[False]`.
                        // In Python, `True` and `False` are equivalent to `1` and `0` for indexing.
                        ast::Expr::BooleanLiteral(ast::ExprBooleanLiteral { value, .. }) => {
                            let _ = write!(path, "{}", u8::from(*value));
                            segments
                                .push(SegmentInfo::new(SegmentKind::IntSubscript, start_offset));
                        }
                        ast::Expr::StringLiteral(string) => {
                            let _ = write!(path, "{}", string.value);
                            segments
                                .push(SegmentInfo::new(SegmentKind::StringSubscript, start_offset));
                        }
                        // Handle bytes literal subscripts, like `x[b"key"]`.
                        ast::Expr::BytesLiteral(bytes) => {
                            let bytes_vec: Vec<u8> = bytes.value.bytes().collect();
                            let _ = write!(path, "{}", String::from_utf8_lossy(&bytes_vec));
                            segments
                                .push(SegmentInfo::new(SegmentKind::BytesSubscript, start_offset));
                        }
                        _ => {
                            return None;
                        }
                    }

                    Some((path, segments))
                }
                _ => None,
            }
        }

        let (path, segments) = visit(expression)?;