mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix B023 (function definition does not bind loop variable)
This commit is contained in:
@@ -163,7 +163,6 @@ ignore = [
|
||||
"ARG003", # unused class method argument
|
||||
"ARG005", # unused lambda argument
|
||||
# flake8-bugbear
|
||||
"B023", # function definition does not bind loop variable
|
||||
"B026", # keyword argument ... must come after starred arguments
|
||||
"B028", # no explicit `stacklevel` keyword argument found
|
||||
# flake8-bugbear opinionated (disabled by default in flake8)
|
||||
|
||||
@@ -123,20 +123,22 @@ class SphinxFileSystemLoader(FileSystemLoader):
|
||||
for searchpath in self.searchpath:
|
||||
filename = str(pathlib.Path(searchpath, template))
|
||||
f = open_if_exists(filename)
|
||||
if f is None:
|
||||
continue
|
||||
with f:
|
||||
contents = f.read().decode(self.encoding)
|
||||
if f is not None:
|
||||
break
|
||||
else:
|
||||
raise TemplateNotFound(template)
|
||||
|
||||
mtime = path.getmtime(filename)
|
||||
with f:
|
||||
contents = f.read().decode(self.encoding)
|
||||
|
||||
def uptodate() -> bool:
|
||||
try:
|
||||
return path.getmtime(filename) == mtime
|
||||
except OSError:
|
||||
return False
|
||||
return contents, filename, uptodate
|
||||
raise TemplateNotFound(template)
|
||||
mtime = path.getmtime(filename)
|
||||
|
||||
def uptodate() -> bool:
|
||||
try:
|
||||
return path.getmtime(filename) == mtime
|
||||
except OSError:
|
||||
return False
|
||||
return contents, filename, uptodate
|
||||
|
||||
|
||||
class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
|
||||
|
||||
@@ -6,7 +6,7 @@ import zlib
|
||||
|
||||
import pytest
|
||||
|
||||
import sphinx.domains.cpp as cppDomain
|
||||
import sphinx.domains.cpp
|
||||
from sphinx import addnodes
|
||||
from sphinx.addnodes import (
|
||||
desc,
|
||||
@@ -128,37 +128,41 @@ def check(name, input, idDict, output=None, key=None, asTextOutput=None):
|
||||
asTextOutput + ';' if asTextOutput is not None else None)
|
||||
|
||||
|
||||
def test_domain_cpp_ast_fundamental_types():
|
||||
@pytest.mark.parametrize(('type_', 'id_v2'),
|
||||
sphinx.domains.cpp._id_fundamental_v2.items())
|
||||
def test_domain_cpp_ast_fundamental_types(type_, id_v2):
|
||||
# see https://en.cppreference.com/w/cpp/language/types
|
||||
for t, id_v2 in cppDomain._id_fundamental_v2.items():
|
||||
def makeIdV1():
|
||||
if t == 'decltype(auto)':
|
||||
return None
|
||||
id = t.replace(" ", "-").replace("long", "l")
|
||||
if "__int" not in t:
|
||||
id = id.replace("int", "i")
|
||||
id = id.replace("bool", "b").replace("char", "c")
|
||||
id = id.replace("wc_t", "wchar_t").replace("c16_t", "char16_t")
|
||||
id = id.replace("c8_t", "char8_t")
|
||||
id = id.replace("c32_t", "char32_t")
|
||||
return "f__%s" % id
|
||||
def make_id_v1():
|
||||
if type_ == 'decltype(auto)':
|
||||
return None
|
||||
id_ = type_.replace(" ", "-").replace("long", "l")
|
||||
if "__int" not in type_:
|
||||
id_ = id_.replace("int", "i")
|
||||
id_ = id_.replace("bool", "b").replace("char", "c")
|
||||
id_ = id_.replace("wc_t", "wchar_t").replace("c16_t", "char16_t")
|
||||
id_ = id_.replace("c8_t", "char8_t")
|
||||
id_ = id_.replace("c32_t", "char32_t")
|
||||
return f"f__{id_}"
|
||||
|
||||
def makeIdV2():
|
||||
id = id_v2
|
||||
if t == "std::nullptr_t":
|
||||
id = "NSt9nullptr_tE"
|
||||
return "1f%s" % id
|
||||
id1 = makeIdV1()
|
||||
id2 = makeIdV2()
|
||||
input = "void f(%s arg)" % t.replace(' ', ' ')
|
||||
output = "void f(%s arg)" % t
|
||||
check("function", input, {1: id1, 2: id2}, output=output)
|
||||
if ' ' in t:
|
||||
# try permutations of all components
|
||||
tcs = t.split()
|
||||
for p in itertools.permutations(tcs):
|
||||
input = "void f(%s arg)" % ' '.join(p)
|
||||
check("function", input, {1: id1, 2: id2})
|
||||
def make_id_v2():
|
||||
id_ = id_v2
|
||||
if type_ == "std::nullptr_t":
|
||||
id_ = "NSt9nullptr_tE"
|
||||
return f"1f{id_}"
|
||||
|
||||
id1 = make_id_v1()
|
||||
id2 = make_id_v2()
|
||||
|
||||
input = f"void f({type_.replace(' ', ' ')} arg)"
|
||||
output = f"void f({type_} arg)"
|
||||
|
||||
check("function", input, {1: id1, 2: id2}, output=output)
|
||||
if ' ' in type_:
|
||||
# try permutations of all components
|
||||
tcs = type_.split()
|
||||
for p in itertools.permutations(tcs):
|
||||
input = f"void f({' '.join(p)} arg)"
|
||||
check("function", input, {1: id1, 2: id2})
|
||||
|
||||
|
||||
def test_domain_cpp_ast_expressions():
|
||||
|
||||
Reference in New Issue
Block a user