Skip to content

Commit

Permalink
chore: Run pyupgrade --py36-plus **/*.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jan 6, 2023
1 parent 007bd99 commit ade7de0
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 41 deletions.
2 changes: 1 addition & 1 deletion csvkit/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def join_rows(rows, joiner=' '):
if len(row) == 0:
row = ['']

fixed_row[-1] += "%s%s" % (joiner, row[0])
fixed_row[-1] += "{}{}".format(joiner, row[0])
fixed_row.extend(row[1:])

return fixed_row
Expand Down
2 changes: 1 addition & 1 deletion csvkit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def handler(t, value, traceback):
'flag or with the PYTHONIOENCODING environment variable. Use the -v flag to see '
'the complete error.\n' % self.args.encoding)
else:
sys.stderr.write('%s: %s\n' % (t.__name__, str(value)))
sys.stderr.write('{}: {}\n'.format(t.__name__, str(value)))

sys.excepthook = handler

Expand Down
4 changes: 2 additions & 2 deletions csvkit/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def standardize_patterns(column_names, patterns):
"""
try:
# Dictionary of patterns
patterns = dict((k, pattern_as_function(v)) for k, v in patterns.items() if v)
patterns = {k: pattern_as_function(v) for k, v in patterns.items() if v}
if not column_names:
return patterns
p2 = {}
Expand All @@ -104,7 +104,7 @@ def standardize_patterns(column_names, patterns):
return p2
except AttributeError:
# Sequence of patterns
return dict((i, pattern_as_function(x)) for i, x in enumerate(patterns))
return {i: pattern_as_function(x) for i, x in enumerate(patterns)}


def pattern_as_function(obj):
Expand Down
4 changes: 2 additions & 2 deletions csvkit/utilities/csvgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def main(self):
if self.args.regex:
pattern = re.compile(self.args.regex)
elif self.args.matchfile:
lines = set(line.rstrip() for line in self.args.matchfile)
lines = {line.rstrip() for line in self.args.matchfile}
self.args.matchfile.close()

def pattern(x):
return x in lines
else:
pattern = self.args.pattern

patterns = dict((column_id, pattern) for column_id in column_ids)
patterns = {column_id: pattern for column_id in column_ids}
filter_reader = FilteringCSVReader(rows, header=False, patterns=patterns,
inverse=self.args.inverse, any_match=self.args.any_match)

Expand Down
2 changes: 1 addition & 1 deletion csvkit/utilities/csvpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main(self):

variable = klass(self.input_file, **self.reader_kwargs)

welcome_message = 'Welcome! "%s" has been loaded in an %s object named "%s".' % (
welcome_message = 'Welcome! "{}" has been loaded in an {} object named "{}".'.format(
filename, class_name, variable_name)

try:
Expand Down
2 changes: 1 addition & 1 deletion csvkit/utilities/csvsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _failsafe_main(self):
queries = []
for query in self.args.queries:
if os.path.exists(query):
with open(query, 'r') as f:
with open(query) as f:
query = f.read()
queries += query.split(';')

Expand Down
8 changes: 4 additions & 4 deletions csvkit/utilities/csvstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def print_one(self, table, column_id, operation, label=True, **kwargs):

# Formatting
if op_name == 'freq':
stat = ', '.join([('"%s": %s' % (str(row['value']), row['count'])) for row in stat])
stat = ', '.join([('"{}": {}'.format(str(row['value']), row['count'])) for row in stat])
stat = '{ %s }' % stat

if label:
Expand Down Expand Up @@ -270,7 +270,7 @@ def print_stats(self, table, column_ids, stats):
column = table.columns[column_id]
column_stats = stats[column_id]

self.output_file.write(('%3i. "%s"\n\n' % (column_id + 1, column_name)))
self.output_file.write('%3i. "%s"\n\n' % (column_id + 1, column_name))

for op_name, op_data in OPERATIONS.items():
if column_stats[op_name] is None:
Expand All @@ -284,7 +284,7 @@ def print_stats(self, table, column_ids, stats):
if op_name == 'freq':
for i, row in enumerate(column_stats['freq']):
if i == 0:
self.output_file.write('\t{} '.format(label))
self.output_file.write(f'\t{label} ')
else:
self.output_file.write('\t{label:{label_column_width}} '.format(**{
'label_column_width': label_column_width,
Expand All @@ -310,7 +310,7 @@ def print_stats(self, table, column_ids, stats):
elif op_name == 'len':
v = '%s characters' % v

self.output_file.write('\t{} {}\n'.format(label, v))
self.output_file.write(f'\t{label} {v}\n')

self.output_file.write('\n')

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# csvkit documentation build configuration file, created by
# sphinx-quickstart on Fri Apr 15 21:52:09 2011.
Expand Down
18 changes: 9 additions & 9 deletions tests/test_convert/test_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class TestFixed(CSVKitTestCase):
Utility = In2CSV

def test_fixed(self):
with open('examples/testfixed', 'r') as f:
with open('examples/testfixed_schema.csv', 'r') as schema:
with open('examples/testfixed') as f:
with open('examples/testfixed_schema.csv') as schema:
output = fixed.fixed2csv(f, schema)

with open('examples/testfixed_converted.csv', 'r') as f:
with open('examples/testfixed_converted.csv') as f:
self.assertEqual(f.read(), output)

def test_fixed_skip_lines(self):
with open('examples/testfixed_skip_lines', 'r') as f:
with open('examples/testfixed_schema.csv', 'r') as schema:
with open('examples/testfixed_skip_lines') as f:
with open('examples/testfixed_schema.csv') as schema:
output = fixed.fixed2csv(f, schema, skip_lines=3)

with open('examples/testfixed_converted.csv', 'r') as f:
with open('examples/testfixed_converted.csv') as f:
self.assertEqual(f.read(), output)

def test_fixed_no_inference(self):
Expand All @@ -39,14 +39,14 @@ def test_fixed_no_inference(self):
input_file.close()

def test_fixed_streaming(self):
with open('examples/testfixed', 'r') as f:
with open('examples/testfixed_schema.csv', 'r') as schema:
with open('examples/testfixed') as f:
with open('examples/testfixed_schema.csv') as schema:
output_file = StringIO()
fixed.fixed2csv(f, schema, output=output_file)
output = output_file.getvalue()
output_file.close()

with open('examples/testfixed_converted.csv', 'r') as f:
with open('examples/testfixed_converted.csv') as f:
self.assertEqual(f.read(), output)

def test_schema_decoder_init(self):
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvclean.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvcut.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from unittest.mock import patch
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvformat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from io import StringIO
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvgrep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from unittest.mock import patch
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvjson.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import sys
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvlook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from io import StringIO
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvsort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from io import StringIO
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities/test_csvsql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
Expand Down
19 changes: 9 additions & 10 deletions tests/test_utilities/test_in2csv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
Expand All @@ -17,7 +16,7 @@ class TestIn2CSV(CSVKitTestCase, EmptyFileTests):
def assertConverted(self, input_format, input_filename, output_filename, additional_args=[]):
output = self.get_output(['-f', input_format, input_filename] + additional_args)

with open(output_filename, 'r') as f:
with open(output_filename) as f:
self.assertEqual(output, f.read())

def test_launch_new_instance(self):
Expand Down Expand Up @@ -213,11 +212,11 @@ def test_convert_xls_with_write_sheets(self):
try:
self.assertConverted('xls', 'examples/sheets.xls', 'examples/testxls_converted.csv',
['--sheet', 'data', '--write-sheets', "ʤ,1"])
with open('examples/sheets_0.csv', 'r') as f:
with open('examples/testxls_unicode_converted.csv', 'r') as g:
with open('examples/sheets_0.csv') as f:
with open('examples/testxls_unicode_converted.csv') as g:
self.assertEqual(f.read(), g.read())
with open('examples/sheets_1.csv', 'r') as f:
with open('examples/testxls_converted.csv', 'r') as g:
with open('examples/sheets_1.csv') as f:
with open('examples/testxls_converted.csv') as g:
self.assertEqual(f.read(), g.read())
self.assertFalse(os.path.exists('examples/sheets_2.csv'))
finally:
Expand All @@ -230,11 +229,11 @@ def test_convert_xlsx_with_write_sheets(self):
try:
self.assertConverted('xlsx', 'examples/sheets.xlsx', 'examples/testxlsx_noinference_converted.csv',
['--no-inference', '--sheet', 'data', '--write-sheets', "ʤ,1"])
with open('examples/sheets_0.csv', 'r') as f:
with open('examples/testxlsx_unicode_converted.csv', 'r') as g:
with open('examples/sheets_0.csv') as f:
with open('examples/testxlsx_unicode_converted.csv') as g:
self.assertEqual(f.read(), g.read())
with open('examples/sheets_1.csv', 'r') as f:
with open('examples/testxlsx_noinference_converted.csv', 'r') as g:
with open('examples/sheets_1.csv') as f:
with open('examples/testxlsx_noinference_converted.csv') as g:
self.assertEqual(f.read(), g.read())
self.assertFalse(os.path.exists('examples/sheets_2.csv'))
finally:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utilities/test_sql2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def csvsql(self, csv_file, db=None):
utility = CSVSQL(args)
utility.run()

with open(csv_file, 'r') as f:
with open(csv_file) as f:
text = f.read()

return text.strip()
Expand Down

0 comments on commit ade7de0

Please sign in to comment.