300
301
302def rstfile_to_description(path, filename, fix_urls):
303 html = subprocess.check_output(304 ['pandoc', path, '--no-highlight', '-f', 'rst', '-t', 'html5'])
305 footer = """<h2>References</h2>
306<p><a href="%s%s.html" target="_blank">clang.llvm.org</a></p>""" % (CLANG_TIDY_DOC_URL_BASE, filename)
290CLANG_TIDY_DOC_URL_BASE = "http://clang.llvm.org/extra/clang-tidy/checks/"
291
292
293def fix_local_urls(html, filename):294 # replace local ancors
295 html = re.sub("href=\"(?!http)#", "href=\"" +
296 CLANG_TIDY_DOC_URL_BASE + filename + ".html#", html)
103
104 linecnt += 1
105
106 elems = allmethod.split(",") 107 if "-" not in elems[2]:
108 # get rule and update
109 elemsfinal = elems[2].split("'")
78def GetDefinition(line_index, strip=0):
79 methodcomplete = 0
80 allmethod = ''
81 linecnt = 0 82
83 # initial line
84 linereplace = _FILE_LINES[line_index + linecnt].rstrip().lstrip()
45
46def CheckIfCommentIsValid(line, linenumber):
47
48 index = line.find("#") 49 if index == -1:
50 return -1
51
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()