Gentoo Archives: gentoo-releng

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-releng@l.g.o
Subject: Re: [gentoo-releng] Enable USE_EXPAND support in catalyst
Date: Sun, 15 Feb 2015 16:46:54
Message-Id: 54E0CDC9.7040200@gentoo.org
In Reply to: Re: [gentoo-releng] Enable USE_EXPAND support in catalyst by "Rémi Cardona"
1 On 02/15/15 02:54, Rémi Cardona wrote:
2 > Le 14/02/2015 20:03, Anthony G. Basile a écrit :
3 > In the last chunk of modules/generic_stage_target.py:
4 >
5 > * type(var) == types.DictType can be replaced with
6 > isinstance(var, dict).
7 >
8 > Same thing for StringType/str, ListType/list and BooleanType/bool.
9 > This is how simple types were checked before Python 2.2 (around 2002).
10 >
11 > * string.replace has been deprecated for ages, use str.replace directly:
12 >
13 > varname2="clst_"+string.replace(y,"/","_")
14 > varname2=string.replace(varname2,"-","_")
15 > varname2=string.replace(varname2,".","_")
16 >
17 > becomes
18 >
19 > varname2 = "clst_" + y.replace("/", "_")
20 > varname2 = varname2.replace("-", "_")
21 > varname2 = varname2.replace(".", "_")
22 >
23 > * string.join is also deprecated, use ' '.join() instead
24 >
25 > * dict objects are iterable (and they return keys). This means that
26 >
27 > string.join(self.settings[x].keys())
28 >
29 > can be written (with the join suggestion above):
30 >
31 > ' '.join(self.settings[x])
32
33 Looking at that code was like a walk down memory lane. Those idioms are
34 used consistently in many different places throughout the code. I'd
35 rather not break from those idioms in this commit because then you get
36 mixed code. If we want to modernize the codebase then we should just
37 grep the source tree and do massive commits switching string.replace()
38 with <str obj>.replace() etc.
39
40 So I'm not disagreeing with you here, but not for this commit.
41
42 >
43 > * You may want to use dict.items() to get both the key and the
44 > associated value:
45 >
46 > for y in self.settings[x].keys():
47 >
48 > becomes:
49 >
50 > for y, val in self.settings[x].items():
51 >
52 > which should allow you to replace "self.settings[x][y]" with "val"
53 >
54 > Cheers,
55 >
56 > Rémi
57 >
58
59 I don't know when d.items() came to python but this one bothers me
60 enough that I'll switch --- I never remember it not being there. There
61 are a few other places using this idiom in the source, but at least not
62 in generic_stage_target.py. Maybe I'll submit a few cleanup commits,
63 but with catalyst 3.x coming, its hard to justify putting the effort
64 into it. There's some pretty scary insanity in 2.x like take a look at
65 line 662 of modules/generic_stage_target.py.
66
67 @Brian. What do you think? Should I spend some time modernizing 2.x or
68 just wait for 3.x?
69
70 --
71 Anthony G. Basile, Ph.D.
72 Gentoo Linux Developer [Hardened]
73 E-Mail : blueness@g.o
74 GnuPG FP : 1FED FAD9 D82C 52A5 3BAB DC79 9384 FA6E F52D 4BBA
75 GnuPG ID : F52D4BBA