Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-242

Python struct constructors are clunky and error-prone

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Python - Compiler
    • None
    • Patch Available

    Description

      The python constructors are clunky and unnecessarily difficult to use. Instead of

      Cls(value1, value2, ...)

      you must write

      Cls(

      {'arg1': value1, 'arg2': value2}

      )

      (or use the dict constructor instead of literal notation).

      Additionally, having the constructor silently do nothing if a non-dict is passed in (an object of the type being created would be another reasonable guess) or if an argument is mis-spelled causes users unnecessary trouble debugging.

      Since removing the d argument entirely would be backwards-incompatible, the attached patch keeps it, but puts real keyword parameters in for forwards-compatibility. Thus, old code will work with this patch, but new code can be written using keyword args that will still work when the d argument is removed in a release that allows backwards-incompatibility. (Removing the d argument is desireable because otherwise positional arguments can't be used.)

      Attachments

        1. thrift-242_v2_no_d_argument.patch
          5 kB
          Esteve Fernandez
        2. thrift-242_no_d_argument.patch
          4 kB
          Esteve Fernandez
        3. init.patch
          2 kB
          Jonathan Ellis

        Activity

          People

            esteve Esteve Fernandez
            jbellis Jonathan Ellis
            Votes:
            2 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: