Thrift
  1. Thrift
  2. THRIFT-162

Thrift structures are unhashable, preventing them from being used as set elements

    Details

    • Patch Info:
      Patch Available

      Description

      Let Foo be a Thrift structure:

      struct Foo

      { 1: i32 bar }

      If you want to use it properly as a set element or a as a dictionary key, the autoegenerated Python code will complain about not being hashable:

      >>> f1 = Foo()
      >>> f1.bar = 1
      >>> f2 = Foo()
      >>> f2.bar = 1
      >>> f1 == f2
      True
      >>> set([f1]) & set([f2])
      set([])
      >>> d = {}
      >>> d[f1] = 2
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: unhashable instance

      Since Thrift structures already implement _eq_ and _ne, they should implement __hash_ as well. The attached patch tries to mimic the behaviour of the Java compiler, including a HashCodeBuilder class written in Python.

      1. thrift_py_hash.patch
        4 kB
        Esteve Fernandez
      2. thrift-162_annotiations.patch
        2 kB
        Esteve Fernandez
      3. thrift-162_v2_annotiations.patch
        5 kB
        Esteve Fernandez
      4. immut-no-slots-v1.diff
        2 kB
        David Reiss
      5. immut-v2.diff
        7 kB
        David Reiss
      6. immut-v3.diff
        9 kB
        David Reiss
      7. immut-v4.diff
        7 kB
        David Reiss
      8. reading-containers.diff
        3 kB
        David Reiss

        Issue Links

          Activity

          Jake Farrell made changes -
          Labels temp
          Fix Version/s 1.0 [ 12318851 ]
          Fix Version/s 1.2 [ 12323379 ]
          Jake Farrell made changes -
          Fix Version/s 1.2 [ 12323379 ]
          Jake Farrell made changes -
          Labels temp
          Gavin made changes -
          Link This issue depends upon THRIFT-301 [ THRIFT-301 ]
          Gavin made changes -
          Link This issue depends on THRIFT-301 [ THRIFT-301 ]
          Bryan Duxbury made changes -
          Fix Version/s 0.4 [ 12314960 ]
          Bryan Duxbury made changes -
          Fix Version/s 0.4 [ 12314960 ]
          Fix Version/s 0.3 [ 12314451 ]
          Todd Lipcon made changes -
          Fix Version/s 0.3 [ 12314451 ]
          Fix Version/s 0.2 [ 12313769 ]
          Kevin Clark made changes -
          Fix Version/s 0.2 [ 12313769 ]
          David Reiss made changes -
          Attachment reading-containers.diff [ 12404410 ]
          David Reiss made changes -
          Attachment immut-v4.diff [ 12403730 ]
          David Reiss made changes -
          Attachment immut-v3.diff [ 12403643 ]
          David Reiss made changes -
          Attachment immut-v2.diff [ 12403568 ]
          David Reiss made changes -
          Attachment immut-no-slots-v1.diff [ 12403561 ]
          Esteve Fernandez made changes -
          Attachment thrift-162_v2_annotiations.patch [ 12399365 ]
          Esteve Fernandez made changes -
          Link This issue depends on THRIFT-301 [ THRIFT-301 ]
          Esteve Fernandez made changes -
          Attachment thrift-162_annotiations.patch [ 12399243 ]
          Esteve Fernandez made changes -
          Status Closed [ 6 ] Reopened [ 4 ]
          Resolution Invalid [ 6 ]
          David Reiss made changes -
          Resolution Invalid [ 6 ]
          Status Open [ 1 ] Closed [ 6 ]
          Esteve Fernandez made changes -
          Field Original Value New Value
          Attachment thrift_py_hash.patch [ 12391751 ]
          Esteve Fernandez created issue -

            People

            • Assignee:
              Unassigned
              Reporter:
              Esteve Fernandez
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Development