-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[clean strict optional] Fix some strict optional errors in mypy #3228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,7 @@ def visit_func_def(self, defn: FuncDef) -> None: | |
if cur_indent is None: | ||
# Consume the line, but don't mark it as belonging to the function yet. | ||
cur_line += 1 | ||
elif cur_indent > start_indent: | ||
elif start_indent is not None and cur_indent > start_indent: | ||
# A non-blank line that belongs to the function. | ||
cur_line += 1 | ||
end_line = cur_line | ||
|
@@ -211,7 +211,7 @@ def visit_func_def(self, defn: FuncDef) -> None: | |
is_typed = defn.type is not None | ||
for line in range(start_line, end_line): | ||
old_indent, _ = self.lines_covered[line] | ||
assert start_indent > old_indent | ||
assert start_indent is not None and start_indent > old_indent | ||
self.lines_covered[line] = (start_indent, is_typed) | ||
|
||
# Visit the body, in case there are nested functions | ||
|
@@ -304,7 +304,7 @@ def __init__(self, reports: Reports, output_dir: str) -> None: | |
self.css_html_path = os.path.join(reports.data_dir, 'xml', 'mypy-html.css') | ||
xsd_path = os.path.join(reports.data_dir, 'xml', 'mypy.xsd') | ||
self.schema = etree.XMLSchema(etree.parse(xsd_path)) | ||
self.last_xml = None # type: etree._ElementTree | ||
self.last_xml = None # type: Optional[etree._ElementTree] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it wouldn't be better to keep this as non-optional and remove the None assignments? Not sure I follow the logic there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand the logic correctly, those |
||
self.files = [] # type: List[FileInfo] | ||
|
||
def on_file(self, | ||
|
@@ -532,6 +532,7 @@ def on_file(self, | |
|
||
def on_finish(self) -> None: | ||
last_xml = self.memory_xml.last_xml | ||
assert last_xml is not None | ||
out_path = os.path.join(self.output_dir, 'index.xml') | ||
out_xslt = os.path.join(self.output_dir, 'mypy-html.xslt') | ||
out_css = os.path.join(self.output_dir, 'mypy-html.css') | ||
|
@@ -575,6 +576,7 @@ def on_file(self, | |
|
||
def on_finish(self) -> None: | ||
last_xml = self.memory_xml.last_xml | ||
assert last_xml is not None | ||
out_path = os.path.join(self.output_dir, 'index.html') | ||
out_css = os.path.join(self.output_dir, 'mypy-html.css') | ||
transformed_html = bytes(self.xslt_html(last_xml, ext=self.param_html)) | ||
|
@@ -606,6 +608,7 @@ def on_file(self, | |
|
||
def on_finish(self) -> None: | ||
last_xml = self.memory_xml.last_xml | ||
assert last_xml is not None | ||
out_path = os.path.join(self.output_dir, 'index.txt') | ||
stats.ensure_dir_exists(os.path.dirname(out_path)) | ||
transformed_txt = bytes(self.xslt_txt(last_xml)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code below distinguishes
False
andNone