Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] Generate soname dependency metadata (282639)
Date: Fri, 30 Jan 2015 19:28:36
Message-Id: 20150130112831.4f431a74.dolsen@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] Generate soname dependency metadata (282639) by Zac Medico
1 On Thu, 29 Jan 2015 22:01:51 -0800
2 Zac Medico <zmedico@g.o> wrote:
3
4 > On 01/29/2015 09:00 PM, Michał Górny wrote:
5 > > Dnia 2015-01-26, o godz. 19:16:28
6 > > Zac Medico <zmedico@g.o> napisał(a):
7 > >> +from ...util.elf.constants import (
8 > >
9 > > Please do not use relative imports. Almost all code is using
10 > > absolute imports so if we're going to change that, we should get a
11 > > proper discussion first.
12 >
13 > Well, is anyone else here opposed to using relative imports? They are
14 > supported since python 2.5, and I don't see anything wrong with them.
15 >
16
17
18 I'm not a fan of relative imports myself. I've had trouble with them
19 when I did try using them. Plus I've found it harder to make changes to
20 code and search for the imports which may need changing.
21
22
23
24
25 >
26 > >> +def decode_uint32_le(data):
27 > >> + """
28 > >> + Decode an unsigned 32-bit integer with little-endian
29 > >> encoding. +
30 > >> + @param data: string of bytes of length 4
31 > >> + @type data: bytes
32 > >> + @rtype: int
33 > >> + @return: unsigned integer value of the decoded data
34 > >> + """
35 > >> + return (
36 > >> + ord(data[0:1]) +
37 > >> + (ord(data[1:2]) << 8) +
38 > >> + (ord(data[2:3]) << 16) +
39 > >> + (ord(data[3:4]) << 24)
40 > >> + )
41 > >
42 > > How about using the struct module instead of reinventing the wheel?
43 >
44 > Well the versions that I wrote seem a lot more readable to me than
45 > they would be if written using things like struct.unpack_from("<L",
46 > data)[0]. Either way is fine with me, though. Google seems to show
47 > some issues with struct import failing for broken python
48 > installations, but that should not be an issue in practice.
49
50 broken python is not reliable then anyway...
51
52 I think I like the struct idea better.
53
54 --
55 Brian Dolbec <dolsen>