mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
mypy: Fix future syntax errors and other minor mistakes.
When we move to the Python 3 mypy syntax, we can't reference a class before its definition.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
if False:
|
||||
from typing import Any
|
||||
from api.zulip import Client
|
||||
from zulip import Client
|
||||
|
||||
def add_subscriptions(client):
|
||||
# type: (Client) -> None
|
||||
|
||||
@@ -71,7 +71,7 @@ def get_whitespace_and_comments(tokens, i, end, line=None):
|
||||
|
||||
|
||||
def parse_sections(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> CssSectionList
|
||||
# type: (List[Token], int, int) -> 'CssSectionList'
|
||||
i = start
|
||||
sections = []
|
||||
while i < end:
|
||||
@@ -101,7 +101,7 @@ def parse_sections(tokens, start, end):
|
||||
return section_list
|
||||
|
||||
def parse_section(tokens, start, end, pre_fluff, post_fluff):
|
||||
# type: (List[Token], int, int, str, str) -> Union[CssNestedSection, CssSection]
|
||||
# type: (List[Token], int, int, str, str) -> Union['CssNestedSection', 'CssSection']
|
||||
assert not ws(tokens[start].s)
|
||||
assert tokens[end-1].s == '}' # caller should strip trailing fluff
|
||||
|
||||
@@ -130,7 +130,7 @@ def parse_section(tokens, start, end, pre_fluff, post_fluff):
|
||||
return section
|
||||
|
||||
def parse_selectors_section(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> Tuple[int, CssSelectorList]
|
||||
# type: (List[Token], int, int) -> Tuple[int, 'CssSelectorList']
|
||||
start, pre_fluff = get_whitespace_and_comments(tokens, start, end)
|
||||
assert pre_fluff == ''
|
||||
i = start
|
||||
@@ -143,7 +143,7 @@ def parse_selectors_section(tokens, start, end):
|
||||
return i, selector_list
|
||||
|
||||
def parse_selectors(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> CssSelectorList
|
||||
# type: (List[Token], int, int) -> 'CssSelectorList'
|
||||
i = start
|
||||
selectors = []
|
||||
while i < end:
|
||||
@@ -190,7 +190,7 @@ def parse_selector(tokens, start, end):
|
||||
return selector
|
||||
|
||||
def parse_declaration_block(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> CssDeclarationBlock
|
||||
# type: (List[Token], int, int) -> 'CssDeclarationBlock'
|
||||
assert tokens[start].s == '{' # caller should strip leading fluff
|
||||
assert tokens[end-1].s == '}' # caller should strip trailing fluff
|
||||
i = start + 1
|
||||
@@ -212,7 +212,7 @@ def parse_declaration_block(tokens, start, end):
|
||||
return declaration_block
|
||||
|
||||
def parse_declaration(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> CssDeclaration
|
||||
# type: (List[Token], int, int) -> 'CssDeclaration'
|
||||
i, pre_fluff = get_whitespace_and_comments(tokens, start, end)
|
||||
|
||||
if (i >= end) or (tokens[i].s == '}'):
|
||||
@@ -241,7 +241,7 @@ def parse_declaration(tokens, start, end):
|
||||
return declaration
|
||||
|
||||
def parse_value(tokens, start, end):
|
||||
# type: (List[Token], int, int) -> CssValue
|
||||
# type: (List[Token], int, int) -> 'CssValue'
|
||||
i, pre_fluff = get_whitespace_and_comments(tokens, start, end)
|
||||
if i < end:
|
||||
value = tokens[i]
|
||||
@@ -353,7 +353,7 @@ def handle_postfluff(post_fluff, indent=False, space_after_first_line=False):
|
||||
|
||||
class CssSectionList(object):
|
||||
def __init__(self, tokens, sections):
|
||||
# type: (List[Token], List[Union[CssNestedSection, CssSection]]) -> None
|
||||
# type: (List[Token], List[Union['CssNestedSection', 'CssSection']]) -> None
|
||||
self.tokens = tokens
|
||||
self.sections = sections
|
||||
|
||||
@@ -364,7 +364,7 @@ class CssSectionList(object):
|
||||
|
||||
class CssNestedSection(object):
|
||||
def __init__(self, tokens, selector_list, section_list, pre_fluff, post_fluff):
|
||||
# type: (List[Token], CssSelectorList, CssSectionList, str, str) -> None
|
||||
# type: (List[Token], 'CssSelectorList', CssSectionList, str, str) -> None
|
||||
self.tokens = tokens
|
||||
self.selector_list = selector_list
|
||||
self.section_list = section_list
|
||||
@@ -391,7 +391,7 @@ class CssNestedSection(object):
|
||||
|
||||
class CssSection(object):
|
||||
def __init__(self, tokens, selector_list, declaration_block, pre_fluff, post_fluff):
|
||||
# type: (List[Token], CssSelectorList, CssDeclarationBlock, str, str) -> None
|
||||
# type: (List[Token], 'CssSelectorList', 'CssDeclarationBlock', str, str) -> None
|
||||
self.tokens = tokens
|
||||
self.selector_list = selector_list
|
||||
self.declaration_block = declaration_block
|
||||
@@ -410,7 +410,7 @@ class CssSection(object):
|
||||
|
||||
class CssSelectorList(object):
|
||||
def __init__(self, tokens, selectors):
|
||||
# type: (List[Token], List[CssSelector]) -> None
|
||||
# type: (List[Token], List['CssSelector']) -> None
|
||||
self.tokens = tokens
|
||||
self.selectors = selectors
|
||||
|
||||
@@ -433,7 +433,7 @@ class CssSelector(object):
|
||||
|
||||
class CssDeclarationBlock(object):
|
||||
def __init__(self, tokens, declarations):
|
||||
# type: (List[Token], List[CssDeclaration]) -> None
|
||||
# type: (List[Token], List['CssDeclaration']) -> None
|
||||
self.tokens = tokens
|
||||
self.declarations = declarations
|
||||
|
||||
@@ -447,7 +447,7 @@ class CssDeclarationBlock(object):
|
||||
|
||||
class CssDeclaration(object):
|
||||
def __init__(self, tokens, pre_fluff, post_fluff, css_property, css_value, semicolon):
|
||||
# type: (List[Token], str, str, str, CssValue, bool) -> None
|
||||
# type: (List[Token], str, str, str, 'CssValue', bool) -> None
|
||||
self.tokens = tokens
|
||||
self.pre_fluff = pre_fluff
|
||||
self.post_fluff = post_fluff
|
||||
|
||||
@@ -20,7 +20,7 @@ class Graph(object):
|
||||
self.nodes.add(child)
|
||||
|
||||
def copy(self):
|
||||
# type: () -> Graph
|
||||
# type: () -> 'Graph'
|
||||
return Graph(self.edges())
|
||||
|
||||
def num_edges(self):
|
||||
@@ -28,7 +28,7 @@ class Graph(object):
|
||||
return len(self.edges())
|
||||
|
||||
def minus_edge(self, edge):
|
||||
# type: (Edge) -> Graph
|
||||
# type: (Edge) -> 'Graph'
|
||||
edges = self.edges().copy()
|
||||
edges.remove(edge)
|
||||
return Graph(edges)
|
||||
|
||||
@@ -22,7 +22,7 @@ class HtmlTreeBranch(object):
|
||||
"""
|
||||
|
||||
def __init__(self, tags, fn):
|
||||
# type: (List[TagInfo], Optional[str]) -> None
|
||||
# type: (List['TagInfo'], Optional[str]) -> None
|
||||
self.tags = tags
|
||||
self.fn = fn
|
||||
self.line = tags[-1].token.line
|
||||
@@ -189,8 +189,8 @@ def html_tag_tree(text):
|
||||
|
||||
|
||||
def build_id_dict(templates):
|
||||
# type: (List[str]) -> (Dict[str,List[str]])
|
||||
template_id_dict = defaultdict(list) # type: (Dict[str,List[str]])
|
||||
# type: (List[str]) -> (Dict[str, List[str]])
|
||||
template_id_dict = defaultdict(list) # type: (Dict[str, List[str]])
|
||||
|
||||
for fn in templates:
|
||||
text = open(fn).read()
|
||||
|
||||
Reference in New Issue
Block a user