[PATCH 4 of 9 yams V2] [refactoring] de-kwargs AbstractTypedAttribute.__init__

Laurent Peuch cortex at worlddomination.be
Wed Jan 15 10:58:27 CET 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1578617294 -3600
#      Fri Jan 10 01:48:14 2020 +0100
# Node ID 38154edd94724b86b7bc2247b87ba8b78015a7f0
# Parent  502f48005ecb7e2e8f873e689f9d6862862db38a
# Available At https://hg.logilab.org/users/lpeuch/yams
#              hg pull https://hg.logilab.org/users/lpeuch/yams -r 38154edd9472
[refactoring] de-kwargs AbstractTypedAttribute.__init__

This is to be able to introduce typing and for a better documentation because
kwargs is totally implicit and hard to guess.

diff --git a/yams/buildobjs.py b/yams/buildobjs.py
--- a/yams/buildobjs.py
+++ b/yams/buildobjs.py
@@ -232,33 +232,37 @@ class AbstractTypedAttribute(SubjectRela
     subclasses must provide a <etype> attribute to be instantiable
     """
 
-    def __init__(self, metadata=None, **kwargs):
+    def __init__(self, metadata=None, required=False, maxsize=None, formula=MARKER,
+                 vocabulary=None, unique=None, override=False, **kwargs):
         # Store metadata
         if metadata is None:
             metadata = {}
         self.metadata = metadata
+
         # transform "required" into "cardinality"
-        required = kwargs.pop('required', False)
         if required:
             cardinality = '11'
         else:
             cardinality = '?1'
         kwargs['cardinality'] = cardinality
+
         # transform maxsize into SizeConstraint
-        maxsize = kwargs.pop('maxsize', None)
         if maxsize is not None:
             _add_constraint(kwargs, SizeConstraint(max=maxsize))
+
         # formula
-        self.formula = kwargs.pop('formula', MARKER)
+        self.formula = formula
+
         # transform vocabulary into StaticVocabularyConstraint
-        vocabulary = kwargs.pop('vocabulary', None)
         if vocabulary is not None:
             self.set_vocabulary(vocabulary, kwargs)
+
         # transform unique into UniqueConstraint
-        unique = kwargs.pop('unique', None)
         if unique:
             _add_constraint(kwargs, UniqueConstraint())
+
         # use the etype attribute provided by subclasses
+        kwargs["override"] = override
         super(AbstractTypedAttribute, self).__init__(self.etype, **kwargs)
         # reassign creation rank
         #



More information about the cubicweb-devel mailing list