Skip to content

Use secure builtins standard module, instead of the __builtins__ #109

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

Merged
merged 3 commits into from
Jul 27, 2022
Merged
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
6 changes: 4 additions & 2 deletions devtools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import builtins
import os
import sys
from pathlib import Path
Expand All @@ -7,12 +8,13 @@
# language=python
install_code = """
# add devtools `debug` function to builtins
import builtins
try:
from devtools import debug
except ImportError:
pass
else:
__builtins__['debug'] = debug
setattr(builtins, "debug", debug)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes please.

"""


Expand All @@ -24,7 +26,7 @@ def print_code() -> int:
def install() -> int:
print('[WARNING: this command is experimental, report issues at github.com/samuelcolvin/python-devtools]\n')

if 'debug' in __builtins__.__dict__:
if 'debug' in builtins.dir():
print('Looks like devtools is already installed.')
return 0

Expand Down