1658def scan_setup_py():
1659 found = set()
1660 setters = False
1661 errors = 01662 with open("setup.py", "r") as f:
1663 for line in f.readlines():
1664 if "import versioneer" in line:
997
998
999@register_vcs_handler("git", "pieces_from_vcs")
1000def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):1001 # this runs 'git' from the root of the source tree. This only gets called
1002 # if the git-archive 'subst' keywords were *not* expanded, and
1003 # _version.py hasn't already been rewritten with a short version string,
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()