grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Cannot import module `struct`: Is a Golang reserved word #124

Closed alanjds closed 5 years ago

alanjds commented 5 years ago
$ grumpy -c 'import struct; print struct'
/var/folders/50/nxn5kg1125g6mfml3sm2qgvh0000gn/T/tmpU4QOxD__pycache__/gopath/src/__python__/__main__/module.go:4:2:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/__pycache__/struct.grumpy-022.pyc/gopath/src/__python__/struct/module.go:1:9: expected 'IDENT', found 'struct'
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/__pycache__/struct.grumpy-022.pyc/gopath/src/__python__/struct/module.go:2:1: expected ';', found 'import'
$ head /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/__pycache__/struct.grumpy-022.pyc/gopath/src/__python__/struct/module.go
package struct
...

As saw on Go specs, the following keywords are not allowed:

The following keywords are reserved and may not be used as identifiers.

break        default      func         interface    select
case         defer        go           map          struct
chan         else         goto         package      switch
const        fallthrough  if           range        type
continue     for          import       return       var

If a module named as it got transpiled its package cannot be named as such.