py.RunFile / RunCode doesn't handle a nil module pointer
- Linguagem predominante
- Go
- Estrelas
- 1k
- Forks
- 105
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embeddable scripting language.
I just noticed that `py.RunFile()` and `py.RunCode()` don't handle a `nil` `py.Module` pointer when deciding to create a new module. I feel like that would lessen the friction on using it, since if you run multiple files and want them to be in a single module you currently have to call two different `RunFile() / RunCode()` calls that are essentially the same (just with `nil` as the `inModule` argument the first time).
Basically, currently I'm doing this:
```go
var mod *py.Module
...
// In a for loop for mutliple .py files
if mod == nil {
mod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, nil) // Returns a new module
} else {
mod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, mod) // Adds onto the existing one
}
```
and it would be easier to just do this:
```go
var mod *py.Module
...
mod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, mod) // Returns a new module on first run because 'mod' is nil, adds onto the existing module afterwards
```
I believe to implement this I would just need to modify `RunCode()` to check for `nil` in the `case *Module` part of the inModule type check. Does this sound OK?
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Comece por RunCode e seu caso *Module handling, depois verifique como RunFile delega a ele. Verifique se um módulo nil cria um módulo na primeira chamada e se as chamadas posteriores a RunFile ou RunCode continuam usando-o; confirme o comportamento com os testes relevantes existentes.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- go, python
- Domínio
- api, compilers
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 58/100