Skip to content

Commit

Permalink
Merge pull request #98 from wyuenho/fix-96
Browse files Browse the repository at this point in the history
Fix #96 none handling for select and extend-select
  • Loading branch information
sondrelg committed Jul 13, 2022
2 parents b4bfe9a + 3e454d2 commit 9bcbefe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions flake8_type_checking/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ def should_warn(self, code: str) -> bool:
logger.info('Options not provided to flake8-type-checking, optional warning %s selected.', code)
return False

selected_rules = tuple(
list(self.options.select or [])
+ list(self.options.extended_default_select or [])
+ list(self.options.extend_select or [])
+ list(self.options.enable_extensions or []),
)

for i in range(3, len(code) + 1):
if code[:i] in (
self.options.select
+ list(self.options.extended_default_select)
+ (self.options.enable_extensions or [])
):
if code[:i] in selected_rules:
# Warn if opted-in
return True

# Don't warn if not opted-in
logger.info(
'Optional warning %s not present in selected warnings: %r. Not running it at all.',
code,
self.options.select,
selected_rules,
)
return False
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _get_error(example: str, *, error_code_filter: Optional[str] = None, **kwarg
if error_code_filter:
mock_options = Mock()
mock_options.select = [error_code_filter]
mock_options.extend_select = None
# defaults
mock_options.extended_default_select = []
mock_options.enable_extensions = []
Expand Down

0 comments on commit 9bcbefe

Please sign in to comment.