Skip to content

Commit 32a46cb

Browse files
amanagrtimabbott
authored andcommitted
mypy: Use Rule from zulint to specify type for custom rules.
1 parent 7588333 commit 32a46cb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tools/custom_check.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import print_function
22
from __future__ import absolute_import
33

4-
from typing import cast, Any, Dict, List, Tuple
4+
from typing import Any, Dict, List, Tuple
55
from zulint.custom_rules import RuleList
66

7-
Rule = List[Dict[str, Any]]
7+
MYPY = False
8+
if MYPY:
9+
from zulint.custom_rules import Rule
810

911
whitespace_rules = [
1012
# This linter should be first since bash_rules depends on it.
@@ -30,7 +32,7 @@
3032

3133
python_rules = RuleList(
3234
langs=['py'],
33-
rules=cast(Rule, [
35+
rules=[
3436
{'pattern': '".*"%\([a-z_].*\)?$',
3537
'description': 'Missing space around "%"'},
3638
{'pattern': "'.*'%\([a-z_].*\)?$",
@@ -96,17 +98,17 @@
9698
'bad_lines': ['class TestSomeBot(DefaultTests, BotTestCase):'],
9799
'good_lines': ['class TestSomeBot(BotTestCase, DefaultTests):'],
98100
'description': 'Bot test cases should inherit from BotTestCase before DefaultTests.'},
99-
]) + whitespace_rules,
101+
] + whitespace_rules,
100102
max_length=140,
101103
)
102104

103105
bash_rules = RuleList(
104106
langs=['sh'],
105-
rules=cast(Rule, [
107+
rules=[
106108
{'pattern': '#!.*sh [-xe]',
107109
'description': 'Fix shebang line with proper call to /usr/bin/env for Bash path, change -x|-e switches'
108110
' to set -x|set -e'},
109-
]) + whitespace_rules[0:1],
111+
] + whitespace_rules[0:1],
110112
)
111113

112114

@@ -141,10 +143,10 @@
141143

142144
markdown_rules = RuleList(
143145
langs=['md'],
144-
rules=markdown_whitespace_rules + prose_style_rules + cast(Rule, [
146+
rules=markdown_whitespace_rules + prose_style_rules + [
145147
{'pattern': '\[(?P<url>[^\]]+)\]\((?P=url)\)',
146148
'description': 'Linkified markdown URLs should use cleaner <http://example.com> syntax.'}
147-
]),
149+
],
148150
max_length=120,
149151
length_exclude=markdown_docs_length_exclude,
150152
)

0 commit comments

Comments
 (0)