summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* generator: Simplify string concatentaionPhilipp Hahn2020-09-011-6/+2
| | | | | | | by using ''.join() instead of concatenating string fragments in a loop, which is slower as it required re-hashing the string multiple times. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Use more string formattingPhilipp Hahn2020-09-011-7/+4
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Merge now identical if-elif-else casesPhilipp Hahn2020-09-011-92/+10
| | | | | | | | | | | | Commit ca394b9f "generator: Fix parent type" fixed the case for creating `virStorage*` instances, which require a reference to `virConnect`, so the special handling for `._conn` is no longer needed. Commit ee5c856a "Remove legacy libvirtError arguments" removed the different arguments, so all cases are the same now. Signed-off-by: Philipp Hahn <hahn@univention.de> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* generator: Fix return type on failurePhilipp Hahn2020-09-011-2/+2
| | | | | | to return a negative value instead of None for consistency. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Remove useless sort keyPhilipp Hahn2020-09-011-1/+1
| | | | | | tuples are sorted by first component anyway. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Remove skipped_modulesPhilipp Hahn2020-09-011-6/+0
| | | | | | Unused. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Remove dead variable assignmentsPhilipp Hahn2020-09-011-2/+0
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Use raw-string for regular expressionPhilipp Hahn2020-09-011-1/+1
| | | | | | | | | | | | | "\(" is not a valid escape sequence for a Python string, but currently is passed on unmodified. This might breaks in the future when new escape sequences are introduced. > generator.py:1001:7: W605 invalid escape sequence '\(' > generator.py:1001:18: W605 invalid escape sequence '\)' Use raw python string instead. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Convert to 'not in' and 'is not'Philipp Hahn2020-09-011-2/+2
| | | | | | as recommended by pep8 Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Change type of quiet to boolPhilipp Hahn2020-09-011-1/+1
| | | | | | Use `bool` instead of `int`. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Simplify exception handlingPhilipp Hahn2020-09-011-18/+8
| | | | | | | sys.exc_info() returns a 3-tuple (type, value, traceback), where `value` is the instance captured by `except type as value`. Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Cleanup importsPhilipp Hahn2020-09-011-7/+5
| | | | | | | | Move imports to top Remove unused import string Remove duplicate import os Signed-off-by: Philipp Hahn <hahn@univention.de>
* generator: Do not use bare exceptPhilipp Hahn2020-09-011-2/+2
| | | | | | as it also catches SystemExit, InterruptedError, SyntaxError and such. Signed-off-by: Philipp Hahn <hahn@univention.de>
* Post-release version bump to 6.8.0Jiri Denemark2020-09-011-1/+1
| | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
* Revert "libvirtaio: Drop object(*args, **kwargs)"v6.7.0Philipp Hahn2020-08-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit f4be03b330125ab1e5a2bb10b4f12674aeff4691. While object.__init__() does not expect any additional arguments, this construct is required for Pythons multiple inheritance implementation. The original author Wojtek Porczyk <woju@invisiblethingslab.com> explained is this way: > I'm sorry I didn't notice this earlier, but the commit f4be03b3 dated > 2020-04-20 [0] is wrong. The super().__init__(*args, **kwargs) in > Callback.__init__ was there on purpose, because of how Python's inheritance in > new-style classes works. > > Let me explain this a bit, because it is not obvious. > > Suppose you had diamond inheritance like this: > > class A(object): pass > class B(A): pass > class C(A): pass > class D(B,C): pass > > And those classes needed a common function with varying arguments: > > class A(object): > def spam(self, a): print(f'A: {a}') > class B(A): > def spam(self, b): print(f'B: {b}') > class C(A): > def spam(self, c): print(f'C: {c}') > class D(B,C): > def spam(self, d): print(f'D: {d}') > > The way to call all parent's functions exactly once (as per MRO) and accept > all arguments and also forbid unknown arguments is to accept **kwargs > everywhere and pass them to super().spam(): > > class A: > def spam(self, a): > print(f'A: {a}') > class B(A): > def spam(self, b, **kwargs): > print(f'B: {b}') > super().spam(**kwargs) > class C(A): > def spam(self, c, **kwargs): > print(f'C: {c}') > super().spam(**kwargs) > class D(B, C): > def spam(self, d, **kwargs): > print(f'D: {d}') > super().spam(**kwargs) > > Let's run this: > > >>> B().spam(a=1, b=2) > B: 2 > A: 1 > >>> D().spam(a=1, b=2, c=3, d=4) > D: 4 > B: 2 > C: 3 > A: 1 > > You may notice that super() in B.spam refers to two different classes, either > A or C, depending on inheritance order in yet undefined classes (as of B's > definition). > > That's why the conclusion that super() in Callback.__init__ refers to object > is wrong. In this example, spam=__init__, A=object, B=Callback and C and D are > not yet written, but theoretically possible classes that could be written by > someone else. Why would they be needed, I don't know, but if someone writes > them, s/he would be out of options to invent new arguments to C.__init__. > > Note that super().__init__(*args, **kwargs) when super() refers to object > isn't harmful, and just ensures that args and kwargs are empty (i.e. no > unknown arguments were passed). In fact, this is exactly why object.__init__() > takes no arguments since Python 2.6 [1][2], as you correctly point out in the > commit message. > > I don't think this breaks anything (I very much doubt anyone would need to > write code that would trigger this), nevertheless, as the commit is both > pointless and wrong, and as the original author of libvirtaio I'd like to ask > for this commit to be reverted. If this breaks some static analysis tool, > could you just suppress it for this particular line? > > > [0] https://gitlab.com/libvirt/libvirt-python/-/commit/f4be03b330125ab1e5a2bb10b4f12674aeff4691 > [1] https://bugs.python.org/issue1683368 > [2] https://docs.python.org/3/whatsnew/2.6.html#porting-to-python-2-6 > (fourth point) > Signed-off-by: Philipp Hahn <hahn@univention.de>
* connect: Just clear all event handlersPhilipp Hahn2020-08-181-2/+1
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* domain: Fix None comparisonPhilipp Hahn2020-08-181-1/+1
| | | | | | | None should be compared with "is None" instead of "== None", as the later would invoke a "__cmp__()" method. Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: Return None from callbackPhilipp Hahn2020-08-181-2/+0
| | | | | | nobody evaluates the return value. Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: Convert type() to isinstance()Philipp Hahn2020-08-181-4/+4
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: no type changePhilipp Hahn2020-08-181-6/+6
| | | | | | | static typing forbids re-declaring a variable with different types. Rename the variable. Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: Simplify boolean conditionPhilipp Hahn2020-08-181-1/+1
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: Fix exception traceback handlingPhilipp Hahn2020-08-181-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | sys.exc_info() returns a 3-tuple (type, value, traceback). Raising just `value` again looses the traceback information as this creates a new exception. Just use `raise` which re-raises the previous exception including the original traceback. FYI: There is a subtile difference between Python 2 and Python 3: > try: > raise ValueError() > except ValueError: > try: > raise TypeError() > except TypeError: > pass > raise With Python 3 the exception environment is dropped after the exception has been handled - as such Python 3 re-raises the outer ValueError. With Python 2 the last (inner) exception is raised: TypeError Signed-off-by: Philipp Hahn <hahn@univention.de>
* stream: Do not use bare exceptPhilipp Hahn2020-08-181-4/+4
| | | | | | as it also catches SystemExit, InterruptedError, SyntaxError and such. Signed-off-by: Philipp Hahn <hahn@univention.de>
* override: Convert to list comprehensionPhilipp Hahn2020-08-186-82/+16
| | | | | | :%s/retlist = list()\n\s*\(for \w\+ in ret\):\n\s*retlist.append(\(.*\))\n\n\s*return retlist/return [\2 \1]/ Signed-off-by: Philipp Hahn <hahn@univention.de>
* override: Catch type errorPhilipp Hahn2020-08-181-1/+5
| | | | | | | handler() should either return bytes or -2 or -3. Explicitly raise ValueError or TypeError to silence mypy. Signed-off-by: Philipp Hahn <hahn@univention.de>
* override: no type changePhilipp Hahn2020-08-181-6/+8
| | | | | | | static typing forbids re-declaring a variable with different types. Rename the variable. Signed-off-by: Philipp Hahn <hahn@univention.de>
* override: Add manual PEP 484 type annotationsPhilipp Hahn2020-08-189-127/+173
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* override: Simplify exception handlingPhilipp Hahn2020-08-181-7/+3
| | | | | | | sys.exc_info() returns a 3-tuple (type, value, traceback), where `value` is the instance captured by `except type as value`. Signed-off-by: Philipp Hahn <hahn@univention.de>
* Include libvirt-qemu-override.py in sdistVincent Vanlaer2020-08-181-0/+1
| | | | | | | | libvirt-qemu-override.py was introduced in e3da8f17 but never added to MANIFEST.in. It was therefore not contained in the official releases on libvirt.org. Signed-off-by: Vincent Vanlaer <vincent.vanlaer@skynet.be>
* libvirtaio: Add manual PEP 484 type annotationsPhilipp Hahn2020-08-071-38/+41
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* libvirtaio: assert callback typePhilipp Hahn2020-08-061-2/+7
| | | | | | | self.callbacks contains a mix of FDCallback and TimeoutCallback, while the update code does not explicitly check for. Signed-off-by: Philipp Hahn <hahn@univention.de>
* libvirtaio: Fix return typePhilipp Hahn2020-08-061-2/+1
| | | | | | libvirtaio.py:364: error: "virEventInvokeFreeCallback" does not return a value Signed-off-by: Philipp Hahn <hahn@univention.de>
* libvirtaio: Drop object(*args, **kwargs)Philipp Hahn2020-08-061-2/+1
| | | | | | object.__init__() does not expect those parameters. Signed-off-by: Philipp Hahn <hahn@univention.de>
* libvirtaio: Cleanup importsPhilipp Hahn2020-08-061-7/+7
| | | | | | Move imports to top Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: no type changePhilipp Hahn2020-08-061-2/+2
| | | | | | | static typing forbids re-declaring a variable with different types. Rename the variable. Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Use str.startswith() instead of str[0]Philipp Hahn2020-08-061-2/+2
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Use set for tracking used functionsPhilipp Hahn2020-08-061-3/+3
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Use 3-tuple for finalklassmapPhilipp Hahn2020-08-061-8/+3
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Use 3-tuple for basicklassmapPhilipp Hahn2020-08-061-9/+5
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Add PEP 484 type annotationsPhilipp Hahn2020-08-061-10/+11
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Drop Python 2 compatibilityPhilipp Hahn2020-08-061-3/+1
| | | | | | Python 3 only has int, remove the Python 2 long type Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Drop else:passPhilipp Hahn2020-08-061-4/+0
| | | | | | useless Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Do not re-declare setPhilipp Hahn2020-08-061-7/+3
| | | | | | is a built-in python type Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Convert type() to isinstance()Philipp Hahn2020-08-061-2/+2
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Skip type annotationsPhilipp Hahn2020-08-061-0/+2
| | | | | | Teach sanitytest to ignore typing imports Signed-off-by: Philipp Hahn <hahn@univention.de>
* sanitytest: Remove unused importPhilipp Hahn2020-08-061-1/+0
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* Remove legacy libvirtError argumentsPhilipp Hahn2020-08-068-57/+57
| | | | | | | | | | | | The fields have been deprecated in C with git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8 They are only passed to the libvirtError constructor, but not stored for later or used anywhere else. sed -ri '/raise libvirtError/s/, \w+=self(\._dom)?//' *.py Signed-off-by: Philipp Hahn <hahn@univention.de>
* Normalize white spacePhilipp Hahn2020-08-0610-378/+433
| | | | | | | indent by 4 spaces one spaces around assignments Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/event-test: Fix remove return typePhilipp Hahn2020-08-061-4/+6
| | | | | | | The remove function are supposed to return 0 on success and -1 on failure. <https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc> Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Fix white spacePhilipp Hahn2020-08-0510-31/+71
| | | | | | | indent by 4 spaces one spaces around assignments Signed-off-by: Philipp Hahn <hahn@univention.de>