1- from typing import Any , Iterable , Iterator , List , Optional , Set , Tuple , Union , overload
1+ import pathlib
2+ from typing import (
3+ IO ,
4+ Any ,
5+ Iterable ,
6+ Iterator ,
7+ List ,
8+ Optional ,
9+ Set ,
10+ Tuple ,
11+ Union ,
12+ overload ,
13+ )
214
315from rdflib import query
416from rdflib .collection import Collection
17+ from rdflib .paths import Path
518from rdflib .resource import Resource
619from rdflib .term import BNode , Identifier , Node
720
@@ -37,6 +50,12 @@ class Graph(Node):
3750 Optional [Identifier ],
3851 ],
3952 ) -> Iterator [Tuple [Identifier , Identifier , Identifier ]]: ...
53+ def __getitem__ (
54+ self , item : slice | Path | Node
55+ ) -> Iterator [
56+ Tuple [Identifier , Identifier , Identifier ] | Tuple [Identifier , identifier ] | Node
57+ ]: ...
58+ def __contains__ (self , triple : Any ) -> bool : ...
4059 def __add__ (self , other : Any ) -> Graph : ...
4160 def set (self , triple : Any ) -> None : ...
4261 def subjects (
@@ -47,7 +66,7 @@ class Graph(Node):
4766 ) -> Iterable [Node ]: ...
4867 def objects (
4968 self , subject : Optional [Any ] = ..., predicate : Optional [Any ] = ...
50- ) -> Iterable [Node ]: ...
69+ ) -> Iterable [Identifier ]: ...
5170 def subject_predicates (self , object : Optional [Any ] = ...) -> None : ...
5271 def subject_objects (self , predicate : Optional [Any ] = ...) -> None : ...
5372 def predicate_objects (self , subject : Optional [Any ] = ...) -> None : ...
@@ -87,13 +106,61 @@ class Graph(Node):
87106 ) -> Any : ...
88107 def namespaces (self ) -> Iterator [Tuple [Any , Any ]]: ...
89108 def absolutize (self , uri : Any , defrag : int = ...) -> Any : ...
109+
110+ # no destination and non-None positional encoding
111+ @overload
112+ def serialize (
113+ self ,
114+ destination : None ,
115+ format : str ,
116+ base : Optional [str ],
117+ encoding : str ,
118+ ** args : Any ,
119+ ) -> bytes : ...
120+
121+ # no destination and non-None keyword encoding
122+ @overload
90123 def serialize (
91124 self ,
92- destination : Optional [ Any ] = ...,
125+ destination : None = ...,
93126 format : str = ...,
94- base : Optional [Any ] = ...,
95- encoding : Optional [Any ] = ...,
96- ** args : Any
127+ base : Optional [str ] = ...,
128+ * ,
129+ encoding : str ,
130+ ** args : Any ,
131+ ) -> bytes : ...
132+
133+ # no destination and None encoding
134+ @overload
135+ def serialize (
136+ self ,
137+ destination : None = ...,
138+ format : str = ...,
139+ base : Optional [str ] = ...,
140+ encoding : None = ...,
141+ ** args : Any ,
142+ ) -> str : ...
143+
144+ # non-None destination
145+ @overload
146+ def serialize (
147+ self ,
148+ destination : Union [str , pathlib .PurePath , IO [bytes ]],
149+ format : str = ...,
150+ base : Optional [str ] = ...,
151+ encoding : Optional [str ] = ...,
152+ ** args : Any ,
153+ ) -> "Graph" : ...
154+
155+ # fallback
156+ @overload
157+ def serialize (
158+ self ,
159+ destination : Optional [Union [str , pathlib .PurePath , IO [bytes ]]] = ...,
160+ format : str = ...,
161+ base : Optional [str ] = ...,
162+ encoding : Optional [str ] = ...,
163+ ** args : Any ,
97164 ) -> Union [bytes , str , "Graph" ]: ...
98165 def parse (
99166 self ,
@@ -103,7 +170,7 @@ class Graph(Node):
103170 location : Optional [Any ] = ...,
104171 file : Optional [Any ] = ...,
105172 data : Optional [Any ] = ...,
106- ** args : Any
173+ ** args : Any ,
107174 ) -> "Graph" : ...
108175 def load (
109176 self , source : Any , publicID : Optional [Any ] = ..., format : str = ...
@@ -116,7 +183,7 @@ class Graph(Node):
116183 initNs : Optional [Any ] = ...,
117184 initBindings : Optional [Any ] = ...,
118185 use_store_provided : bool = ...,
119- ** kwargs : Any
186+ ** kwargs : Any ,
120187 ) -> query .Result : ...
121188 def update (
122189 self ,
@@ -125,7 +192,7 @@ class Graph(Node):
125192 initNs : Optional [Any ] = ...,
126193 initBindings : Optional [Any ] = ...,
127194 use_store_provided : bool = ...,
128- ** kwargs : Any
195+ ** kwargs : Any ,
129196 ) -> Any : ...
130197 def n3 (self ) -> str : ...
131198 def isomorphic (self , other : Any ) -> bool : ...
@@ -177,7 +244,7 @@ class ConjunctiveGraph(Graph):
177244 location : Optional [Any ] = ...,
178245 file : Optional [Any ] = ...,
179246 data : Optional [Any ] = ...,
180- ** args : Any
247+ ** args : Any ,
181248 ) -> Graph : ...
182249
183250class Seq :
0 commit comments