33from dataclasses import dataclass
44from enum import Enum , unique
55from traceback import format_exc
6- from typing import NewType , List , Dict , Optional , Any , Tuple , Union , Pattern
6+ from typing import NewType , Optional , Any , Tuple , Union , Pattern
77
88from pystrict import strict
99
@@ -23,7 +23,7 @@ class OntoInfo:
2323 hashtag : bool
2424
2525
26- ContextType = NewType ("ContextType" , Dict [str , OntoInfo ])
26+ ContextType = NewType ("ContextType" , dict [str , OntoInfo ])
2727
2828
2929def LINE () -> int :
@@ -86,7 +86,7 @@ class Cardinality(Enum):
8686@strict
8787class ContextIterator :
8888 _context : 'Context'
89- _prefixes : List [str ]
89+ _prefixes : list [str ]
9090 _index : int
9191
9292 def __init__ (self , context : 'Context' ):
@@ -111,10 +111,10 @@ class Context:
111111 This class holds a JSON-LD context with the ontology IRI's and the associated prefixes
112112 """
113113 _context : ContextType
114- _rcontext : Dict [str , str ]
114+ _rcontext : dict [str , str ]
115115 _exp : Pattern [str ]
116116
117- common_ontologies = ContextType ({
117+ common_ontologies = ContextType ({
118118 "foaf" : OntoInfo ("http://xmlns.com/foaf/0.1/" , False ),
119119 "dc" : OntoInfo ("http://purl.org/dc/elements/1.1/" , False ),
120120 "dcterms" : OntoInfo ("http://purl.org/dc/terms/" , False ),
@@ -148,7 +148,7 @@ def __is_iri(self, val: str) -> bool:
148148 m = self ._exp .match (val )
149149 return m .span ()[1 ] == len (val ) if m else False
150150
151- def __init__ (self , context : Optional [Dict [str , str ]] = None ):
151+ def __init__ (self , context : Optional [dict [str , str ]] = None ):
152152 """
153153 THe Constructor of the Context. It takes one optional parameter which as a dict of
154154 prefix - ontology-iri pairs. If the hashtag "#" is used to append element name, the
@@ -158,17 +158,17 @@ def __init__(self, context: Optional[Dict[str, str]] = None):
158158 # regexp to test for a complete IRI (including fragment identifier)
159159 self ._exp = re .compile ("^(http)s?://([\\ w\\ .\\ -~]+)?(:\\ d{,6})?(/[\\ w\\ -~]+)*(#[\\ w\\ -~]*)?" )
160160 self ._context = ContextType ({})
161-
161+
162162 # add ontologies from context, if any
163163 if context :
164164 for prefix , onto in context .items ():
165165 self ._context [prefix ] = OntoInfo (onto .removesuffix ('#' ), onto .endswith ('#' ))
166-
166+
167167 # add standard ontologies (rdf, rdfs, owl, xsl)
168168 for k , v in self .base_ontologies .items ():
169169 if not self ._context .get (k ):
170170 self ._context [k ] = v
171-
171+
172172 # add DSP-API internal ontologies (knora-api, salsah-gui)
173173 for k , v in self .knora_ontologies .items ():
174174 if not self ._context .get (k ):
@@ -224,7 +224,7 @@ def context(self, value: ContextType) -> None:
224224 raise BaseError ("Error in parameter to context setter" )
225225
226226 @property
227- def rcontext (self ) -> Dict [str , str ]:
227+ def rcontext (self ) -> dict [str , str ]:
228228 return self ._rcontext
229229
230230 def add_context (self , prefix : str , iri : Optional [str ] = None ) -> None :
@@ -400,15 +400,15 @@ def reduce_iri(self, iristr: str, ontoname: Optional[str] = None) -> str:
400400 else :
401401 return iristr
402402
403- def toJsonObj (self ) -> Dict [str , str ]:
403+ def toJsonObj (self ) -> dict [str , str ]:
404404 """
405405 Return a python object that can be jsonfied...
406406 :return: Object to be jsonfied
407407 """
408408 return {prefix : oinfo .iri + '#' if oinfo .hashtag else oinfo .iri
409409 for prefix , oinfo in self ._context .items ()}
410410
411- def get_externals_used (self ) -> Dict [str , str ]:
411+ def get_externals_used (self ) -> dict [str , str ]:
412412 exclude = ["rdf" , "rdfs" , "owl" , "xsd" , "knora-api" , "salsah-gui" ]
413413 return {prefix : onto .iri for prefix , onto in self ._context .items () if prefix not in exclude }
414414
@@ -487,7 +487,7 @@ class WithId:
487487 """
488488 _tmp : str = None
489489
490- def __init__ (self , obj : Optional [Dict [str , str ]]):
490+ def __init__ (self , obj : Optional [dict [str , str ]]):
491491 if obj is None :
492492 return
493493 self ._tmp = obj .get ('@id' )
0 commit comments