From ab4e366ecaccfd5bfa4db3f432486508c73a658f Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 2 May 2019 12:02:03 +0200 Subject: [PATCH] Declare globals FMT_XML and FMT_BINARY > PlistFormat = enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__) > globals().update(PlistFormat.__members__) > global FMT_XML, FMT_BINARY # explicitly declare globals to aid humans and linters The first two lines create two global variables in a nonstandard way. The third line makes explicit what the first two lines have done. [flake8](http://flake8.pycqa.org) testing of https://github.com/python/cpython on Python 3.7.1 $ __flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics__ ``` ./Lib/plistlib.py:48:1: F822 undefined name 'FMT_BINARY' in __all__ __all__ = [ ^ ./Lib/plistlib.py:48:1: F822 undefined name 'FMT_XML' in __all__ __all__ = [ ^ ./Lib/plistlib.py:112:29: F821 undefined name 'FMT_XML' dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False) ^ ./Lib/plistlib.py:135:24: F821 undefined name 'FMT_XML' dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False) ^ ./Lib/plistlib.py:917:5: F821 undefined name 'FMT_XML' FMT_XML: dict( ^ ./Lib/plistlib.py:922:5: F821 undefined name 'FMT_BINARY' FMT_BINARY: dict( ^ ./Lib/plistlib.py:961:28: F821 undefined name 'FMT_XML' def dump(value, fp, *, fmt=FMT_XML, sort_keys=True, skipkeys=False): ^ ./Lib/plistlib.py:972:25: F821 undefined name 'FMT_XML' def dumps(value, *, fmt=FMT_XML, skipkeys=False, sort_keys=True): ^ ``` __E901,E999,F821,F822,F823__ are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety. * F821: undefined name `name` * F822: undefined name `name` in `__all__` * F823: local variable name referenced before assignment * E901: SyntaxError or IndentationError * E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree --- Lib/plistlib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 248f5143f4edf7..ee35446200796d 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -67,6 +67,7 @@ PlistFormat = enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__) globals().update(PlistFormat.__members__) +global FMT_XML, FMT_BINARY # explicitly declare globals to aid humans and linters #