Skip to content

Commit

Permalink
Merge pull request #5537 from tk0miya/mypy-0.641
Browse files Browse the repository at this point in the history
Fix mypy violations
  • Loading branch information
tk0miya authored Oct 16, 2018
2 parents 8c56fd8 + a77f351 commit be2b86c
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 63 deletions.
2 changes: 1 addition & 1 deletion sphinx/builders/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def add_js_file(self, filename, **kwargs):
if filename and '://' not in filename:
filename = posixpath.join('_static', filename)

self.script_files.append(JavaScript(filename, **kwargs)) # type: ignore
self.script_files.append(JavaScript(filename, **kwargs))

@property
def default_translator_class(self):
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/qthelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def write_toc(self, node, indentlevel=4):

def keyword_item(self, name, ref):
# type: (unicode, Any) -> unicode
matchobj = _idpattern.match(name) # type: ignore
matchobj = _idpattern.match(name)
if matchobj:
groupdict = matchobj.groupdict()
shortname = groupdict['title']
Expand Down
4 changes: 2 additions & 2 deletions sphinx/cmd/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def valid_dir(d):
if not path.isdir(dir):
return False

if set(['Makefile', 'make.bat']) & set(os.listdir(dir)): # type: ignore
if set(['Makefile', 'make.bat']) & set(os.listdir(dir)):
return False

if d['sep']:
Expand All @@ -523,7 +523,7 @@ def valid_dir(d):
d['dot'] + 'templates',
d['master'] + d['suffix'],
]
if set(reserved_names) & set(os.listdir(dir)): # type: ignore
if set(reserved_names) & set(os.listdir(dir)):
return False

return True
Expand Down
2 changes: 1 addition & 1 deletion sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def correct_copyright_year(app, config):
for k in ('copyright', 'epub_copyright'):
if k in config:
replace = r'\g<1>%s' % format_date('%Y')
config[k] = copyright_year_re.sub(replace, config[k]) # type: ignore
config[k] = copyright_year_re.sub(replace, config[k])


def check_confval_types(app, config):
Expand Down
12 changes: 6 additions & 6 deletions sphinx/domains/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CObject(ObjectDescription):
def _parse_type(self, node, ctype):
# type: (nodes.Node, unicode) -> None
# add cross-ref nodes for all words
for part in [_f for _f in wsplit_re.split(ctype) if _f]: # type: ignore
for part in [_f for _f in wsplit_re.split(ctype) if _f]:
tnode = nodes.Text(part, part)
if part[0] in string.ascii_letters + '_' and \
part not in self.stopwords:
Expand All @@ -98,10 +98,10 @@ def _parse_type(self, node, ctype):
def _parse_arglist(self, arglist):
# type: (unicode) -> Iterator[unicode]
while True:
m = c_funcptr_arg_sig_re.match(arglist) # type: ignore
m = c_funcptr_arg_sig_re.match(arglist)
if m:
yield m.group()
arglist = c_funcptr_arg_sig_re.sub('', arglist) # type: ignore
arglist = c_funcptr_arg_sig_re.sub('', arglist)
if ',' in arglist:
_, arglist = arglist.split(',', 1)
else:
Expand All @@ -118,9 +118,9 @@ def handle_signature(self, sig, signode):
# type: (unicode, addnodes.desc_signature) -> unicode
"""Transform a C signature into RST nodes."""
# first try the function pointer signature regex, it's more specific
m = c_funcptr_sig_re.match(sig) # type: ignore
m = c_funcptr_sig_re.match(sig)
if m is None:
m = c_sig_re.match(sig) # type: ignore
m = c_sig_re.match(sig)
if m is None:
raise ValueError('no match')
rettype, name, arglist, const = m.groups()
Expand Down Expand Up @@ -162,7 +162,7 @@ def handle_signature(self, sig, signode):
arg = arg.strip()
param = addnodes.desc_parameter('', '', noemph=True)
try:
m = c_funcptr_arg_sig_re.match(arg) # type: ignore
m = c_funcptr_arg_sig_re.match(arg)
if m:
self._parse_type(param, m.group(1) + '(')
param += nodes.emphasis(m.group(2), m.group(2))
Expand Down
4 changes: 2 additions & 2 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def make_xrefs(self,
if split_contnode:
contnode = nodes.Text(sub_target)

if delims_re.match(sub_target): # type: ignore
if delims_re.match(sub_target):
results.append(contnode or innernode(sub_target, sub_target))
else:
results.append(self.make_xref(rolename, domain, sub_target,
Expand Down Expand Up @@ -253,7 +253,7 @@ def handle_signature(self, sig, signode):
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
"""
m = py_sig_re.match(sig) # type: ignore
m = py_sig_re.match(sig)
if m is None:
raise ValueError
name_prefix, name, arglist, retann = m.groups()
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def parse_directive(d):
if not dir.startswith('.'):
# Assume it is a directive without syntax
return (dir, '')
m = dir_sig_re.match(dir) # type: ignore
m = dir_sig_re.match(dir)
if not m:
return (dir, '')
parsed_dir, parsed_args = m.groups()
Expand Down
6 changes: 3 additions & 3 deletions sphinx/domains/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def handle_signature(self, sig, signode):
# type: (unicode, addnodes.desc_signature) -> unicode
"""Transform an option description into RST nodes."""
count = 0
firstname = ''
firstname = '' # type: unicode
for potential_option in sig.split(', '):
potential_option = potential_option.strip()
m = option_desc_re.match(potential_option) # type: ignore
m = option_desc_re.match(potential_option)
if not m:
logger.warning(__('Malformed option description %r, should '
'look like "opt", "-opt args", "--opt args", '
Expand Down Expand Up @@ -388,7 +388,7 @@ def token_xrefs(text):
# type: (unicode) -> List[nodes.Node]
retnodes = []
pos = 0
for m in token_re.finditer(text): # type: ignore
for m in token_re.finditer(text):
if m.start() > pos:
txt = text[pos:m.start()]
retnodes.append(nodes.Text(txt, txt))
Expand Down
8 changes: 4 additions & 4 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def parse_name(self):
# an autogenerated one
try:
explicit_modname, path, base, args, retann = \
py_ext_sig_re.match(self.name).groups() # type: ignore
py_ext_sig_re.match(self.name).groups()
except AttributeError:
logger.warning(__('invalid signature for auto%s (%r)') % (self.objtype, self.name))
return False
Expand All @@ -367,7 +367,7 @@ def parse_name(self):
modname = None
parents = []

self.modname, self.objpath = self.resolve_name(modname, parents, path, base)
self.modname, self.objpath = self.resolve_name(modname, parents, path, base) # type: ignore # NOQA

if not self.modname:
return False
Expand Down Expand Up @@ -981,7 +981,7 @@ def _find_signature(self, encoding=None):
if not doclines:
continue
# match first line of docstring against signature RE
match = py_ext_sig_re.match(doclines[0]) # type: ignore
match = py_ext_sig_re.match(doclines[0])
if not match:
continue
exmod, path, base, args, retann = match.groups()
Expand All @@ -998,7 +998,7 @@ def _find_signature(self, encoding=None):
result = args, retann
# don't look any further
break
return result
return result # type: ignore

def get_doc(self, encoding=None, ignore=1):
# type: (unicode, int) -> List[List[unicode]]
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def mangle_signature(sig, max_chars=30):

opt_re = re.compile(r"^(.*, |)([a-zA-Z0-9_*]+)=")
while s:
m = opt_re.search(s) # type: ignore
m = opt_re.search(s)
if not m:
# The rest are arguments
args = s.split(', ')
Expand Down Expand Up @@ -493,7 +493,7 @@ def extract_summary(doc, document):
summary = doc[0].strip()
else:
# Try to find the "first sentence", which may span multiple lines
sentences = periods_re.split(" ".join(doc)) # type: ignore
sentences = periods_re.split(" ".join(doc))
if len(sentences) == 1:
summary = sentences[0].strip()
else:
Expand Down
14 changes: 7 additions & 7 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,27 +303,27 @@ def find_autosummary_in_lines(lines, module=None, filename=None):
template = None
current_module = module
in_autosummary = False
base_indent = ""
base_indent = "" # type: unicode

for line in lines:
if in_autosummary:
m = toctree_arg_re.match(line) # type: ignore
m = toctree_arg_re.match(line)
if m:
toctree = m.group(1)
if filename:
toctree = os.path.join(os.path.dirname(filename),
toctree)
continue

m = template_arg_re.match(line) # type: ignore
m = template_arg_re.match(line)
if m:
template = m.group(1).strip()
continue

if line.strip().startswith(':'):
continue # skip options

m = autosummary_item_re.match(line) # type: ignore
m = autosummary_item_re.match(line)
if m:
name = m.group(1).strip()
if name.startswith('~'):
Expand All @@ -339,23 +339,23 @@ def find_autosummary_in_lines(lines, module=None, filename=None):

in_autosummary = False

m = autosummary_re.match(line) # type: ignore
m = autosummary_re.match(line)
if m:
in_autosummary = True
base_indent = m.group(1)
toctree = None
template = None
continue

m = automodule_re.search(line) # type: ignore
m = automodule_re.search(line)
if m:
current_module = m.group(1).strip()
# recurse into the automodule docstring
documented.extend(find_autosummary_in_docstring(
current_module, filename=filename))
continue

m = module_re.match(line) # type: ignore
m = module_re.match(line)
if m:
current_module = m.group(2)
continue
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def build_c_coverage(self):
# Fetch all the info from the header files
c_objects = self.env.domaindata['c']['objects']
for filename in self.c_sourcefiles:
undoc = set()
undoc = set() # type: Set[Tuple[unicode, unicode]]
with open(filename, 'r') as f:
for line in f:
for key, regex in self.c_regexes:
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, filename, content, dot=''):

def parse(self, dot=None):
# type: (unicode) -> None
matched = self.maptag_re.match(self.content[0]) # type: ignore
matched = self.maptag_re.match(self.content[0])
if not matched:
raise GraphvizError('Invalid clickable map file found: %s' % self.filename)

Expand All @@ -73,7 +73,7 @@ def parse(self, dot=None):
self.content[0] = self.content[0].replace('%3', self.id)

for line in self.content:
if self.href_re.search(line): # type: ignore
if self.href_re.search(line):
self.clickable.append(line)

def generate_clickable_map(self):
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/imgmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def convert_dvi_to_png(dvipath, builder):
depth = None
if builder.config.imgmath_use_preview:
for line in stdout.splitlines():
matched = depth_re.match(line) # type: ignore
matched = depth_re.match(line)
if matched:
depth = int(matched.group(1))
write_png_depth(filename, depth)
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def try_import(objname):
__import__(objname)
return sys.modules.get(objname) # type: ignore
except (ImportError, ValueError): # ValueError,py27 -> ImportError,py3
matched = module_sig_re.match(objname) # type: ignore
matched = module_sig_re.match(objname)

if not matched:
return None
Expand All @@ -88,7 +88,7 @@ def try_import(objname):
return None
try:
__import__(modname)
return getattr(sys.modules.get(modname), attrname, None)
return getattr(sys.modules.get(modname), attrname, None) # type: ignore
except (ImportError, ValueError): # ValueError,py27 -> ImportError,py3
return None

Expand Down
18 changes: 9 additions & 9 deletions sphinx/ext/napoleon/docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _consume_field(self, parse_type=True, prefer_type=False):
_name, _type, _desc = before, '', after # type: unicode, unicode, unicode

if parse_type:
match = _google_typed_arg_regex.match(before) # type: ignore
match = _google_typed_arg_regex.match(before)
if match:
_name = match.group(1)
_type = match.group(2)
Expand Down Expand Up @@ -496,9 +496,9 @@ def _is_list(self, lines):
# type: (List[unicode]) -> bool
if not lines:
return False
if _bullet_list_regex.match(lines[0]): # type: ignore
if _bullet_list_regex.match(lines[0]):
return True
if _enumerated_list_regex.match(lines[0]): # type: ignore
if _enumerated_list_regex.match(lines[0]):
return True
if len(lines) < 2 or lines[0].endswith('::'):
return False
Expand Down Expand Up @@ -572,7 +572,7 @@ def _parse(self):
section = self._consume_section_header()
self._is_in_section = True
self._section_indent = self._get_current_indent()
if _directive_regex.match(section): # type: ignore
if _directive_regex.match(section):
lines = [section] + self._consume_to_next_section()
else:
lines = self._sections[section.lower()](section)
Expand Down Expand Up @@ -784,9 +784,9 @@ def _partition_field_on_colon(self, line):
# type: (unicode) -> Tuple[unicode, unicode, unicode]
before_colon = []
after_colon = []
colon = ''
colon = '' # type: unicode
found_colon = False
for i, source in enumerate(_xref_regex.split(line)): # type: ignore
for i, source in enumerate(_xref_regex.split(line)):
if found_colon:
after_colon.append(source)
else:
Expand Down Expand Up @@ -968,7 +968,7 @@ def _is_section_header(self):
section, underline = self._line_iter.peek(2)
section = section.lower()
if section in self._sections and isinstance(underline, string_types):
return bool(_numpy_section_regex.match(underline)) # type: ignore
return bool(_numpy_section_regex.match(underline))
elif self._directive_sections:
if _directive_regex.match(section):
for directive_section in self._directive_sections:
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def _parse_numpydoc_see_also_section(self, content):
def parse_item_name(text):
# type: (unicode) -> Tuple[unicode, unicode]
"""Match ':role:`name`' or 'name'"""
m = self._name_rgx.match(text) # type: ignore
m = self._name_rgx.match(text)
if m:
g = m.groups()
if g[1] is None:
Expand All @@ -1029,7 +1029,7 @@ def push_item(name, rest):
if not line.strip():
continue

m = self._name_rgx.match(line) # type: ignore
m = self._name_rgx.match(line)
if m and line[m.end():].strip().startswith(':'):
push_item(current_func, rest)
current_func, line = line[:m.end()], line[m.end():]
Expand Down
4 changes: 2 additions & 2 deletions sphinx/highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def highlight_block(self, source, lang, opts=None, location=None, force=False, *

# trim doctest options if wanted
if isinstance(lexer, PythonConsoleLexer) and self.trim_doctest_flags:
source = doctest.blankline_re.sub('', source) # type: ignore
source = doctest.doctestopt_re.sub('', source) # type: ignore
source = doctest.blankline_re.sub('', source)
source = doctest.doctestopt_re.sub('', source)

# highlight via Pygments
formatter = self.get_formatter(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __new__(cls, func, *args):
if not args:
# not called with "function" and "arguments", but a plain string
return text_type(func)
return object.__new__(cls) # type: ignore
return object.__new__(cls)

def __getnewargs__(self):
# type: () -> Tuple
Expand Down
Loading

0 comments on commit be2b86c

Please sign in to comment.