[dataimport] methods that modify in-place shouldn't return value

Also mark those methods private and drop some useless comments in passing.

Related to #5414760

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changesetb7f4acf0473b
branchdefault
phasepublic
hiddenno
parent revision#8e1f6de61300 [dataimport] implement new store API on massive store
child revision#2537df9fdd27 [dataimport] drop no more used parameter on massive store
files modified by this revision
dataimport/massive_store.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1445438092 -7200
# Wed Oct 21 16:34:52 2015 +0200
# Node ID b7f4acf0473b45efc57de7f6eb8157f3b7dea4c6
# Parent 8e1f6de61300b5032a7b615cd8274bb96d2ca173
[dataimport] methods that modify in-place shouldn't return value

Also mark those methods private and drop some useless comments in passing.

Related to #5414760

diff --git a/dataimport/massive_store.py b/dataimport/massive_store.py
@@ -417,28 +417,24 @@
1          while True:
2              last_eid = self._cnx.repo.system_source.create_eid(self._cnx, self._eids_seq_range)
3              for eid in range(last_eid - self._eids_seq_range + 1, last_eid + 1):
4                  yield eid
5 
6 -    def apply_size_constraints(self, etype, kwargs):
7 -        """ Apply the size constraints for a given etype, attribute and value
8 -        """
9 +    def _apply_size_constraints(self, etype, kwargs):
10 +        """Apply the size constraints for a given etype, attribute and value."""
11          size_constraints = self.size_constraints[etype]
12          for attr, value in kwargs.items():
13              if value:
14                  maxsize = size_constraints.get(attr)
15                  if maxsize is not None and len(value) > maxsize:
16                      kwargs[attr] = value[:maxsize-4] + '...'
17 -        return kwargs
18 
19 -    def apply_default_values(self, etype, kwargs):
20 -        """ Apply the default values for a given etype, attribute and value
21 -        """
22 +    def _apply_default_values(self, etype, kwargs):
23 +        """Apply the default values for a given etype, attribute and value."""
24          default_values = self.default_values[etype]
25          missing_keys = set(default_values) - set(kwargs)
26          kwargs.update((key, default_values[key]) for key in missing_keys)
27 -        return kwargs
28 
29      # store api ################################################################
30 
31      def prepare_insert_entity(self, etype, **kwargs):
32          """Given an entity type, attributes and inlined relations, returns the inserted entity's
@@ -459,17 +455,13 @@
33                  self._count_cwuri += 1
34          if 'eid' not in kwargs and self._eids_seq_range is not None:
35              # If eid is not given and the eids sequence is set,
36              # use the value from the sequence
37              kwargs['eid'] = self.get_next_eid()
38 -        # Check size constraints
39 -        kwargs = self.apply_size_constraints(etype, kwargs)
40 -        # Apply default values
41 -        kwargs = self.apply_default_values(etype, kwargs)
42 -        # Push data
43 +        self._apply_size_constraints(etype, kwargs)
44 +        self._apply_default_values(etype, kwargs)
45          self._data_entities[etype].append(kwargs)
46 -        # Return eid
47          return kwargs.get('eid')
48 
49      def prepare_insert_relation(self, eid_from, rtype, eid_to, **kwargs):
50          """Insert into the database a  relation ``rtype`` between entities with eids ``eid_from``
51          and ``eid_to``.