Merge ~cjwatson/lazr.config:drop-py2 into lazr.config:main

Proposed by Colin Watson
Status: Merged
Merged at revision: e5cd66ae708ad90f3fc51ca405bd6aae52366758
Proposed branch: ~cjwatson/lazr.config:drop-py2
Merge into: lazr.config:main
Diff against target: 308 lines (+27/-50)
11 files modified
.pre-commit-config.yaml (+4/-0)
NEWS.rst (+3/-3)
pyproject.toml (+1/-0)
setup.py (+1/-1)
src/lazr/config/_config.py (+15/-25)
src/lazr/config/_version.py (+1/-1)
src/lazr/config/docs/conf.py (+0/-2)
src/lazr/config/interfaces.py (+1/-4)
src/lazr/config/tests/test_config.py (+0/-3)
src/lazr/config/tests/test_docs.py (+1/-10)
tox.ini (+0/-1)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+437444@code.launchpad.net

Commit message

Drop Python 2 support

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
2index 6382dc7..4753587 100644
3--- a/.pre-commit-config.yaml
4+++ b/.pre-commit-config.yaml
5@@ -18,6 +18,10 @@ repos:
6 - id: black
7 # skip namespace package declaration
8 exclude: ^src/lazr/__init__\.py$
9+- repo: https://github.com/asottile/pyupgrade
10+ rev: v3.3.1
11+ hooks:
12+ - id: pyupgrade
13 - repo: https://github.com/PyCQA/isort
14 rev: 5.12.0
15 hooks:
16diff --git a/NEWS.rst b/NEWS.rst
17index d298c85..ea61f16 100644
18--- a/NEWS.rst
19+++ b/NEWS.rst
20@@ -2,14 +2,14 @@
21 NEWS for lazr.config
22 ====================
23
24-2.2.4
25-=====
26+3.0
27+===
28 - Add basic pre-commit configuration.
29 - Publish Documentation on Read the Docs.
30 - Apply inclusive naming via the woke pre-commit hook.
31 - Test using ``zope.testrunner`` rather than ``nose``.
32 - Officially add support for Python 3.9 and 3.10.
33-- Drop support for Python 2.6 and 3.4.
34+- Drop support for Python 2.6, 2.7, and 3.4.
35 - Apply ``black`` and ``isort``.
36
37 2.2.3 (2021-01-26)
38diff --git a/pyproject.toml b/pyproject.toml
39index a8f43fe..1eb96ee 100644
40--- a/pyproject.toml
41+++ b/pyproject.toml
42@@ -1,2 +1,3 @@
43 [tool.black]
44 line-length = 79
45+target-version = ["py35"]
46diff --git a/setup.py b/setup.py
47index 5448a20..f5a5da9 100755
48--- a/setup.py
49+++ b/setup.py
50@@ -61,7 +61,6 @@ files. The format supports schema validation.
51 "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", # noqa
52 "Operating System :: OS Independent",
53 "Programming Language :: Python",
54- "Programming Language :: Python :: 2.7",
55 "Programming Language :: Python :: 3",
56 "Programming Language :: Python :: 3.5",
57 "Programming Language :: Python :: 3.6",
58@@ -73,4 +72,5 @@ files. The format supports schema validation.
59 extras_require=dict(
60 docs=["Sphinx"],
61 ),
62+ python_requires=">=3.5",
63 )
64diff --git a/src/lazr/config/_config.py b/src/lazr/config/_config.py
65index 0f12bf7..b8a56a7 100644
66--- a/src/lazr/config/_config.py
67+++ b/src/lazr/config/_config.py
68@@ -16,9 +16,6 @@
69
70 """Implementation classes for config."""
71
72-from __future__ import absolute_import, print_function, unicode_literals
73-
74-__metaclass__ = type
75 __all__ = [
76 "Config",
77 "ConfigData",
78@@ -41,7 +38,6 @@ import logging
79 import os
80 import pwd
81 import re
82-import sys
83 from os.path import abspath, basename, dirname
84 from textwrap import dedent
85
86@@ -86,7 +82,7 @@ _missing = object()
87
88 def read_content(filename):
89 """Return the content of a file at filename as a string."""
90- with open(filename, "rt") as fp:
91+ with open(filename) as fp:
92 return fp.read()
93
94
95@@ -111,8 +107,7 @@ class SectionSchema:
96
97 def __iter__(self):
98 """See `ISectionSchema`"""
99- for key in self._options.keys():
100- yield key
101+ yield from self._options.keys()
102
103 def __contains__(self, name):
104 """See `ISectionSchema`"""
105@@ -150,7 +145,7 @@ class Section:
106 # Use __dict__ because __getattr__ limits access to self.options.
107 self.__dict__["schema"] = schema
108 if _options is None:
109- _options = dict((key, schema[key]) for key in schema)
110+ _options = {key: schema[key] for key in schema}
111 self.__dict__["_options"] = _options
112
113 def __getitem__(self, key):
114@@ -184,7 +179,7 @@ class Section:
115 if key in self._options:
116 self._options[key] = value
117 else:
118- msg = "%s does not have a %s key." % (self.name, key)
119+ msg = "{} does not have a {} key.".format(self.name, key)
120 errors.append(UnknownKeyError(msg))
121 return errors
122
123@@ -240,12 +235,12 @@ class ImplicitTypeSection(Section):
124
125 def __getitem__(self, key):
126 """See `ISection`."""
127- value = super(ImplicitTypeSection, self).__getitem__(key)
128+ value = super().__getitem__(key)
129 return self._convert(value)
130
131 def __getattr__(self, name):
132 """See `ISection`."""
133- value = super(ImplicitTypeSection, self).__getattr__(name)
134+ value = super().__getattr__(name)
135 return self._convert(value)
136
137
138@@ -396,8 +391,7 @@ class ConfigSchema:
139
140 def __iter__(self):
141 """See `IConfigSchema`."""
142- for value in self._section_schemas.values():
143- yield value
144+ yield from self._section_schemas.values()
145
146 def __contains__(self, name):
147 """See `IConfigSchema`."""
148@@ -500,8 +494,7 @@ class ConfigData:
149
150 def __iter__(self):
151 """See `IConfigData`."""
152- for value in self._sections.values():
153- yield value
154+ yield from self._sections.values()
155
156 def __contains__(self, name):
157 """See `IConfigData`."""
158@@ -618,16 +611,13 @@ class Config:
159 # option and in Python 3.2, this argument changed its default from
160 # False to True. This breaks behavior compatibility with Python 2, so
161 # under Python 3, always force strict=False.
162- kws = {}
163- if sys.version_info >= (3,):
164- kws["strict"] = False
165- parser = RawConfigParser(**kws)
166+ parser = RawConfigParser(strict=False)
167 _parser_read_file(parser, StringIO(conf_data), conf_filename)
168 confs.append((conf_filename, parser, encoding_errors))
169 if parser.has_option("meta", "extends"):
170 base_path = dirname(conf_filename)
171 extends_name = parser.get("meta", "extends")
172- extends_filename = abspath("%s/%s" % (base_path, extends_name))
173+ extends_filename = abspath("{}/{}".format(base_path, extends_name))
174 extends_data = read_content(extends_filename)
175 self._getExtendedConfs(extends_filename, extends_data, confs)
176 return confs
177@@ -676,7 +666,7 @@ class Config:
178 and master_name not in self.schema
179 ):
180 # Any section not in the the schema is an error.
181- msg = "%s does not have a %s section." % (
182+ msg = "{} does not have a {} section.".format(
183 self.schema.name,
184 section_name,
185 )
186@@ -784,7 +774,7 @@ class Category:
187
188 def __getattr__(self, name):
189 """See `ICategory`."""
190- full_name = "%s.%s" % (self.name, name)
191+ full_name = "{}.{}".format(self.name, name)
192 if full_name in self._sections:
193 return self._sections[full_name]
194 raise AttributeError("No section named %s." % name)
195@@ -872,10 +862,10 @@ def as_timedelta(value):
196 # Complain if the components are out of order.
197 if "".join(components) != value:
198 raise ValueError
199- keywords = dict(
200- (interval[0].lower(), interval)
201+ keywords = {
202+ interval[0].lower(): interval
203 for interval in ("weeks", "days", "hours", "minutes", "seconds")
204- )
205+ }
206 keyword_arguments = {}
207 for interval in components:
208 if len(interval) == 0:
209diff --git a/src/lazr/config/_version.py b/src/lazr/config/_version.py
210index f394e69..ecd0eec 100644
211--- a/src/lazr/config/_version.py
212+++ b/src/lazr/config/_version.py
213@@ -1 +1 @@
214-__version__ = "2.2.3"
215+__version__ = "3.0.dev0"
216diff --git a/src/lazr/config/docs/conf.py b/src/lazr/config/docs/conf.py
217index f9eabe9..160b12a 100644
218--- a/src/lazr/config/docs/conf.py
219+++ b/src/lazr/config/docs/conf.py
220@@ -1,5 +1,3 @@
221-# -*- coding: utf-8 -*-
222-#
223 # lazr.config documentation build configuration file, created by
224 # sphinx-quickstart on Mon Jan 7 10:37:37 2013.
225 #
226diff --git a/src/lazr/config/interfaces.py b/src/lazr/config/interfaces.py
227index 3c6527e..273c7c3 100644
228--- a/src/lazr/config/interfaces.py
229+++ b/src/lazr/config/interfaces.py
230@@ -17,9 +17,6 @@
231 # pylint: disable-msg=E0211,E0213,W0231
232 """Interfaces for process configuration.."""
233
234-from __future__ import absolute_import, print_function, unicode_literals
235-
236-__metaclass__ = type
237 __all__ = [
238 "ConfigErrors",
239 "ConfigSchemaError",
240@@ -90,7 +87,7 @@ class ConfigErrors(ConfigSchemaError):
241 self.errors = errors
242
243 def __str__(self):
244- return "%s: %s" % (self.__class__.__name__, self.message)
245+ return "{}: {}".format(self.__class__.__name__, self.message)
246
247
248 class ISectionSchema(Interface):
249diff --git a/src/lazr/config/tests/test_config.py b/src/lazr/config/tests/test_config.py
250index 723e3e2..8817325 100644
251--- a/src/lazr/config/tests/test_config.py
252+++ b/src/lazr/config/tests/test_config.py
253@@ -16,9 +16,6 @@
254
255 """Tests of lazr.config."""
256
257-from __future__ import absolute_import, print_function, unicode_literals
258-
259-__metaclass__ = type
260 __all__ = [
261 "TestConfig",
262 ]
263diff --git a/src/lazr/config/tests/test_docs.py b/src/lazr/config/tests/test_docs.py
264index 4c17208..698a94d 100644
265--- a/src/lazr/config/tests/test_docs.py
266+++ b/src/lazr/config/tests/test_docs.py
267@@ -16,9 +16,6 @@
268
269 """Test harness for doctests."""
270
271-from __future__ import absolute_import, print_function, unicode_literals
272-
273-__metaclass__ = type
274 __all__ = []
275
276 import atexit
277@@ -49,18 +46,12 @@ def load_tests(loader, tests, pattern):
278 )
279 )
280 atexit.register(cleanup_resources)
281- globs = {
282- "absolute_import": absolute_import,
283- "print_function": print_function,
284- "unicode_literals": unicode_literals,
285- }
286 tests.addTest(
287 doctest.DocFileSuite(
288 *doctest_files,
289 module_relative=False,
290 optionflags=DOCTEST_FLAGS,
291- globs=globs,
292- encoding="UTF-8"
293+ encoding="UTF-8",
294 )
295 )
296 return tests
297diff --git a/tox.ini b/tox.ini
298index 186f2bd..4615990 100644
299--- a/tox.ini
300+++ b/tox.ini
301@@ -1,7 +1,6 @@
302 [tox]
303 envlist =
304 pre-commit
305- py27
306 py35
307 py36
308 py37

Subscribers

People subscribed via source and target branches