diff service/reasoning/inputgraph.py @ 756:f3f667769aef

python 3! and some types and cleanups Ignore-this: 3453a547ee745fa83668f36956c835cd
author drewp@bigasterisk.com
date Fri, 14 Feb 2020 00:07:23 -0800
parents ffcad6bf9c57
children c8562ace4917
line wrap: on
line diff
--- a/service/reasoning/inputgraph.py	Thu Feb 13 23:00:06 2020 -0800
+++ b/service/reasoning/inputgraph.py	Fri Feb 14 00:07:23 2020 -0800
@@ -1,5 +1,6 @@
 import logging, time
 import weakref
+from typing import Callable
 
 from greplin import scales
 from rdflib import Graph, ConjunctiveGraph
@@ -11,6 +12,7 @@
 
 from patchablegraph.patchsource import ReconnectingPatchSource
 from rdfdb.rdflibpatch import patchQuads
+from rdfdb.patch import Patch
 
 log = logging.getLogger('fetch')
 
@@ -21,7 +23,9 @@
 STATS = scales.collection('/web',
                           scales.PmfStat('combineGraph'),
 )
-def parseRdf(text, contentType):
+
+
+def parseRdf(text: str, contentType: str):
     g = Graph()
     g.parse(StringInputSource(text), format={
         'text/n3': 'n3',
@@ -30,7 +34,7 @@
 
 
 class RemoteData(object):
-    def __init__(self, onChange):
+    def __init__(self, onChange: Callable[[], None]):
         """we won't fire onChange during init"""
         self.onChange = onChange
         self.graph = ConjunctiveGraph()
@@ -42,7 +46,7 @@
             #URIRef('http://frontdoor:10012/graph/events'),
             self.onPatch, reconnectSecs=10, agent='reasoning')
 
-    def onPatch(self, p, fullGraph):
+    def onPatch(self, p: Patch, fullGraph: bool):
         if fullGraph:
             self.graph = ConjunctiveGraph()
         patchQuads(self.graph,
@@ -79,6 +83,7 @@
         else:
             log.debug("  remote graph has no changes to trigger rules")
 
+
 class InputGraph(object):
     def __init__(self, inputDirs, onChange):
         """