Skip to content

Commit

Permalink
Merge pull request #87 from dalcinl/patch-1
Browse files Browse the repository at this point in the history
do not emit unused warning for variables named `unused*`
  • Loading branch information
MarcoGorelli authored Nov 26, 2023
2 parents c0a33b2 + e7ed425 commit 7b645c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions cython_lint/cython_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def visit_funcdef(
and _def[0] != func_name
and _def[0] not in [i[0] for i in args]
and not _def[0].startswith('_')
and not _def[0].startswith('unused')
and _def[0] not in global_names
):

Expand Down
37 changes: 37 additions & 0 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@
INCLUDE_FILE_1 = os.path.join('tests', 'data', 'bar.pxi')


@pytest.mark.parametrize(
'src',
[
(
'cdef bint foo():\n'
' cdef int _\n'
' cdef int _a\n'
' cdef int unused\n'
' cdef int unused_a\n'
),
(
'cdef bint foo():\n'
' cdef int _ = 1\n'
' cdef int _a = 1\n'
' cdef int unused = 1\n'
' cdef int unused_a = 1\n'
),
(
'cdef bint foo():\n'
' cdef int _\n'
' cdef int _a\n'
' cdef int unused\n'
' cdef int unused_a\n'
' _ = 1\n'
' _a = 1\n'
' unused = 1\n'
' unused_a = 1\n'
),
],
)
def test_named_unused(capsys: Any, src: str) -> None:
ret = _main(src, 't.py', ext='.pyx', no_pycodestyle=True)
out, _ = capsys.readouterr()
assert out == ''
assert ret == 0


@pytest.mark.parametrize(
'src, expected',
[
Expand Down

0 comments on commit 7b645c8

Please sign in to comment.