Gentoo Archives: gentoo-portage-dev

From: Matt Turner <mattst88@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-portage-dev] [PATCH 3/3] lib: Remove outdated Python 2 comments
Date: Thu, 04 Mar 2021 19:24:06
Message-Id: 20210304192347.899796-3-mattst88@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/3] Remove Python 2 workaround by Matt Turner
1 Fixes: 788c0e8bb ("Remove from __future__ import unicode_literals")
2 Signed-off-by: Matt Turner <mattst88@g.o>
3 ---
4 bin/egencache | 2 --
5 lib/_emerge/Package.py | 9 ---------
6 lib/_emerge/Scheduler.py | 2 --
7 lib/_emerge/UseFlagDisplay.py | 2 --
8 lib/_emerge/resolver/output.py | 2 --
9 lib/portage/cache/flat_hash.py | 3 ---
10 lib/portage/tests/unicode/test_string_format.py | 9 ---------
11 lib/portage/util/digraph.py | 3 ---
12 8 files changed, 32 deletions(-)
13
14 diff --git a/bin/egencache b/bin/egencache
15 index 9b6df2e7d..fc18b892f 100755
16 --- a/bin/egencache
17 +++ b/bin/egencache
18 @@ -2,8 +2,6 @@
19 # Copyright 2009-2021 Gentoo Authors
20 # Distributed under the terms of the GNU General Public License v2
21
22 -# unicode_literals for compat with TextIOWrapper in Python 2
23 -
24 import argparse
25 import platform
26 import signal
27 diff --git a/lib/_emerge/Package.py b/lib/_emerge/Package.py
28 index 995af6311..0ee25b90a 100644
29 --- a/lib/_emerge/Package.py
30 +++ b/lib/_emerge/Package.py
31 @@ -453,15 +453,6 @@ class Package(Task):
32 else:
33 qacat = k + ".syntax"
34
35 - # For unicode safety with python-2.x we need to avoid
36 - # using the string format operator with a non-unicode
37 - # format string, since that will result in the
38 - # PortageException.__str__() method being invoked,
39 - # followed by unsafe decoding that may result in a
40 - # UnicodeDecodeError. Therefore, use unicode_literals
41 - # to ensure that format strings are unicode, so that
42 - # PortageException.__unicode__() is used when necessary
43 - # in python-2.x.
44 if not self.installed:
45 categorized_error = False
46 if e.errors:
47 diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py
48 index 465f928a0..0ed2ee530 100644
49 --- a/lib/_emerge/Scheduler.py
50 +++ b/lib/_emerge/Scheduler.py
51 @@ -1188,8 +1188,6 @@ class Scheduler(PollScheduler):
52 printer.eerror(line)
53 printer.eerror("")
54 for failed_pkg in self._failed_pkgs_all:
55 - # Use unicode_literals to force unicode format string so
56 - # that Package.__unicode__() is called in python2.
57 msg = " %s" % (failed_pkg.pkg,)
58 if failed_pkg.postinst_failure:
59 msg += " (postinst failed)"
60 diff --git a/lib/_emerge/UseFlagDisplay.py b/lib/_emerge/UseFlagDisplay.py
61 index 5e3ba400d..fffc8144a 100644
62 --- a/lib/_emerge/UseFlagDisplay.py
63 +++ b/lib/_emerge/UseFlagDisplay.py
64 @@ -111,8 +111,6 @@ def pkg_use_display(pkg, opts, modified_use=None):
65 flags.sort(key=UseFlagDisplay.sort_combined)
66 else:
67 flags.sort(key=UseFlagDisplay.sort_separated)
68 - # Use unicode_literals to force unicode format string so
69 - # that UseFlagDisplay.__unicode__() is called in python2.
70 flag_displays.append('%s="%s"' % (varname,
71 ' '.join("%s" % (f,) for f in flags)))
72
73 diff --git a/lib/_emerge/resolver/output.py b/lib/_emerge/resolver/output.py
74 index 0c90abefb..dea8a4be8 100644
75 --- a/lib/_emerge/resolver/output.py
76 +++ b/lib/_emerge/resolver/output.py
77 @@ -554,8 +554,6 @@ class Display:
78 """
79 writemsg_stdout('\n%s\n' % (self.counters,), noiselevel=-1)
80 if show_repos:
81 - # Use unicode_literals to force unicode format string so
82 - # that RepoDisplay.__unicode__() is called in python2.
83 writemsg_stdout("%s" % (self.conf.repo_display,),
84 noiselevel=-1)
85
86 diff --git a/lib/portage/cache/flat_hash.py b/lib/portage/cache/flat_hash.py
87 index 7d48bae81..25930f0a4 100644
88 --- a/lib/portage/cache/flat_hash.py
89 +++ b/lib/portage/cache/flat_hash.py
90 @@ -73,9 +73,6 @@ class database(fs_template.FsBased):
91 v = values.get(k)
92 if not v:
93 continue
94 - # NOTE: This format string requires unicode_literals, so that
95 - # k and v are coerced to unicode, in order to prevent TypeError
96 - # when writing raw bytes to TextIOWrapper with Python 2.
97 myf.write("%s=%s\n" % (k, v))
98
99 self._ensure_access(fp)
100 diff --git a/lib/portage/tests/unicode/test_string_format.py b/lib/portage/tests/unicode/test_string_format.py
101 index 3b994d622..54ac038a6 100644
102 --- a/lib/portage/tests/unicode/test_string_format.py
103 +++ b/lib/portage/tests/unicode/test_string_format.py
104 @@ -15,9 +15,6 @@ class StringFormatTestCase(TestCase):
105 which may be either python2 or python3.
106 """
107
108 - # We need unicode_literals in order to get some unicode test strings
109 - # in a way that works in both python2 and python3.
110 -
111 unicode_strings = (
112 '\u2018',
113 '\u2019',
114 @@ -31,8 +28,6 @@ class StringFormatTestCase(TestCase):
115 arg_bytes = _unicode_encode(arg_unicode, encoding=_encodings['content'])
116 dependency_arg = DependencyArg(arg=arg_unicode)
117
118 - # Use unicode_literals for unicode format string so that
119 - # __unicode__() is called in Python 2.
120 formatted_str = "%s" % (dependency_arg,)
121 self.assertEqual(formatted_str, arg_unicode)
122
123 @@ -48,8 +43,6 @@ class StringFormatTestCase(TestCase):
124 arg_bytes = _unicode_encode(arg_unicode, encoding=_encodings['content'])
125 e = PortageException(arg_unicode)
126
127 - # Use unicode_literals for unicode format string so that
128 - # __unicode__() is called in Python 2.
129 formatted_str = "%s" % (e,)
130 self.assertEqual(formatted_str, arg_unicode)
131
132 @@ -66,8 +59,6 @@ class StringFormatTestCase(TestCase):
133 for arg_unicode in self.unicode_strings:
134 e = UseFlagDisplay(arg_unicode, enabled, forced)
135
136 - # Use unicode_literals for unicode format string so that
137 - # __unicode__() is called in Python 2.
138 formatted_str = "%s" % (e,)
139 self.assertEqual(isinstance(formatted_str, str), True)
140
141 diff --git a/lib/portage/util/digraph.py b/lib/portage/util/digraph.py
142 index c262cddee..623f2d988 100644
143 --- a/lib/portage/util/digraph.py
144 +++ b/lib/portage/util/digraph.py
145 @@ -311,9 +311,6 @@ class digraph:
146 def debug_print(self):
147 def output(s):
148 writemsg(s, noiselevel=-1)
149 - # Use unicode_literals to force unicode format
150 - # strings for python-2.x safety, ensuring that
151 - # node.__unicode__() is used when necessary.
152 for node in self.nodes:
153 output("%s " % (node,))
154 if self.nodes[node][0]:
155 --
156 2.26.2

Replies