Skip to content

Commit

Permalink
Update typing ignores for mypy 0.990
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Nov 13, 2022
1 parent a6032e8 commit cd3f2e4
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ lint = [
"flake8-bugbear",
"flake8-simplify",
"isort",
"mypy>=0.981",
"mypy>=0.990",
"sphinx-lint",
"docutils-stubs",
"types-requests",
Expand Down
4 changes: 2 additions & 2 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def add_js_file(self, filename: Optional[str], priority: int = 500,

self.registry.add_js_file(filename, priority=priority, **kwargs)
if hasattr(self, 'builder') and hasattr(self.builder, 'add_js_file'):
self.builder.add_js_file(filename, # type: ignore[attr-defined]
self.builder.add_js_file(filename,
priority=priority, **kwargs)

def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> Non
logger.debug('[app] adding stylesheet: %r', filename)
self.registry.add_css_files(filename, priority=priority, **kwargs)
if hasattr(self, 'builder') and hasattr(self.builder, 'add_css_file'):
self.builder.add_css_file(filename, # type: ignore[attr-defined]
self.builder.add_css_file(filename,
priority=priority, **kwargs)

def add_latex_package(self, packagename: str, options: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def add(self, msg: str, origin: Union[Element, "MsgOrigin"]) -> None:
line = origin.line
if line is None:
line = -1
self.metadata[msg].append((origin.source, line, origin.uid)) # type: ignore
self.metadata[msg].append((origin.source, line, origin.uid))

def __iter__(self) -> Generator[Message, None, None]:
for message in self.messages:
Expand Down
2 changes: 1 addition & 1 deletion sphinx/cmd/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def main(argv: List[str] = sys.argv[1:]) -> int:
try:
args = parser.parse_args(argv)
except SystemExit as err:
return err.code
return err.code # type: ignore[return-value]

d = vars(args)
# delete None or False value
Expand Down
2 changes: 1 addition & 1 deletion sphinx/directives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def run(self) -> List[Node]:
role_name = self.arguments[0]
role, messages = roles.role(role_name, self.state_machine.language,
self.lineno, self.state.reporter)
if role:
if role: # type: ignore[truthy-function]
docutils.register_role('', role)
self.env.temp_data['default_role'] = role_name
else:
Expand Down
2 changes: 1 addition & 1 deletion sphinx/environment/adapters/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _entries_from_toctree(toctreenode: addnodes.toctree, parents: List[str],
if hasattr(toctree, 'uid'):
# move uid to caption_node to translate it
caption_node.uid = toctree.uid # type: ignore
del toctree.uid # type: ignore
del toctree.uid
newnode += caption_node
newnode.extend(tocentries)
newnode['toctree'] = True
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def render_dot(self: SphinxTranslator, code: str, options: Dict, format: str,
return relfn, outfn

if (hasattr(self.builder, '_graphviz_warned_dot') and
self.builder._graphviz_warned_dot.get(graphviz_dot)): # type: ignore[attr-defined]
self.builder._graphviz_warned_dot.get(graphviz_dot)):
return None, None

ensuredir(path.dirname(outfn))
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/imgmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def clean_up_files(app: Sphinx, exc: Exception) -> None:

if hasattr(app.builder, '_imgmath_tempdir'):
try:
shutil.rmtree(app.builder._imgmath_tempdir) # type: ignore
shutil.rmtree(app.builder._imgmath_tempdir)
except Exception:
pass

Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def fetch_inventory(app: Sphinx, uri: str, inv: Any) -> Any:
raise
try:
if hasattr(f, 'url'):
newinv = f.url # type: ignore
newinv = f.url
if inv != newinv:
logger.info(__('intersphinx inventory has moved: %s -> %s'), inv, newinv)

Expand Down
8 changes: 4 additions & 4 deletions sphinx/ext/viewcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def env_merge_info(app: Sphinx, env: BuildEnvironment, docnames: Iterable[str],
if not hasattr(env, '_viewcode_modules'):
env._viewcode_modules = {} # type: ignore
# now merge in the information from the subprocess
for modname, entry in other._viewcode_modules.items(): # type: ignore
for modname, entry in other._viewcode_modules.items():
if modname not in env._viewcode_modules: # type: ignore
env._viewcode_modules[modname] = entry # type: ignore
else:
Expand Down Expand Up @@ -228,12 +228,12 @@ def collect_pages(app: Sphinx) -> Generator[Tuple[str, Dict[str, Any], str], Non
highlighter = app.builder.highlighter # type: ignore
urito = app.builder.get_relative_uri

modnames = set(env._viewcode_modules) # type: ignore
modnames = set(env._viewcode_modules)

for modname, entry in status_iterator(
sorted(env._viewcode_modules.items()), # type: ignore
sorted(env._viewcode_modules.items()),
__('highlighting module code... '), "blue",
len(env._viewcode_modules), # type: ignore
len(env._viewcode_modules),
app.verbosity, lambda x: x[0]):
if not entry:
continue
Expand Down
4 changes: 2 additions & 2 deletions sphinx/pycode/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ def visit_Assign(self, node: ast.Assign) -> None:
return # this assignment is not new definition!

# record annotation
if hasattr(node, 'annotation') and node.annotation: # type: ignore
if hasattr(node, 'annotation') and node.annotation:
for varname in varnames:
self.add_variable_annotation(varname, node.annotation) # type: ignore
self.add_variable_annotation(varname, node.annotation)
elif hasattr(node, 'type_comment') and node.type_comment:
for varname in varnames:
self.add_variable_annotation(varname, node.type_comment) # type: ignore
Expand Down
8 changes: 4 additions & 4 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def unwrap_all(obj: Any, *, stop: Optional[Callable] = None) -> Any:
elif ispartial(obj):
obj = obj.func
elif inspect.isroutine(obj) and hasattr(obj, '__wrapped__'):
obj = obj.__wrapped__ # type: ignore
obj = obj.__wrapped__
elif isclassmethod(obj):
obj = obj.__func__
elif isstaticmethod(obj):
Expand Down Expand Up @@ -278,7 +278,7 @@ def is_singledispatch_function(obj: Any) -> bool:
if (inspect.isfunction(obj) and
hasattr(obj, 'dispatch') and
hasattr(obj, 'register') and
obj.dispatch.__module__ == 'functools'): # type: ignore
obj.dispatch.__module__ == 'functools'):
return True
else:
return False
Expand Down Expand Up @@ -336,10 +336,10 @@ def isgenericalias(obj: Any) -> bool:
if isinstance(obj, typing._GenericAlias): # type: ignore
return True
elif (hasattr(types, 'GenericAlias') and # only for py39+
isinstance(obj, types.GenericAlias)): # type: ignore
isinstance(obj, types.GenericAlias)):
return True
elif (hasattr(typing, '_SpecialGenericAlias') and # for py39+
isinstance(obj, typing._SpecialGenericAlias)): # type: ignore
isinstance(obj, typing._SpecialGenericAlias)):
return True
else:
return False
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@contextmanager
def ignore_insecure_warning(**kwargs: Any) -> Generator[None, None, None]:
with warnings.catch_warnings():
if not kwargs.get('verify') and InsecureRequestWarning:
if not kwargs.get('verify'):
# ignore InsecureRequestWarning if verify=False
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
yield
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def default_role(docname: str, name: str) -> Generator[None, None, None]:
if name:
dummy_reporter = Reporter('', 4, 4)
role_fn, _ = roles.role(name, english, 0, dummy_reporter)
if role_fn:
if role_fn: # type: ignore[truthy-function]
docutils.register_role('', role_fn)
else:
logger.warning(__('default role %s not found'), name, location=docname)
Expand Down
4 changes: 2 additions & 2 deletions sphinx/writers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def visit_math(self, node: Element, math_env: str = '') -> None:
def depart_math(self, node: Element, math_env: str = '') -> None:
name = self.builder.math_renderer_name
_, depart = self.builder.app.registry.html_inline_math_renderers[name]
if depart:
if depart: # type: ignore[truthy-function]
depart(self, node)

def visit_math_block(self, node: Element, math_env: str = '') -> None:
Expand All @@ -878,5 +878,5 @@ def visit_math_block(self, node: Element, math_env: str = '') -> None:
def depart_math_block(self, node: Element, math_env: str = '') -> None:
name = self.builder.math_renderer_name
_, depart = self.builder.app.registry.html_block_math_renderers[name]
if depart:
if depart: # type: ignore[truthy-function]
depart(self, node)
4 changes: 2 additions & 2 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def visit_math(self, node: Element, math_env: str = '') -> None:
def depart_math(self, node: Element, math_env: str = '') -> None:
name = self.builder.math_renderer_name
_, depart = self.builder.app.registry.html_inline_math_renderers[name]
if depart:
if depart: # type: ignore[truthy-function]
depart(self, node)

def visit_math_block(self, node: Element, math_env: str = '') -> None:
Expand All @@ -816,5 +816,5 @@ def visit_math_block(self, node: Element, math_env: str = '') -> None:
def depart_math_block(self, node: Element, math_env: str = '') -> None:
name = self.builder.math_renderer_name
_, depart = self.builder.app.registry.html_block_math_renderers[name]
if depart:
if depart: # type: ignore[truthy-function]
depart(self, node)

0 comments on commit cd3f2e4

Please sign in to comment.