diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2020-12-20 20:19:49 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-03 06:26:21 -0500 |
commit | 7ff93a9740da5dec4eba6c6cad288d25a472d75a (patch) | |
tree | b81243f1508e4727dc28094c48be84ac6ae07706 | |
parent | 12c5fcd57fd1cce3bc3563732f5502f5e943c0e0 (diff) | |
download | python-coveragepy-git-7ff93a9740da5dec4eba6c6cad288d25a472d75a.tar.gz |
Use set literals
-rw-r--r-- | coverage/collector.py | 2 | ||||
-rw-r--r-- | coverage/html.py | 2 | ||||
-rw-r--r-- | coverage/misc.py | 2 | ||||
-rw-r--r-- | coverage/parser.py | 18 | ||||
-rw-r--r-- | coverage/phystokens.py | 2 | ||||
-rw-r--r-- | coverage/sqldata.py | 4 | ||||
-rw-r--r-- | tests/plugin1.py | 2 | ||||
-rw-r--r-- | tests/test_collector.py | 2 | ||||
-rw-r--r-- | tests/test_parser.py | 12 | ||||
-rw-r--r-- | tests/test_plugins.py | 6 | ||||
-rw-r--r-- | tests/test_results.py | 6 | ||||
-rw-r--r-- | tests/test_testing.py | 6 |
12 files changed, 32 insertions, 32 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 9333d66a..a4f1790d 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -55,7 +55,7 @@ class Collector(object): _collectors = [] # The concurrency settings we support here. - SUPPORTED_CONCURRENCIES = set(["greenlet", "eventlet", "gevent", "thread"]) + SUPPORTED_CONCURRENCIES = {"greenlet", "eventlet", "gevent", "thread"} def __init__( self, should_trace, check_include, should_start_context, file_mapper, diff --git a/coverage/html.py b/coverage/html.py index 247d2ae1..ef50b56b 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -84,7 +84,7 @@ class HtmlDataGeneration(object): data = self.coverage.get_data() self.has_arcs = data.has_arcs() if self.config.show_contexts: - if data.measured_contexts() == set([""]): + if data.measured_contexts() == {""}: self.coverage._warn("No contexts were measured") data.set_query_contexts(self.config.report_contexts) diff --git a/coverage/misc.py b/coverage/misc.py index 5c4381ab..96573f7a 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -77,7 +77,7 @@ if USE_CONTRACTS: def one_of(argnames): """Ensure that only one of the argnames is non-None.""" def _decorator(func): - argnameset = set(name.strip() for name in argnames.split(",")) + argnameset = {name.strip() for name in argnames.split(",")} def _wrapper(*args, **kwargs): vals = [kwargs.get(name) for name in argnameset] assert sum(val is not None for val in vals) == 1 diff --git a/coverage/parser.py b/coverage/parser.py index e3e43149..f5a8ddd9 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -220,7 +220,7 @@ class PythonParser(object): Returns a set of the first lines. """ - return set(self.first_line(l) for l in lines) + return {self.first_line(l) for l in lines} def translate_lines(self, lines): """Implement `FileReporter.translate_lines`.""" @@ -520,7 +520,7 @@ class AstArcAnalyzer(object): def __init__(self, text, statements, multiline): self.root_node = ast.parse(neuter_encoding_declaration(text)) # TODO: I think this is happening in too many places. - self.statements = set(multiline.get(l, l) for l in statements) + self.statements = {multiline.get(l, l) for l in statements} self.multiline = multiline if AST_DUMP: # pragma: debugging @@ -626,10 +626,10 @@ class AstArcAnalyzer(object): return 1 # The node types that just flow to the next node with no complications. - OK_TO_DEFAULT = set([ + OK_TO_DEFAULT = { "Assign", "Assert", "AugAssign", "Delete", "Exec", "Expr", "Global", "Import", "ImportFrom", "Nonlocal", "Pass", "Print", - ]) + } @contract(returns='ArcStarts') def add_arcs(self, node): @@ -661,7 +661,7 @@ class AstArcAnalyzer(object): print("*** Unhandled: {}".format(node)) # Default for simple statements: one exit from this node. - return set([ArcStart(self.line_for_node(node))]) + return {ArcStart(self.line_for_node(node))} @one_of("from_start, prev_starts") @contract(returns='ArcStarts') @@ -677,7 +677,7 @@ class AstArcAnalyzer(object): """ if prev_starts is None: - prev_starts = set([from_start]) + prev_starts = {from_start} for body_node in body: lineno = self.line_for_node(body_node) first_line = self.multiline.get(lineno, lineno) @@ -890,7 +890,7 @@ class AstArcAnalyzer(object): self.add_arc(last, lineno) last = lineno # The body is handled in collect_arcs. - return set([ArcStart(last)]) + return {ArcStart(last)} _handle__ClassDef = _handle_decorated @@ -984,7 +984,7 @@ class AstArcAnalyzer(object): # If there are `except` clauses, then raises in the try body # will already jump to them. Start this set over for raises in # `except` and `else`. - try_block.raise_from = set([]) + try_block.raise_from = set() else: self.block_stack.pop() @@ -1079,7 +1079,7 @@ class AstArcAnalyzer(object): if start.cause is not None: causes.append(start.cause.format(lineno=start.lineno)) cause = " or ".join(causes) - exits = set(ArcStart(xit.lineno, cause) for xit in exits) + exits = {ArcStart(xit.lineno, cause) for xit in exits} return exits @contract(returns='ArcStarts') diff --git a/coverage/phystokens.py b/coverage/phystokens.py index b6866e7d..54378b3b 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -87,7 +87,7 @@ def source_token_lines(source): """ - ws_tokens = set([token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL]) + ws_tokens = {token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL} line = [] col = 0 diff --git a/coverage/sqldata.py b/coverage/sqldata.py index 7a3b5c79..b28b83b4 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -784,7 +784,7 @@ class CoverageData(SimpleReprMixin): """ self._start_using() with self._connect() as con: - contexts = set(row[0] for row in con.execute("select distinct(context) from context")) + contexts = {row[0] for row in con.execute("select distinct(context) from context")} return contexts def file_tracer(self, filename): @@ -857,7 +857,7 @@ class CoverageData(SimpleReprMixin): arcs = self.arcs(filename) if arcs is not None: all_lines = itertools.chain.from_iterable(arcs) - return list(set(l for l in all_lines if l > 0)) + return list({l for l in all_lines if l > 0}) with self._connect() as con: file_id = self._file_id(filename) diff --git a/tests/plugin1.py b/tests/plugin1.py index a070af36..3283fbda 100644 --- a/tests/plugin1.py +++ b/tests/plugin1.py @@ -44,7 +44,7 @@ class FileTracer(coverage.FileTracer): class FileReporter(coverage.FileReporter): """Dead-simple FileReporter.""" def lines(self): - return set([105, 106, 107, 205, 206, 207]) + return {105, 106, 107, 205, 206, 207} def coverage_init(reg, options): # pylint: disable=unused-argument diff --git a/tests/test_collector.py b/tests/test_collector.py index 9989b229..f7e8a4c4 100644 --- a/tests/test_collector.py +++ b/tests/test_collector.py @@ -45,6 +45,6 @@ class CollectorTest(CoverageTest): self.start_import_stop(cov, "f2") # Double-check that our files were checked. - abs_files = set(os.path.abspath(f) for f in should_trace_hook.filenames) + abs_files = {os.path.abspath(f) for f in should_trace_hook.filenames} self.assertIn(os.path.abspath("f1.py"), abs_files) self.assertIn(os.path.abspath("f2.py"), abs_files) diff --git a/tests/test_parser.py b/tests/test_parser.py index 0e6a0859..5fb3bc1f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -171,11 +171,11 @@ class PythonParserTest(CoverageTest): def func(x=25): return 26 """) - raw_statements = set([3, 4, 5, 6, 8, 9, 10, 13, 15, 16, 17, 20, 22, 23, 25, 26]) + raw_statements = {3, 4, 5, 6, 8, 9, 10, 13, 15, 16, 17, 20, 22, 23, 25, 26} if env.PYBEHAVIOR.trace_decorated_def: raw_statements.update([11, 19]) self.assertEqual(parser.raw_statements, raw_statements) - self.assertEqual(parser.statements, set([8])) + self.assertEqual(parser.statements, {8}) def test_class_decorator_pragmas(self): parser = self.parse_source("""\ @@ -188,8 +188,8 @@ class PythonParserTest(CoverageTest): def __init__(self): self.x = 8 """) - self.assertEqual(parser.raw_statements, set([1, 2, 3, 5, 6, 7, 8])) - self.assertEqual(parser.statements, set([1, 2, 3])) + self.assertEqual(parser.raw_statements, {1, 2, 3, 5, 6, 7, 8}) + self.assertEqual(parser.statements, {1, 2, 3}) def test_empty_decorated_function(self): parser = self.parse_source("""\ @@ -463,7 +463,7 @@ class ParserFileTest(CoverageTest): """) parser = self.parse_file("normal.py") - self.assertEqual(parser.statements, set([1])) + self.assertEqual(parser.statements, {1}) self.make_file("abrupt.py", """\ out, err = subprocess.Popen( @@ -476,4 +476,4 @@ class ParserFileTest(CoverageTest): self.assertEqual(f.read()[-1], ")") parser = self.parse_file("abrupt.py") - self.assertEqual(parser.statements, set([1])) + self.assertEqual(parser.statements, {1}) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index d14f5c47..1f224695 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -400,12 +400,12 @@ class GoodFileTracerTest(FileTracerTest): # have 7 lines in it. If render() was called with line number 4, # then the plugin will claim that lines 4 and 5 were executed. analysis = cov._analyze("foo_7.html") - self.assertEqual(analysis.statements, set([1, 2, 3, 4, 5, 6, 7])) + self.assertEqual(analysis.statements, {1, 2, 3, 4, 5, 6, 7}) # Plugins don't do branch coverage yet. self.assertEqual(analysis.has_arcs(), True) self.assertEqual(analysis.arc_possibilities(), []) - self.assertEqual(analysis.missing, set([1, 2, 3, 6, 7])) + self.assertEqual(analysis.missing, {1, 2, 3, 6, 7}) def test_plugin2_with_text_report(self): self.make_render_and_caller() @@ -553,7 +553,7 @@ class GoodFileTracerTest(FileTracerTest): class MyReporter(coverage.FileReporter): def lines(self): - return set([99, 999, 9999]) + return {99, 999, 9999} def coverage_init(reg, options): reg.add_file_tracer(Plugin()) diff --git a/tests/test_results.py b/tests/test_results.py index 86806cfd..377c150b 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -114,7 +114,7 @@ def test_should_fail_under_invalid_value(): @pytest.mark.parametrize("statements, lines, result", [ - (set([1,2,3,4,5,10,11,12,13,14]), set([1,2,5,10,11,13,14]), "1-2, 5-11, 13-14"), + ({1,2,3,4,5,10,11,12,13,14}, {1,2,5,10,11,13,14}, "1-2, 5-11, 13-14"), ([1,2,3,4,5,10,11,12,13,14,98,99], [1,2,5,10,11,13,14,99], "1-2, 5-11, 13-14, 99"), ([1,2,3,4,98,99,100,101,102,103,104], [1,2,99,102,103,104], "1-2, 99, 102-104"), ([17], [17], "17"), @@ -128,8 +128,8 @@ def test_format_lines(statements, lines, result): @pytest.mark.parametrize("statements, lines, arcs, result", [ ( - set([1,2,3,4,5,10,11,12,13,14]), - set([1,2,5,10,11,13,14]), + {1,2,3,4,5,10,11,12,13,14}, + {1,2,5,10,11,13,14}, (), "1-2, 5-11, 13-14" ), diff --git a/tests/test_testing.py b/tests/test_testing.py index 2fda956b..c5d46430 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -33,11 +33,11 @@ class TestingTest(TestCase): def test_assert_count_equal(self): self.assertCountEqual(set(), set()) - self.assertCountEqual(set([1,2,3]), set([3,1,2])) + self.assertCountEqual({1,2,3}, {3,1,2}) with self.assertRaises(AssertionError): - self.assertCountEqual(set([1,2,3]), set()) + self.assertCountEqual({1,2,3}, set()) with self.assertRaises(AssertionError): - self.assertCountEqual(set([1,2,3]), set([4,5,6])) + self.assertCountEqual({1,2,3}, {4,5,6}) class CoverageTestTest(CoverageTest): |