Skip to content

Commit

Permalink
Merge pull request #153 from jakkdl/disable_pyi
Browse files Browse the repository at this point in the history
disable the plugin entirely for stub files
  • Loading branch information
sondrelg committed Mar 8, 2023
2 parents 2d2e215 + 9cb3c43 commit bf632c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions flake8_type_checking/plugin.py
Expand Up @@ -88,14 +88,15 @@ def add_options(cls, option_manager: OptionManager) -> None: # pragma: no cover

def run(self) -> Flake8Generator:
"""Run flake8 plugin and return any relevant errors."""
# disable plugin for stub files
# context: https://github.com/snok/flake8-type-checking/issues/152
if self.filename.endswith('.pyi'):
return

visitor = TypingOnlyImportsChecker(self.tree, self.options)

for e in visitor.errors:
code = e[2].split(':')[0]
if self.filename.endswith('.pyi') and code.startswith('TC100'):
# Stub files don't need futures imports
# context: https://github.com/snok/flake8-type-checking/issues/121
continue
if self.should_warn(code):
yield e

Expand Down
13 changes: 13 additions & 0 deletions tests/test_should_warn.py
Expand Up @@ -113,3 +113,16 @@ def test_tc2_works_when_opted_in(flake8_path):
assert result.out_lines == [
f".{os.sep}example.py:7:4: TC200 Annotation 'Union' needs to be made into a string literal"
]


def test_pyi_ignored(flake8_path):
(flake8_path / 'example.pyi').write_text(
dedent(
'''
import pandas
x: pandas.DataFrame
'''
)
)
result = flake8_path.run_flake8()
assert result.out_lines == []

0 comments on commit bf632c7

Please sign in to comment.