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

Dylink doesn't allow us to call functions that start with '_' #164

Open
aaaaalbert opened this issue Feb 18, 2015 · 2 comments
Open

Dylink doesn't allow us to call functions that start with '_' #164

aaaaalbert opened this issue Feb 18, 2015 · 2 comments

Comments

@aaaaalbert
Copy link
Contributor

Note: This was SeattleTestbed/repy_v2#60 previously. I'm just attaching it to the correct issue tracker, but have not reviewed it for aptness.


If we import a file using dylink, it won't allow us to call functions that start with an underscore. This is different from how python import works. Not sure if this is an intended behaviour or not. Below is a piece of code that fails.

foo.py:

def _foo():
    print "foo"

bar.py:

from repyportability import *
add_dy_support(locals())

foo = dy_import_module("foo.py")

try:
  foo._foo()
except AttributeError, err:
  print "Unable to call foo._foo() when using dylink.\n" + str(err)

import foo
foo._foo()

If we run bar.py, we get the following error when calling foo._foo() (when using dylink):

monzum@TestUbuntu:$ python bar.py 
Unable to call foo._foo() when using dylink.
ImportedModule instance has no attribute '_foo'

However once we use 'import' to import it, we are able to call foo._foo().

aaaaalbert added a commit to aaaaalbert/seattlelib_v2 that referenced this issue Aug 17, 2016
These tests try to illustrate Python's behavior on `import`ing or
`from MODULE import *`ing a name that starts with an underscore
(``_'') character, and check whether `dylink`'s corresponding
functions `dy_import_module` and `dy_import_module_symbols`
perform like their Python counterparts.

The expected behavior is to
* do import `module._underscorename`, but
* don't add `_underscorename` via `from module import *`

Alas, `dylink` doesn't conform currently: SeattleTestbed#164 .
@aaaaalbert
Copy link
Contributor Author

Indeed, this issue (and also #153) shows that dylink (and also repyportability in combination with it, see SeattleTestbed/portability#28) doesn't quite work as Python's import / from MODULE import * do. I've created a few additional unit tests to demonstrate what should and what does happen, see aaaaalbert/seattlelib_v2@bb285e4. From the commit message:

The expected behavior is to

  • do import module._underscorename, but
  • don't add _underscorename via from module import *

However, the corresponding dy_import_module and dy_import_module_symbols get it both wrong.

@aaaaalbert
Copy link
Contributor Author

See also here for Python's import behavior: https://docs.python.org/2/reference/simple_stmts.html#the-import-statement

aaaaalbert added a commit to aaaaalbert/seattlelib_v2 that referenced this issue Aug 26, 2016
This patch makes `dylink.r2py`'s import functions behave more
like their Python counterparts. Specifically,
* `dy_import_module_symbols` (akin to Python's `from MODULE import *`)
  now correctly *skips* names that start with an underscort ("_"), and
* `dy_import_module` (akin to Python's `import MODULE`) now *does*
  correctly import these names.

The new test cases supplied by the parent commit,
bb285e4 ,
thus all pass now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant