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 — [mypyc] Add primitives for list and variable-length tuple equality by Jahongir-Qurbonov · Pull Request #22410 · python/mypy

Conversation

@Jahongir-Qurbonov

@Jahongir-Qurbonov Jahongir-Qurbonov commented Nov 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add primitives for == / != where both operands are list, or both are variable-length tuple (tuple[T, ...]).

Previously these used PyObject_RichCompare, followed by a truth test of the returned object. The new CPyList_Compare / CPyTuple_Compare take the operator (Py_EQ or Py_NE) and return a C int directly (like CPyBytes_Compare):

  • If both objects are exact list / tuple objects: identical objects are equal, otherwise items are compared with PyObject_RichCompareBool, like CPython does. Lists of different lengths are not equal without comparing items. Tuples compare items even if the lengths differ, since CPython's tuple comparison doesn't have a length shortcut (item comparisons can have side effects or raise exceptions).
  • CPyList_Compare holds a critical section on both lists (like CPython), and handles lists being mutated by an item __eq__.
  • Subclasses (which may override __eq__ or __ne__) use PyObject_RichCompare with the original operator, so != calls __ne__ instead of negating __eq__.

Fixed-length tuples (RTuple) are already compared item by item, so they are not affected.

Tests compare the results against the generic implementation (through Any), and cover items with custom __eq__ (including non-bool results and exceptions), identity of items (NaN), mutation during comparison, tuples of different lengths, and subclasses (including named tuples, and subclasses overriding only __eq__ or only __ne__).

Micro-benchmark (compiled code, 3.2M comparisons, best of 15, before -> after, Python 3.13):

Case list tuple
Empty 0.048s -> 0.038s 0.049s -> 0.038s
Length 3, equal 0.056s -> 0.047s 0.053s -> 0.043s
Length 3, equal, distinct item objects 0.102s -> 0.108s 0.088s -> 0.090s
Different lengths 0.049s -> 0.041s 0.053s -> 0.042s
First item differs 0.065s -> 0.062s 0.062s -> 0.058s
Length 20, equal 0.101s -> 0.078s 0.083s -> 0.067s

Part of mypyc/mypyc#644.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Jahongir-Qurbonov added 2 commits November 10, 2026 22:45
@Jahongir-Qurbonov
[mypyc] Add primitives for list and variable-length tuple equality
eef2bdf
Use specialized C functions for == and != when both operands are lists
or both are variable-length tuples, instead of PyObject_RichCompare
followed by a truth test of the result. Subclasses use the generic path.
@Jahongir-Qurbonov
Match CPython for tuple equality with different lengths and subclass !=
25d80a4
Tuple equality now compares items even if the lengths differ, like CPython,
since item comparisons can have side effects or raise exceptions.

Pass the comparison operator to the C functions, so that != on list and
tuple subclasses calls __ne__ instead of negating the result of __eq__.
@Jahongir-Qurbonov
Jahongir-Qurbonov force-pushed the mypyc-list-tuple-eq branch from 87ada72 to 25d80a4 Compare November 10, 2026 18:02
@Jahongir-Qurbonov Jahongir-Qurbonov mentioned this pull request Nov 10, 2026
More primitives mypyc/mypyc#644
Open
13 of 14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Jahongir-Qurbonov
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.