[PATCH 15 of 15 yams V3] [mypy] add typing in serialize.py

Laurent Peuch cortex at worlddomination.be
Wed Jan 15 20:59:15 CET 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1579116480 -3600
#      Wed Jan 15 20:28:00 2020 +0100
# Node ID 32554ee1225a5639852c5ab1949c2af8bbdd7b33
# Parent  0e6cf6b04bbda2352c6eb719be5834ebc8a65d9f
# Available At https://hg.logilab.org/users/lpeuch/yams
#              hg pull https://hg.logilab.org/users/lpeuch/yams -r 32554ee1225a
[mypy] add typing in serialize.py

diff --git a/yams/serialize.py b/yams/serialize.py
--- a/yams/serialize.py
+++ b/yams/serialize.py
@@ -1,17 +1,21 @@
 import logging
 from io import StringIO
+from typing import Dict
 from logilab.common.graph import ordered_nodes
 
 
-def serialize_to_python(s):
+def serialize_to_python(s) -> str:
     out = StringIO()
     w = out.write
     w(u'from yams.buildobjs import *\n\n')
-    graph = {}
+
+    graph: Dict = {}
+
     for entity in s.entities():
-        l = graph.setdefault(entity, [])
+        l_ = graph.setdefault(entity, [])
         if entity._specialized_type is not None:
-            l.append(entity._specialized_type)
+            l_.append(entity._specialized_type)
+
     for e in reversed(ordered_nodes(graph)):
         if not e.final:
             if e._specialized_type:
@@ -26,6 +30,7 @@ def serialize_to_python(s):
             else:
                 w(u'    pass\n')
             w(u'\n')
+
     for r in s.relations():
         if not r.final:
             if r.subjects() and r.objects():
@@ -38,4 +43,5 @@ def serialize_to_python(s):
             else:
                 logging.warning(
                     'relation definition %s missing subject/object' % r.type)
+
     return out.getvalue()



More information about the cubicweb-devel mailing list