diff --git a/src/unasync/__init__.py b/src/unasync/__init__.py index c7ece45..872a1ff 100644 --- a/src/unasync/__init__.py +++ b/src/unasync/__init__.py @@ -83,15 +83,19 @@ def _unasync_tokenize(self, contents, filename): comment_lines_locations = [] for token in tokens: # find line numbers where "unasync: remove" comments are found - if token.name == 'COMMENT' and 'unasync: remove' in token.src: # XXX: maybe make this a little more strict + if ( + token.name == "COMMENT" and "unasync: remove" in token.src + ): # XXX: maybe make this a little more strict comment_lines_locations.append(token.line) lines_to_remove = set() - if comment_lines_locations: # only parse ast if we actually have "unasync: remove" comments + if ( + comment_lines_locations + ): # only parse ast if we actually have "unasync: remove" comments tree = ast.parse(contents, filename=filename) for node in ast.walk(tree): # find nodes whose line number (start line) intersect with unasync: remove comments - if hasattr(node, 'lineno') and node.lineno in comment_lines_locations: + if hasattr(node, "lineno") and node.lineno in comment_lines_locations: for lineno in range(node.lineno, node.end_lineno + 1): # find all lines related to each node and mark those lines for removal lines_to_remove.add(lineno) diff --git a/tests/data/async/removals.py b/tests/data/async/removals.py index 6d88118..5640722 100644 --- a/tests/data/async/removals.py +++ b/tests/data/async/removals.py @@ -1,3 +1,5 @@ +# isort: skip_file +# fmt: off from common import ( a, b , c # these should stick around ) @@ -34,3 +36,4 @@ async def another_method(self): print('This line should stick around') await self.something("the content in this line should be removed") # unasync: remove +# fmt: on diff --git a/tests/data/sync/removals.py b/tests/data/sync/removals.py index e923281..260a79f 100644 --- a/tests/data/sync/removals.py +++ b/tests/data/sync/removals.py @@ -1,3 +1,5 @@ +# isort: skip_file +# fmt: off from common import ( a, b , c # these should stick around ) @@ -21,3 +23,4 @@ def foobar(self): def another_method(self): print('This line should stick around') +# fmt: on diff --git a/tests/test_unasync.py b/tests/test_unasync.py index 35e0c6c..6b02adc 100644 --- a/tests/test_unasync.py +++ b/tests/test_unasync.py @@ -35,7 +35,6 @@ def test_rule_on_short_path(): @pytest.mark.parametrize("source_file", TEST_FILES) def test_unasync(tmpdir, source_file): - rule = unasync.Rule(fromdir=ASYNC_DIR, todir=str(tmpdir)) rule._unasync_file(os.path.join(ASYNC_DIR, source_file)) @@ -64,7 +63,6 @@ def test_unasync_files(tmpdir): def test_build_py_modules(tmpdir): - source_modules_dir = os.path.join(TEST_DIR, "example_mod") mod_dir = str(tmpdir) + "/" + "example_mod" shutil.copytree(source_modules_dir, mod_dir) @@ -84,7 +82,6 @@ def test_build_py_modules(tmpdir): def test_build_py_packages(tmpdir): - source_pkg_dir = os.path.join(TEST_DIR, "example_pkg") pkg_dir = str(tmpdir) + "/" + "example_pkg" shutil.copytree(source_pkg_dir, pkg_dir) @@ -101,7 +98,6 @@ def test_build_py_packages(tmpdir): def test_project_structure_after_build_py_packages(tmpdir): - source_pkg_dir = os.path.join(TEST_DIR, "example_pkg") pkg_dir = str(tmpdir) + "/" + "example_pkg" shutil.copytree(source_pkg_dir, pkg_dir) @@ -121,7 +117,6 @@ def test_project_structure_after_build_py_packages(tmpdir): def test_project_structure_after_customized_build_py_packages(tmpdir): - source_pkg_dir = os.path.join(TEST_DIR, "example_custom_pkg") pkg_dir = str(tmpdir) + "/" + "example_custom_pkg" shutil.copytree(source_pkg_dir, pkg_dir)