Skip to content

[flake8-executable] EXE001 flags ordinary #! comments as shebangs #27028

Description

@ntBre

EXE001 treats an ordinary comment beginning with #! as a shebang even when it appears inside a function and does not specify an interpreter.

# test.py (not executable)
def f():
    #! regular comment
    return 1
$ ruff check --isolated --select EXE001 test.py
EXE001 Shebang is present but file is not executable
 --> test.py:3:5
  |
1 | # test.py (not executable)
2 | def f():
3 |     #! regular comment
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |     return 1
  |

Found 1 error.

This probably applies to other shebang rules too since they all share ShebangDirective::try_extract. I guess I assumed that that would filter out "shebang" lines later in the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions