go-python / go-python/gopy

Imported types not working properly

Đang mở
#303 0 bình luận 3 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
2.3k
Fork
136
Merge trung bình
14 phút
Pull request đã merge (30 ngày)
2

Mô tả

I'm trying to build a function which uses imported types as argument and as return type:

```go
package request

import "github.com/Danny-Dasilva/CycleTLS/cycletls"

func Request(method string, url string, options cycletls.Options) (cycletls.Response, error) {
client := cycletls.Init()

response, err := client.Do(url, options, method)

return Response(response), err
}
```

However, the python types are not being generated properly, so I get the following error when trying to pass a `cycletls.Options` to the `Request` function in python:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f5523f2a520]

goroutine 17 [running, locked to thread]:
main.request_Request(0xc00003e060?, 0x0?, 0x1?)
/home/matheus/tests/go-request/request/request.go:1881 +0xe0
Aborted
```

Here are the go types:

```go
type Options struct {
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Ja3 string `json:"ja3"`
UserAgent string `json:"userAgent"`
Proxy string `json:"proxy"`
Cookies []Cookie `json:"cookies"`
Timeout int `json:"timeout"`
DisableRedirect bool `json:"disableRedirect"`
HeaderOrder []string `json:"headerOrder"`
OrderAsProvided bool `json:"orderAsProvided"`
}

type Response struct {
RequestID string
Status int
Body string
Headers map[string]string
}
```

And here are the generated python types:

```python
# Python type for cycletls.Options
class cycletls_Options(GoClass):
""""""
def __init__(self, *args, **kwargs):
"""
handle=A Go-side object is always initialized with an explicit handle=arg
"""
if len(kwargs) == 1 and 'handle' in kwargs:
self.handle = kwargs['handle']
_request.IncRef(self.handle)
elif len(args) == 1 and isinstance(args[0], GoClass):
self.handle = args[0].handle
_request.IncRef(self.handle)
elif len(args) == 1 and isinstance(args[0], int):
self.handle = args[0]
_request.IncRef(self.handle)
else:
self.handle = 0
def __del__(self):
_request.DecRef(self.handle)

# Python type for cycletls.Response
class cycletls_Response(GoClass):
""""""
def __init__(self, *args, **kwargs):
"""
handle=A Go-side object is always initialized with an explicit handle=arg
"""
if len(kwargs) == 1 and 'handle' in kwargs:
self.handle = kwargs['handle']
_request.IncRef(self.handle)
elif len(args) == 1 and isinstance(args[0], GoClass):
self.handle = args[0].handle
_request.IncRef(self.handle)
elif len(args) == 1 and isinstance(args[0], int):
self.handle = args[0]
_request.IncRef(self.handle)
else:
self.handle = 0
def __del__(self):
_request.DecRef(self.handle)
```

As a workaround, I was able to make it work by redefining the types in my go package, but it is a bit annoying, since I have to redefine the subtypes in `cycletls.Options` and rebuild the struct inside the function.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Start at the Go Request entry point in request/request.go around line 1881 and compare the generated cycletls_Options and cycletls_Response wrappers with the imported Go structs shown in the issue. Reproduce the call using imported cycletls.Options and identify why it reaches a nil pointer. Done means imported types can be passed to Request without redefining them in the local Go package.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go, python
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.