1818import sys
1919import time
2020import warnings
21- from typing import Any , Dict , List , Optional , Tuple
21+ from typing import Any , Dict , List , Optional , Tuple , Union
2222from urllib .parse import quote
2323
2424import rdflib
@@ -105,7 +105,8 @@ def toProperty(label: str): # noqa: N802
105105 """
106106 label = re .sub (r"[^\w]" , " " , label )
107107 label = re .sub ("([a-z])([A-Z])" , "\\ 1 \\ 2" , label )
108- label = label .split (" " )
108+ # type error: Incompatible types in assignment (expression has type "None", variable has type "BinaryIO")
109+ label = label .split (" " ) # type: ignore[assignment]
109110 return "" .join ([label [0 ].lower ()] + [x .capitalize () for x in label [1 :]])
110111
111112
@@ -151,6 +152,7 @@ def __call__(self, x: Any):
151152
152153class NodeUri (NodeMaker ):
153154 def __init__ (self , prefix , class_ ):
155+ self .class_ : Optional [URIRef ] = None
154156 self .prefix = prefix
155157 if class_ :
156158 self .class_ = rdflib .URIRef (class_ )
@@ -303,7 +305,7 @@ def __init__(self):
303305 self .CLASS = None
304306 self .BASE = None
305307 self .PROPBASE = None
306- self .IDENT = "auto"
308+ self .IDENT : Union [ Tuple [ str , ...], str ] = "auto"
307309 self .LABEL = None
308310 self .DEFINECLASS = False
309311 self .SKIP = 0
@@ -375,23 +377,29 @@ def convert(self, csvreader):
375377 uri = self .BASE [
376378 "_" .join (
377379 [
378- quote (x .encode ("utf8" ).replace (" " , "_" ), safe = "" )
379- for x in index (l_ , self .IDENT )
380+ # type error: "int" has no attribute "encode"
381+ quote (x .encode ("utf8" ).replace (" " , "_" ), safe = "" ) # type: ignore[attr-defined]
382+ # type error: Argument 2 to "index" has incompatible type "Union[Tuple[str, ...], str]"; expected "Tuple[int, ...]"
383+ for x in index (l_ , self .IDENT ) # type: ignore[arg-type]
380384 ]
381385 )
382386 ]
383387
384388 if self .LABEL :
385389 self .triple (
386- uri , RDFS .label , rdflib .Literal (" " .join (index (l_ , self .LABEL )))
390+ # type error: Argument 1 to "join" of "str" has incompatible type "Tuple[int, ...]"; expected "Iterable[str]"
391+ uri ,
392+ RDFS .label ,
393+ rdflib .Literal (" " .join (index (l_ , self .LABEL ))), # type: ignore[arg-type]
387394 )
388395
389396 if self .CLASS :
390397 # type triple
391398 self .triple (uri , RDF .type , self .CLASS )
392399
393400 for i , x in enumerate (l_ ):
394- x = x .strip ()
401+ # type error: "int" has no attribute "strip"
402+ x = x .strip () # type: ignore[attr-defined]
395403 if x != "" :
396404 if self .COLUMNS .get (i , self .DEFAULT ) == "ignore" :
397405 continue
@@ -407,7 +415,8 @@ def convert(self, csvreader):
407415 warnings .warn (
408416 "Could not process value for column "
409417 + "%d:%s in row %d, ignoring: %s "
410- % (i , headers [i ], rows , e .message )
418+ # type error: "Exception" has no attribute "message"
419+ % (i , headers [i ], rows , e .message ) # type: ignore[attr-defined]
411420 )
412421
413422 rows += 1
@@ -422,13 +431,19 @@ def convert(self, csvreader):
422431
423432 # output types/labels for generated URIs
424433 classes = set ()
425- for l_ , x in uris .items ():
426- u , c = x
427- self .triple (u , RDFS .label , rdflib .Literal (l_ ))
428- if c :
429- c = rdflib .URIRef (c )
434+ # type error: Incompatible types in assignment (expression has type "Tuple[URIRef, Optional[URIRef]]", variable has type "int")
435+ for l_ , x in uris .items (): # type: ignore[assignment]
436+ # type error: "int" object is not iterable
437+ u , c = x # type: ignore[misc]
438+ # type error: Cannot determine type of "u"
439+ self .triple (u , RDFS .label , rdflib .Literal (l_ )) # type: ignore[has-type]
440+ # type error: Cannot determine type of "c"
441+ if c : # type: ignore[has-type]
442+ # type error: Cannot determine type of "c"
443+ c = rdflib .URIRef (c ) # type: ignore[has-type]
430444 classes .add (c )
431- self .triple (u , RDF .type , c )
445+ # type error: Cannot determine type of "u"
446+ self .triple (u , RDF .type , c ) # type: ignore[has-type]
432447
433448 for c in classes :
434449 self .triple (c , RDF .type , RDFS .Class )
@@ -441,6 +456,7 @@ def convert(self, csvreader):
441456def main ():
442457 csv2rdf = CSV2RDF ()
443458
459+ opts : Union [Dict [str , str ], List [Tuple [str , str ]]]
444460 opts , files = getopt .getopt (
445461 sys .argv [1 :],
446462 "hc:b:p:i:o:Cf:l:s:d:D:" ,
0 commit comments