Skip to content

Commit d31e0df

Browse files
authored
Apply pyupgrade to project (#2364)
Update patterns to modern Python syntax and features. Drops unnecessary legacy syntax that was required for Python 2 (removed in 9c3db1a). Details on pyupgrade can be found at: https://github.com/asottile/pyupgrade
1 parent a8a5228 commit d31e0df

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

codespell_lib/_codespell.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# This program is free software; you can redistribute it and/or modify
43
# it under the terms of the GNU General Public License as published by
@@ -29,12 +28,12 @@
2928
# autogenerated by setuptools_scm
3029
from ._version import __version__ as VERSION
3130

32-
word_regex_def = u"[\\w\\-'’`]+"
31+
word_regex_def = "[\\w\\-'’`]+"
3332
# While we want to treat characters like ( or " as okay for a starting break,
3433
# these may occur unescaped in URIs, and so we are more restrictive on the
3534
# endpoint. Emails are more restrictive, so the endpoint remains flexible.
36-
uri_regex_def = (u"(\\b(?:https?|[ts]?ftp|file|git|smb)://[^\\s]+(?=$|\\s)|"
37-
u"\\b[\\w.%+-]+@[\\w.-]+\\b)")
35+
uri_regex_def = ("(\\b(?:https?|[ts]?ftp|file|git|smb)://[^\\s]+(?=$|\\s)|"
36+
"\\b[\\w.%+-]+@[\\w.-]+\\b)")
3837
encodings = ('utf-8', 'iso-8859-1')
3938
USAGE = """
4039
\t%prog [OPTIONS] [file1 file2 ... fileN]
@@ -83,7 +82,7 @@
8382
# file1 .. fileN Files to check spelling
8483

8584

86-
class QuietLevels(object):
85+
class QuietLevels:
8786
NONE = 0
8887
ENCODING = 1
8988
BINARY_FILE = 2
@@ -92,7 +91,7 @@ class QuietLevels(object):
9291
FIXES = 16
9392

9493

95-
class GlobMatch(object):
94+
class GlobMatch:
9695
def __init__(self, pattern):
9796
if pattern:
9897
# Pattern might be a list of comma-delimited strings
@@ -111,14 +110,14 @@ def match(self, filename):
111110
return False
112111

113112

114-
class Misspelling(object):
113+
class Misspelling:
115114
def __init__(self, data, fix, reason):
116115
self.data = data
117116
self.fix = fix
118117
self.reason = reason
119118

120119

121-
class TermColors(object):
120+
class TermColors:
122121
def __init__(self):
123122
self.FILE = '\033[33m'
124123
self.WWORD = '\033[31m'
@@ -132,7 +131,7 @@ def disable(self):
132131
self.DISABLE = ''
133132

134133

135-
class Summary(object):
134+
class Summary:
136135
def __init__(self):
137136
self.summary = {}
138137

@@ -152,7 +151,7 @@ def __str__(self):
152151
width=15 - len(key)) for key in keys])
153152

154153

155-
class FileOpener(object):
154+
class FileOpener:
156155
def __init__(self, use_chardet, quiet_level):
157156
self.use_chardet = use_chardet
158157
if use_chardet:

codespell_lib/tests/test_basic.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import contextlib
42
import inspect
53
import os
@@ -22,7 +20,7 @@ def test_constants():
2220
assert EX_DATAERR == 65
2321

2422

25-
class MainWrapper(object):
23+
class MainWrapper:
2624
"""Compatibility wrapper for when we used to return the count."""
2725

2826
def main(self, *args, count=True, std=False, **kwargs):
@@ -174,7 +172,7 @@ def test_interactivity(tmpdir, capsys):
174172
with FakeStdin('0\n'): # blank input -> nothing
175173
assert cs.main('-w', '-i', '3', f.name) == 0
176174
assert cs.main(f.name) == 0
177-
with open(f.name, 'r') as f_read:
175+
with open(f.name) as f_read:
178176
assert f_read.read() == 'awkward\n'
179177
with open(f.name, 'w') as f:
180178
f.write('ackward\n')
@@ -184,7 +182,7 @@ def test_interactivity(tmpdir, capsys):
184182
assert code == 0
185183
assert 'a valid option' in stdout
186184
assert cs.main(f.name) == 0
187-
with open(f.name, 'r') as f:
185+
with open(f.name) as f:
188186
assert f.read() == 'backward\n'
189187
finally:
190188
os.remove(f.name)
@@ -249,11 +247,11 @@ def test_exclude_file(tmpdir, capsys):
249247
"""Test exclude file functionality."""
250248
d = str(tmpdir)
251249
with open(op.join(d, 'bad.txt'), 'wb') as f:
252-
f.write('1 abandonned 1\n2 abandonned 2\n'.encode('utf-8'))
250+
f.write(b'1 abandonned 1\n2 abandonned 2\n')
253251
bad_name = f.name
254252
assert cs.main(bad_name) == 2
255253
with open(op.join(d, 'tmp.txt'), 'wb') as f:
256-
f.write('1 abandonned 1\n'.encode('utf-8'))
254+
f.write(b'1 abandonned 1\n')
257255
assert cs.main(bad_name) == 2
258256
assert cs.main('-x', f.name, bad_name) == 1
259257

@@ -266,11 +264,11 @@ def test_encoding(tmpdir, capsys):
266264
# with CaptureStdout() as sio:
267265
assert cs.main(f.name) == 0
268266
with open(f.name, 'wb') as f:
269-
f.write(u'naïve\n'.encode('utf-8'))
267+
f.write('naïve\n'.encode())
270268
assert cs.main(f.name) == 0
271269
assert cs.main('-e', f.name) == 0
272270
with open(f.name, 'ab') as f:
273-
f.write(u'naieve\n'.encode('utf-8'))
271+
f.write(b'naieve\n')
274272
assert cs.main(f.name) == 1
275273
# Encoding detection (only try ISO 8859-1 because UTF-8 is the default)
276274
with open(f.name, 'wb') as f:
@@ -395,7 +393,7 @@ def test_case_handling(tmpdir, capsys):
395393
# with CaptureStdout() as sio:
396394
assert cs.main(f.name) == 0
397395
with open(f.name, 'wb') as f:
398-
f.write('this has an ACII error'.encode('utf-8'))
396+
f.write(b'this has an ACII error')
399397
code, stdout, _ = cs.main(f.name, std=True)
400398
assert code == 1
401399
assert 'ASCII' in stdout

codespell_lib/tests/test_dictionary.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import glob
42
import os.path as op
53
import os
@@ -41,9 +39,9 @@
4139

4240
def test_dictionaries_exist():
4341
"""Test consistency of dictionaries."""
44-
doc_fnames = set(op.basename(f[0]) for f in _fnames_in_aspell)
45-
got_fnames = set(op.basename(f)
46-
for f in glob.glob(op.join(_data_dir, '*.txt')))
42+
doc_fnames = {op.basename(f[0]) for f in _fnames_in_aspell}
43+
got_fnames = {op.basename(f)
44+
for f in glob.glob(op.join(_data_dir, '*.txt'))}
4745
assert doc_fnames == got_fnames
4846

4947

0 commit comments

Comments
 (0)