-
Notifications
You must be signed in to change notification settings - Fork 646
from x import y: y can only be a module, not any old attribute #99
Comments
Thanks for reporting this. This is a limitation of the current import system: you can only import whole modules not individual members from the module. The reason is for the statement I've added this to the missing features list. |
Can not use Python's own modules? |
Modules work, but you must name a module, not it's members in a 'from
package import x'.
|
I think that is intentional because of Google style guide prohibit it according to this.
May be worth to mention somewhere in docs? |
Modules being imported are now detected at compile time. So it's possible to determine whether "from x import y" is importing module y or a member y of module x. This change uses this capability to choose whether to import a module or a member. This fixes google/grumpy#99
Importing certain classes or other objects from packages results in packages not found. E.g.
os.path
works just fine (from os import path
), becausebuild/src/os/path
exists, but many packages (I came acrossmath
andcollections
) are implemented in a single Go file, so things likefrom math import pi
orfrom collections import defaultdict
will fail like this:Importing the package as a whole works just fine:
Maybe I'm missing something. I'm running b730a44.
The text was updated successfully, but these errors were encountered: