Uploaded image for project: 'Nuxeo Python Client'
  1. Nuxeo Python Client
  2. NXPY-143

Remove duplicate constructors code in models.py

    XMLWordPrintable

    Details

    • Type: Clean up
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.0
    • Fix Version/s: 2.4.0
    • Component/s: Core

      Description

      All models in models.py have the same code:

      def __init__(self, **kwargs):
          # type: (Any) -> None
          super(Directory, self).__init__(**kwargs)
          for key, default in Directory._valid_properties.items():
              key = key.replace("-", "_")
              setattr(self, key, kwargs.get(key, default))
      

      Here, this is the constructor of the Directory class.

      That code can be moved to the parent class, Model, using the type(self) "trick":

      for key, default in type(self)_valid_properties.items():
          key = key.replace("-", "_")
          setattr(self, key, kwargs.get(key, default))
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h