Skip to content

Equal objects (e. g. User) are not recognized as equal #587

@j-maas

Description

@j-maas

Steps to reproduce

  1. Create two equal objects. E. g.:
user1 = User(id=1, first_name="Equal", last_name="Identical", username="same", type=None, bot=None)
user2 = User(id=1, first_name="Equal", last_name="Identical", username="same", type=None, bot=None)
  1. Compare the objects: assert user1 == user2

Expected behaviour

The assertion should pass: The equality comparison should return True.

Actual behaviour

The assertion fails:

>       assert user1 == user2
E       assert <telegram.use...at 0x041006F0> == <telegram.user...at 0x041006D0>

Configuration

Operating System:
Windows 10

Version of Python, python-telegram-bot & dependencies:
Python 3.6.1
python-telegram-bot commit 4541476

Possible fix

Implementing the rich comparison method __eq__ for the class. Implementing __hash__ alongside might be a good idea.

Notes

This probably not only holds for the User object, but for all Telegram objects.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy