Wildcard import ("from module import *") not supported #108

Open
pyjsorg opened this Issue Apr 27, 2012 · 3 comments

Comments

Projects
None yet
1 participant
Contributor

pyjsorg commented Apr 27, 2012

>>> from os import *
Translated JS:
$module[''] = $p['_import_']('os.', null, null, false);

Translator._from() or Translator._doImport() should know that '*' is special case and use some kind of import_all($m, 'os'), which would import module, and then add to $m references to all names in os.all or all names in 'os' which do not start with underscore.

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=615 (May 15, 2011 04:42:16)

Contributor

pyjsorg commented Apr 27, 2012

From pe...@bittner.it on May 15, 2011 19:49:17:
As Luke explained it is (wide spread) bad practice, so not having it in pyjs is not necessarily a bad thing. Though, as some (lots, maybe) programmers are used to doing it why not implement it and print a pyjs compiler warning? I believe this would be a valid point, educating about the bad side effects the use of this syntax may have.

As a first step toward issuing the warning message as an error could be good.

Contributor

pyjsorg commented Apr 27, 2012

From dan.kl...@gmail.com on May 15, 2011 21:40:11:
It does not matter whether it is 'bad practice' or not as long as its valid python feature.
It is used in many modules out there, and ideally they should be translatable as is. Forcing user to alter 3rd-party modules is definitely worse than allowing wildcard imports.

Contributor

pyjsorg commented Apr 27, 2012

From dan.kl...@gmail.com on June 12, 2011 13:41:32:
Implemented in

http://pyjamas.git.sourceforge.net/git/gitweb.cgi?p=pyjamas/pyjamas;a=commit;h=b3424c5616899394260027997526fe79b2daaf63

http://pyjamas.git.sourceforge.net/git/gitweb.cgi?p=pyjamas/pyjamas;a=commit;h=ef3c0e4e3fd819389b6e975f1736a3de407f08ec

It does not restrict imports from local namespaces tho, always importing into globals. Safer way is to either forbid local import-all (as it is done in python3), or at least raise NotImplemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment