Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Handle the conditionally existing builtins edge case #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions beniget/beniget.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def _str(self, nodes):
# this should probably be assigned to the filename give to DefUseChains instead.
Builtins["__file__"] = __file__

# The WindowsError is the sole occurence of a conditionally existing builtin.
tristanlatr marked this conversation as resolved.
Show resolved Hide resolved
# So we handle it by special-casing it.
Builtins.setdefault('WindowsError', OSError)

DeclarationStep, DefinitionStep = object(), object()

def collect_future_imports(node):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@ class Point:
'x -> (<MatchClass> -> (), x -> (<Call> -> ()))',
'y -> (<MatchClass> -> (), y -> (<Call> -> ()))'])

def test_WindowsError_builtin_name(self):
# Test for issue https://github.com/serge-sans-paille/beniget/issues/119
code = 'try: 1/0\nexcept WindowsError as e: raise'
self.check_message(code, [])


class TestDefUseChainsStdlib(TestDefUseChains):
ast = _ast
Expand Down