Skip to content

Difference in equality check between C and Python implementation for datetime module's timedelta and time #81760

Closed

Description

@tirkarthi
BPO 37579
Nosy @abalkin, @serhiy-storchaka, @pganssle, @miss-islington, @tirkarthi
PRs
  • bpo-37579: Return NotImplemented in Python implementation of __eq__ to match C implementation of datetime for timedelta and time #14726
  • [3.8] bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726) #14743
  • [3.7] bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726) #14745
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-07-14.10:04:38.808>
    created_at = <Date 2019-07-13.05:25:41.676>
    labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
    title = "Difference in equality check between C and Python implementation for datetime module's timedelta and time"
    updated_at = <Date 2019-07-25.21:16:37.867>
    user = 'https://github.com/tirkarthi'

    bugs.python.org fields:

    activity = <Date 2019-07-25.21:16:37.867>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-07-14.10:04:38.808>
    closer = 'p-ganssle'
    components = ['Library (Lib)']
    creation = <Date 2019-07-13.05:25:41.676>
    creator = 'xtreak'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37579
    keywords = ['patch']
    message_count = 6.0
    messages = ['347773', '347813', '347815', '347821', '347903', '348454']
    nosy_count = 5.0
    nosy_names = ['belopolsky', 'serhiy.storchaka', 'p-ganssle', 'miss-islington', 'xtreak']
    pr_nums = ['14726', '14743', '14745']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37579'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. tirkarthi commented on Jul 13, 2019

      @tirkarthi
      MemberAuthor

      As reported by Serhiy on https://bugs.python.org/issue37555#msg347733 there is a difference in __eq__ definition in datetime module's C and Python implementation for timedelta and time. When the other in __eq__ is not of the same type NotImplemented is not returned in Python implementation like C causing equality to behave differently.

      Difference in C implementation and Python implementation for datetime.timedelta.__eq__

      static PyObject *

      static PyObject *
      delta_richcompare(PyObject *self, PyObject *other, int op)
      {
          if (PyDelta_Check(other)) {
              int diff = delta_cmp(self, other);
              return diff_to_bool(diff, op);
          }
          else {
              Py_RETURN_NOTIMPLEMENTED;
          }
      }

      def __eq__(self, other):

      def __eq__(self, other):
          if isinstance(other, timedelta):
              return self._cmp(other) == 0
          else:
              return False

      I will add a PR for this with test.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 13, 2019
    3. serhiy-storchaka commented on Jul 13, 2019

      @serhiy-storchaka
      Member

      Do you mind to fix also other similar cases if they are? __lt__ and others should have the same property.

    4. pganssle commented on Jul 13, 2019

      @pganssle
      Member

      New changeset e6b46aa by Paul Ganssle (Xtreak) in branch 'master':
      bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726)
      e6b46aa

    5. miss-islington commented on Jul 13, 2019

      @miss-islington
      Contributor

      New changeset 143672c by Miss Islington (bot) in branch '3.8':
      bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726)
      143672c

    6. miss-islington commented on Jul 14, 2019

      @miss-islington
      Contributor

      New changeset c6b3106 by Miss Islington (bot) (Xtreak) in branch '3.7':
      [3.7] bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726) (GH-14745)
      c6b3106

    7. serhiy-storchaka commented on Jul 25, 2019

      @serhiy-storchaka
      Member
    8. transferred this issue fromon Apr 10, 2022
    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.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions