Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-697

Migrate to timedelta/datetime from FiniteDuration/Seconds etc

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-beta.2
    • None
    • None
    • 1

    Description

      I am not exactly sure what feels right here, but having our own Seconds doesn't seem too idiomatic.  Perhaps 

      date = timedelta(seconds=3)
      #or
      date = timedelta(milliseconds=100)

       and using that date seems more idiomatic?

      The date can always be converted:

      date.total_seconds() # a float so feel free to / 1000 or /1000000 for milli or microseconds

      Probably there are other possibilities too, thoughts?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Ellis.Breen Ellis Breen added a comment -

          I agree timedelta is more idiomatic. I did consider it before, but was trying to match the Java/.NET examples. Given further cues on the level of idiomaticness desired, I think timedelta is the way to go. The constructor takes named parameters with different time units so we get more expressiveness e.g. timedelta(days=1,hours=12) vs Minutes(36*60*24) etc.

          Ellis.Breen Ellis Breen added a comment - I agree timedelta is more idiomatic. I did consider it before, but was trying to match the Java/.NET examples. Given further cues on the level of idiomaticness desired, I think timedelta is the way to go. The constructor takes named parameters with different time units so we get more expressiveness e.g. timedelta(days=1,hours=12) vs Minutes(36*60*24) etc.
          david.kelly David Kelly added a comment -

          FWIW, on the java side, there is a class hierarchy for the options. At the base is a CommonOptions with timeout in there, then there's a CommonDurabilityOptions (for options that are used in mutating functions) which has CommonOptions as a base, and the specific options on top of these (roughly). Perhaps we can do the same?

          david.kelly David Kelly added a comment - FWIW, on the java side, there is a class hierarchy for the options. At the base is a CommonOptions with timeout in there, then there's a CommonDurabilityOptions (for options that are used in mutating functions) which has CommonOptions as a base, and the specific options on top of these (roughly). Perhaps we can do the same?
          Ellis.Breen Ellis Breen added a comment -

          Indeed, we have OptionBlock and OptionBlockTimeout in couchbase/options.py, as well as ClientDurableOption and ServerDurableOption in couchbase/durability.py - the latter are mixins which you can see in use in couchbase/collections.py: https://github.com/couchbase/couchbase-python-client/blob/3787943d90fd76cfecf7c6d3be3d8cbacf06b41d/couchbase/collection.py#L49 (see ReplaceOptions, RemoveOptions, and so on). I have a plan to define the arguments to both a function and an OptionBlock in one place, but will come back to that on Monday if I have time. In practice, most of the options in the RFC itself are pretty empty (the odd timeout/durability option and that's all), but there are plenty of SDK2 options that we probably want to expose too, and it would be a shame to have to specify these twice per function.

          Ellis.Breen Ellis Breen added a comment - Indeed, we have OptionBlock and OptionBlockTimeout in couchbase/options.py, as well as ClientDurableOption and ServerDurableOption in couchbase/durability.py - the latter are mixins which you can see in use in couchbase/collections.py: https://github.com/couchbase/couchbase-python-client/blob/3787943d90fd76cfecf7c6d3be3d8cbacf06b41d/couchbase/collection.py#L49  (see ReplaceOptions, RemoveOptions, and so on). I have a plan to define the arguments to both a function and an OptionBlock in one place, but will come back to that on Monday if I have time. In practice, most of the options in the RFC itself are pretty empty (the odd timeout/durability option and that's all), but there are plenty of SDK2 options that we probably want to expose too, and it would be a shame to have to specify these twice per function.

          People

            Ellis.Breen Ellis Breen
            david.kelly David Kelly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty