Skip to content

Commit abbd47f

Browse files
pmhahnberrange
authored andcommitted
override: Add manual PEP 484 type annotations
Signed-off-by: Philipp Hahn <[email protected]>
1 parent 67af8b9 commit abbd47f

9 files changed

+173
-127
lines changed

libvirt-override-virConnect.py

+66-71
Large diffs are not rendered by default.

libvirt-override-virDomain.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def listAllSnapshots(self, flags=0):
1+
def listAllSnapshots(self, flags: int = 0) -> List['virDomainSnapshot']:
22
"""List all snapshots and returns a list of snapshot objects"""
33
ret = libvirtmod.virDomainListAllSnapshots(self._o, flags)
44
if ret is None:
@@ -10,7 +10,7 @@ def listAllSnapshots(self, flags=0):
1010

1111
return retlist
1212

13-
def listAllCheckpoints(self, flags=0):
13+
def listAllCheckpoints(self, flags: int = 0) -> List['virDomainCheckpoint']:
1414
"""List all checkpoints and returns a list of checkpoint objects"""
1515
ret = libvirtmod.virDomainListAllCheckpoints(self._o, flags)
1616
if ret is None:
@@ -22,7 +22,7 @@ def listAllCheckpoints(self, flags=0):
2222

2323
return retlist
2424

25-
def createWithFiles(self, files, flags=0):
25+
def createWithFiles(self, files: List[int], flags: int = 0) -> 'virDomain':
2626
"""Launch a defined domain. If the call succeeds the domain moves from the
2727
defined to the running domains pools.
2828
@@ -60,28 +60,28 @@ def createWithFiles(self, files, flags=0):
6060
raise libvirtError('virDomainCreateWithFiles() failed')
6161
return ret
6262

63-
def fsFreeze(self, mountpoints=None, flags=0):
63+
def fsFreeze(self, mountpoints: List[str] = None, flags: int = 0) -> int:
6464
"""Freeze specified filesystems within the guest """
6565
ret = libvirtmod.virDomainFSFreeze(self._o, mountpoints, flags)
6666
if ret == -1:
6767
raise libvirtError('virDomainFSFreeze() failed')
6868
return ret
6969

70-
def fsThaw(self, mountpoints=None, flags=0):
70+
def fsThaw(self, mountpoints: List[str] = None, flags: int = 0) -> int:
7171
"""Thaw specified filesystems within the guest """
7272
ret = libvirtmod.virDomainFSThaw(self._o, mountpoints, flags)
7373
if ret == -1:
7474
raise libvirtError('virDomainFSThaw() failed')
7575
return ret
7676

77-
def getTime(self, flags=0):
77+
def getTime(self, flags: int = 0) -> int:
7878
"""Extract information about guest time """
7979
ret = libvirtmod.virDomainGetTime(self._o, flags)
8080
if ret == None:
8181
raise libvirtError('virDomainGetTime() failed')
8282
return ret
8383

84-
def setTime(self, time=None, flags=0):
84+
def setTime(self, time: int = None, flags: int = 0) -> int:
8585
"""Set guest time to the given value. @time is a dict containing
8686
'seconds' field for seconds and 'nseconds' field for nanoseconds """
8787
ret = libvirtmod.virDomainSetTime(self._o, time, flags)

libvirt-override-virDomainCheckpoint.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def getConnect(self):
1+
def getConnect(self) -> 'virConnect':
22
"""Get the connection that owns the domain that a checkpoint was created for"""
33
return self.connect()
44

5-
def getDomain(self):
5+
def getDomain(self) -> 'virDomain':
66
"""Get the domain that a checkpoint was created for"""
77
return self.domain()
88

9-
def listAllChildren(self, flags=0):
9+
def listAllChildren(self, flags: int = 0) -> List['virDomainCheckpoint']:
1010
"""List all child checkpoints and returns a list of checkpoint objects"""
1111
ret = libvirtmod.virDomainCheckpointListAllChildren(self._o, flags)
1212
if ret is None:

libvirt-override-virDomainSnapshot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def getConnect(self):
1+
def getConnect(self) -> 'virConnect':
22
"""Get the connection that owns the domain that a snapshot was created for"""
33
return self.connect()
44

5-
def getDomain(self):
5+
def getDomain(self) -> 'virDomain':
66
"""Get the domain that a snapshot was created for"""
77
return self.domain()
88

9-
def listAllChildren(self, flags=0):
9+
def listAllChildren(self, flags: int = 0) -> List['virDomainSnapshot']:
1010
"""List all child snapshots and returns a list of snapshot objects"""
1111
ret = libvirtmod.virDomainSnapshotListAllChildren(self._o, flags)
1212
if ret is None:

libvirt-override-virNetwork.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def listAllPorts(self, flags=0):
1+
def listAllPorts(self, flags: int = 0) -> List['virNetworkPort']:
22
"""List all ports on the network and returns a list of network port objects"""
33
ret = libvirtmod.virNetworkListAllPorts(self._o, flags)
44
if ret is None:

libvirt-override-virStoragePool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def listAllVolumes(self, flags=0):
1+
def listAllVolumes(self, flags: int = 0) -> List['virStorageVol']:
22
"""List all storage volumes and returns a list of storage volume objects"""
33
ret = libvirtmod.virStoragePoolListAllVolumes(self._o, flags)
44
if ret is None:

libvirt-override-virStream.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def __del__(self):
1+
def __del__(self) -> None:
22
try:
33
if self.cb:
44
libvirtmod.virStreamEventRemoveCallback(self._o)
@@ -9,7 +9,7 @@ def __del__(self):
99
libvirtmod.virStreamFree(self._o)
1010
self._o = None
1111

12-
def _dispatchStreamEventCallback(self, events, cbData):
12+
def _dispatchStreamEventCallback(self, events: int, cbData: Dict[str, Any]) -> int:
1313
"""
1414
Dispatches events to python user's stream event callbacks
1515
"""
@@ -19,14 +19,14 @@ def _dispatchStreamEventCallback(self, events, cbData):
1919
cb(self, events, opaque)
2020
return 0
2121

22-
def eventAddCallback(self, events, cb, opaque):
22+
def eventAddCallback(self, events: int, cb: Callable[['virStream', int, _T], None], opaque: _T) -> None:
2323
self.cb = cb
2424
cbData = {"stream": self, "cb": cb, "opaque": opaque}
2525
ret = libvirtmod.virStreamEventAddCallback(self._o, events, cbData)
2626
if ret == -1:
2727
raise libvirtError('virStreamEventAddCallback() failed')
2828

29-
def recvAll(self, handler, opaque):
29+
def recvAll(self, handler: Callable[['virStream', bytes, _T], int], opaque: _T) -> None:
3030
"""Receive the entire data stream, sending the data to the
3131
requested data sink. This is simply a convenient alternative
3232
to virStreamRecv, for apps that do blocking-I/O.
@@ -59,7 +59,7 @@ def handler(stream, # virStream instance
5959
pass
6060
raise e
6161

62-
def sendAll(self, handler, opaque):
62+
def sendAll(self, handler: Callable[['virStream', int, _T], bytes], opaque: _T) -> None:
6363
"""
6464
Send the entire data stream, reading the data from the
6565
requested data source. This is simply a convenient alternative
@@ -92,7 +92,7 @@ def handler(stream, # virStream instance
9292
raise libvirtError("cannot use sendAll with "
9393
"nonblocking stream")
9494

95-
def recv(self, nbytes):
95+
def recv(self, nbytes: int) -> bytes:
9696
"""Reads a series of bytes from the stream. This method may
9797
block the calling application for an arbitrary amount
9898
of time.
@@ -110,7 +110,7 @@ def recv(self, nbytes):
110110
raise libvirtError('virStreamRecv() failed')
111111
return ret
112112

113-
def send(self, data):
113+
def send(self, data: bytes) -> int:
114114
"""Write a series of bytes to the stream. This method may
115115
block the calling application for an arbitrary amount
116116
of time. Once an application has finished sending data
@@ -129,7 +129,7 @@ def send(self, data):
129129
raise libvirtError('virStreamSend() failed')
130130
return ret
131131

132-
def recvHole(self, flags=0):
132+
def recvHole(self, flags: int = 0) -> int:
133133
"""This method is used to determine the length in bytes
134134
of the empty space to be created in a stream's target
135135
file when uploading or downloading sparsely populated
@@ -140,7 +140,7 @@ def recvHole(self, flags=0):
140140
raise libvirtError('virStreamRecvHole() failed')
141141
return ret
142142

143-
def sendHole(self, length, flags=0):
143+
def sendHole(self, length: int, flags: int = 0) -> int:
144144
"""Rather than transmitting empty file space, this method
145145
directs the stream target to create length bytes of empty
146146
space. This method would be used when uploading or
@@ -152,7 +152,7 @@ def sendHole(self, length, flags=0):
152152
raise libvirtError('virStreamSendHole() failed')
153153
return ret
154154

155-
def recvFlags(self, nbytes, flags=0):
155+
def recvFlags(self, nbytes: int, flags: int = 0) -> Union[bytes, int]:
156156
"""Reads a series of bytes from the stream. This method may
157157
block the calling application for an arbitrary amount
158158
of time. This is just like recv except it has flags
@@ -171,7 +171,7 @@ def recvFlags(self, nbytes, flags=0):
171171
raise libvirtError('virStreamRecvFlags() failed')
172172
return ret
173173

174-
def sparseRecvAll(self, handler, holeHandler, opaque):
174+
def sparseRecvAll(self, handler: Callable[['virStream', bytes, _T], Union[bytes, int]], holeHandler: Callable[['virStream', int, _T], Optional[int]], opaque: _T) -> None:
175175
"""Receive the entire data stream, sending the data to
176176
the requested data sink handler and calling the skip
177177
holeHandler to generate holes for sparse stream targets.
@@ -219,7 +219,7 @@ def holeHandler(stream, # virStream instance
219219
self.abort()
220220
raise RuntimeError("sparseRecvAll handler returned %d" % ret)
221221

222-
def sparseSendAll(self, handler, holeHandler, skipHandler, opaque):
222+
def sparseSendAll(self, handler: Callable[['virStream', int, _T], Union[bytes, int]], holeHandler: Callable[['virStream', _T], Tuple[bool, int]], skipHandler: Callable[['virStream', int, _T], int], opaque: _T) -> None:
223223
"""Send the entire data stream, reading the data from the
224224
requested data source. This is simply a convenient
225225
alternative to virStreamSend, for apps that do
@@ -269,6 +269,7 @@ def skipHandler(stream, # virStream instance
269269
if not got:
270270
break
271271

272+
assert isinstance(got, bytes)
272273
ret = self.send(got)
273274
if ret == -2:
274275
raise libvirtError("cannot use sparseSendAll with "

0 commit comments

Comments
 (0)