Declare globals FMT_XML and FMT_BINARY#13054
Closed
cclauss wants to merge 1 commit intopython:masterfrom
Closed
Conversation
> 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
Member
|
I am not sure of these changes to be made just for silence linting. There are places where this pattern is followed. I am adding module maintainers to take a call. cc: @serhiy-storchaka, @ronaldoussoren |
Member
|
I concur with @tirkarthi. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first two lines create two global variables in a nonstandard way.
The third line makes explicit what the first two lines have accomplished.
flake8 testing of https://github.com/python/cpython on Python 3.7.1
$ flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
E901,E999,F821,F822,F823 are the "showstopper" flake8 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.
namenamein__all__