[PATCH 06 of 15 yams V3] [refactoring] de-kwargs AbstractTypedAttribute.__init__

Laurent Peuch cortex at worlddomination.be
Wed Jan 15 20:59:06 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 1ba418b4b80a620e27dda5d05bd2ac2ef66a2efa
# Parent  f6c4e858f937ffa193d8161e2f559d52f3baf9f8
# Available At https://hg.logilab.org/users/lpeuch/yams
#              hg pull https://hg.logilab.org/users/lpeuch/yams -r 1ba418b4b80a
[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