Skip to content

Commit

Permalink
Be stricter about mypy needing error codes
Browse files Browse the repository at this point in the history
These make it clearer what's being ignored and harder to
accidentally ignore more than expected.
  • Loading branch information
PeterJCLaw committed Feb 13, 2023
1 parent 4eba7d6 commit 171fd33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions parso/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def parse(self,

if file_io is None:
if code is None:
file_io = FileIO(path) # type: ignore
file_io = FileIO(path) # type: ignore[arg-type]
else:
file_io = KnownContentFileIO(path, code)

if cache and file_io.path is not None:
module_node = load_module(self._hashed, file_io, cache_path=cache_path)
if module_node is not None:
return module_node # type: ignore
return module_node # type: ignore[no-any-return]

if code is None:
code = file_io.read()
Expand All @@ -132,7 +132,7 @@ def parse(self,
module_node = module_cache_item.node
old_lines = module_cache_item.lines
if old_lines == lines:
return module_node # type: ignore
return module_node # type: ignore[no-any-return]

new_node = self._diff_parser(
self._pgen_grammar, self._tokenizer, module_node
Expand All @@ -144,7 +144,7 @@ def parse(self,
# Never pickle in pypy, it's slow as hell.
pickling=cache and not is_pypy,
cache_path=cache_path)
return new_node # type: ignore
return new_node # type: ignore[no-any-return]

tokens = self._tokenizer(lines)

Expand All @@ -160,7 +160,7 @@ def parse(self,
# Never pickle in pypy, it's slow as hell.
pickling=cache and not is_pypy,
cache_path=cache_path)
return root_node # type: ignore
return root_node # type: ignore[no-any-return]

def _get_token_namespace(self):
ns = self._token_namespace
Expand Down
2 changes: 1 addition & 1 deletion parso/pgen2/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def generate_grammar(bnf_grammar: str, token_namespace) -> Grammar:
dfa_state.transitions[transition] = DFAPlan(next_dfa)

_calculate_tree_traversal(rule_to_dfas)
return Grammar(start_nonterminal, rule_to_dfas, reserved_strings) # type: ignore
return Grammar(start_nonterminal, rule_to_dfas, reserved_strings) # type: ignore[arg-type]


def _make_transition(token_namespace, reserved_syntax_strings, label):
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ ignore =


[mypy]
show_error_codes = true
enable_error_code = ignore-without-code

disallow_subclassing_any = True

# Avoid creating future gotchas emerging from bad typing
Expand Down

0 comments on commit 171fd33

Please sign in to comment.