Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-7365

PyROOT: Objects missing __hash__ implementation for use in Python 3

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: 6.04.00
    • Fix Version/s: None
    • Component/s: PyROOT
    • Labels:
      None
    • Environment:

      GNU/Linux x86_64

      Description

      ROOT objects are not hashable in Python 3 because the required __hash__ is missing. Namely:

      If a class that overrides __eq__() needs to retain the implementation of __hash__() from a parent class, the interpreter must be told this explicitly by setting __hash__ = <ParentClass>.__hash__.

      https://docs.python.org/3.4/reference/datamodel.html#object.__hash__

      Python 2.X:

      >>> from ROOT import TH1D
      >>> a = TH1D("asd", "asd", 10, 0, 1)
      >>> a.__hash__()
      8790705923292
      >>> object.__hash__(a)
      8790705923292
      >>> {a:1}
      {<ROOT.TH1D object ("asd") at 0x474d860>: 1}

      Python 3.X:

      >>> from ROOT import TH1D
      >>> a = TH1D("asd", "asd", 10, 0, 1)
      >>> a.__hash__()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: 'NoneType' object is not callable
      >>> object.__hash__(a)
      -9223363257750828679
      >>> {a:1}
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: unhashable type: 'TH1D'

      Can __hash__ be explicitly defined on ROOT objects in PyROOT so they remain hashable in Python 3?

        Attachments

          Activity

            People

            Assignee:
            wlav Wim Lavrijsen
            Reporter:
            end Noel Dawe (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: