[Rpm-maint] pull request with Python 3 support bug fix

Panu Matilainen pmatilai at laiskiainen.org
Thu Oct 17 09:30:18 UTC 2013


On 10/16/2013 07:42 PM, Jan Silhan wrote:

Hi,

> Hi, I'd like create a pull request to RPM: https://github.com/jsilhan/rpm.
> It's fix in python/rpm/transaction.py for Python 3 support.

Mmh, this made me realize I by far prefer patches via email over pull 
requests - when there's something to discuss about a patch, inlined 
email patches makes that far more natural than with pull requests.

> diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py
> index 756e893..d15623d 100644
> --- a/python/rpm/transaction.py
> +++ b/python/rpm/transaction.py
> @@ -2,6 +2,11 @@
>
>  import rpm
>  from rpm._rpm import ts as TransactionSetCore
> +from sys import version_info
> +
> +if version_info.major >= 3:
> +    from io import IOBase as file

This "as file" import is presumably for the isinstance(item, file) check 
in addInstall(), right? I think the better thing to do would be changing 
it to check for a file-like object instead, ie 
PyObject_AsFileDescriptor() equivalent in python. That makes the code 
more flexible and avoids the need for python3-specific tweaks at the 
same time. Using isinstance() on "file" originally looks like a brain 
malfunction on my behalf...

> +    basestring = unicode = str

This smells like a hack that'll come back biting us sooner or later. 
However I've no idea what's the "standard" way of doing this in a python 
2 & 3 compatible manner.

>  # TODO: migrate relevant documentation from C-side
>  class TransactionSet(TransactionSetCore):
> @@ -46,7 +51,7 @@ class TransactionSet(TransactionSetCore):
>
>      def addInstall(self, item, key, how="u"):
>          if isinstance(item, basestring):
> -            f = file(item)
> +            f = open(item)

This is obviously ok, using file() there is another brain malfunction of 
mine :)

>              header = self.hdrFromFdno(f)
>              f.close()
>          elif isinstance(item, file):

	- Panu -


More information about the Rpm-maint mailing list