Skip to content

Give AST nodes a useful __eq__ #118855

Closed as not planned
Closed as not planned

Description

@JelleZijlstra

Feature or enhancement

Proposal:

>>> import ast
>>> ast.Load() == ast.Load()
False

It's useful for unit tests if equal nodes actually compare equal.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Activity

  1. added
    type-feature
    3.14
    on May 9, 2024
  2. Eclips4 commented on May 9, 2024

    @Eclips4
    Member

    I would like to take this one if you don't mind :)

  3. JelleZijlstra commented on May 9, 2024

    @JelleZijlstra
    MemberAuthor

    Go for it!

  4. serhiy-storchaka commented on May 10, 2024

    @serhiy-storchaka
    Member

    Should it be recursive or not? See also #60191.

    For things like ast.Load() it makes sense to make them singletons. This would automatically solve the problem with equal comparison.

  5. sobolevn commented on May 10, 2024

    @sobolevn
    Member

    Also, there are two ways to compare nodes. "exactly equal" including position and every other detail and "looks equal" when their content is similar: ast.Name(id="a") might look equal to other ast.Name(id="a")

    Both are useful for static analysis tools.

  6. JelleZijlstra commented on May 10, 2024

    @JelleZijlstra
    MemberAuthor

    Thanks Serhyi, let's close this as a duplicate of #60191.

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

    3.14type-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions