Open
Conversation
ankitxjoshi
reviewed
Aug 3, 2018
pyflakes/checker.py
Outdated
| super(Builtin, self).__init__(name, None) | ||
| self.can_delete = False | ||
| # __file__ can only be deleted on Python 3 | ||
| if not PY2 and name == '__file__': |
Contributor
There was a problem hiding this comment.
Please do verify if __file__ can be deleted or not in Python 2.
d5ffe4d to
ed63c89
Compare
An exception to the handling of builtins is they can not be deleted.
__builtins__, __file__ and __debug__ can be deleted. Adds a test runner that ensures defined builtins can be loaded, and can be deleted when the python runtime allows it.
ankitxjoshi
reviewed
Aug 11, 2018
| super(Builtin, self).__init__(name, None) | ||
| self.can_delete = False | ||
| # __builtins__ and __file__ can always be deleted. | ||
| # __debug__ can be deleted sometimes and not deleted other times. |
Contributor
There was a problem hiding this comment.
Can you please elaborate on this, it is failing for me.
surfer-172-20-4-99-hotspot:Desktop macbox$ python py-test.py
Traceback (most recent call last):
File "py-test.py", line 1, in <module>
del __debug__
NameError: name '__debug__' is not defined
surfer-172-20-4-99-hotspot:Desktop macbox$ python3 py-test.py
Traceback (most recent call last):
File "py-test.py", line 1, in <module>
del __debug__
NameError: name '__debug__' is not defined
Member
Author
There was a problem hiding this comment.
On my Python 3.7 (Rawhide), __debug__ can be deleted.
On earlier Python, locally, it isnt.
However it might come down to whether the Python build had debug enabled in it.
We might need to dig into the CPython source to find out, as I dont see any mention of this in peps
myint
requested changes
Nov 4, 2018
| # __debug__ can be deleted sometimes and not deleted other times. | ||
| # Safest course of action is to assume it can be deleted, in | ||
| # order that no error is reported by pyflakes | ||
| elif name in ('__builtins__', '__file__', '__debug__'): |
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 recent builtin rewrite had one regression, in that it allowed them to be deleted.
The first commit fixes that, but there are several builtins which can be deleted.
The second commit allows those builtins to be deleted without an UndefinedName being reported , which is an enhancement.
This also adds a test rig for determining which builtins can be deleted.