Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions dylink.r2py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def _dy_bind_code(module, context):

# Check each key, and bind those we should...
for attr in context:
# Skip attributes starting with _ or part of the stock API
if attr.startswith("_") or attr in STOCK_API:
# Skip attributes that are part of the stock API
if attr in STOCK_API:
continue

# Bind now
Expand Down Expand Up @@ -245,7 +245,8 @@ def dylink_import_global(module, module_context,new_callfunc="import"):
# It is critical to avoid overwriting things like _context, callfunc,
# and dy_import_module because these are specific to the containing
# module
if symbolname not in SYMBOLS_TO_IGNORE_WHEN_FROM_X_IMPORT:
if (symbolname not in SYMBOLS_TO_IGNORE_WHEN_FROM_X_IMPORT and
not symbolname.startswith("_")):
module_context[symbolname] = module_object._context[symbolname]


Expand Down
1 change: 1 addition & 0 deletions tests/examplelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Example library used to demonstrate import-override rules.
"""
foo = "examplelib.py's foo"
_foo = "examplelib.py's underscore-foo"
8 changes: 8 additions & 0 deletions tests/ut_seattlelib_dylinkunderscoreimportmodule.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Verify that `dylink`'s `dy_import_module` makes names with an underscore
prefix accessible.
"""
#pragma repy restrictions.test dylink.r2py
examplelib = dy_import_module("examplelib.py")

examplelib._foo
15 changes: 15 additions & 0 deletions tests/ut_seattlelib_dylinkunderscoreimportmodulesymbols.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Verify that `dylink`'s `dy_import_module_symbols` hides names with
an underscore prefix from the importer's namespace.
"""
#pragma repy restrictions.test dylink.r2py
dy_import_module_symbols("examplelib.py")

try:
_foo
except NameError:
# The expected, correct exception.
pass
else:
log("Error! Expected examplelib's `_foo` to be hidden, like in Python!\n")

14 changes: 14 additions & 0 deletions tests/ut_seattlelib_dylinkunderscorepythonfromximport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Demonstrate that Python's `from MODULE import *` hides names with
an underscore prefix from the importer's namespace.
"""
from examplelib import *

try:
_foo
except NameError:
# The expected, correct exception.
pass
else:
print "Error! Expected examplelib's `_foo` to be hidden!"

7 changes: 7 additions & 0 deletions tests/ut_seattlelib_dylinkunderscorepythonimport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Demonstrate that Python's `import` makes names with an underscore
prefix accessible.
"""
import examplelib
examplelib._foo