Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circular import #8

Open
Wouimbly opened this issue Feb 15, 2024 · 2 comments
Open

circular import #8

Wouimbly opened this issue Feb 15, 2024 · 2 comments
Assignees

Comments

@Wouimbly
Copy link

Hi!
just tried your wrapper it seems that there is circular import...
ImportError: cannot import name 'TypedDict' from partially initialized module 'typing_extensions' (most likely due to a circular import)

i'm running Python 3.12.2 on win10...
thanks

@0xTaoDev
Copy link
Owner

Hello, can you share your code where you are importing Python modules? thanks

@Wouimbly
Copy link
Author

Pretty weird that the first call worked then now i'm getting the error...
Here is my setup:
-windows10
-python version and installation path: C:\Python312
-pip install jupiter-python-sdk
-pip install asyncio
-complete error stack:
C:\Temp\pyjupswapper>python swapper.py
Traceback (most recent call last):
File "C:\Temp\pyjupswapper\swapper.py", line 5, in
from solders import message
File "C:\Python312\Lib\site-packages\solders_init_.py", line 25, in
from . import system_program, sysvar
File "C:\Python312\Lib\site-packages\solders\system_program.py", line 2, in
from typing_extensions import Final, TypedDict
File "C:\Python312\Lib\site-packages\typing_extensions.py", line 5, in
import inspect
File "C:\Python312\Lib\inspect.py", line 151, in
import linecache
File "C:\Python312\Lib\linecache.py", line 11, in
import tokenize
File "C:\Python312\Lib\tokenize.py", line 35, in
from token import *
File "C:\Temp\pyjupswapper\token.py", line 6, in
from solana.rpc.async_api import AsyncClient
File "C:\Python312\Lib\site-packages\solana\rpc\async_api.py", line 64, in
from solana.rpc import types
File "C:\Python312\Lib\site-packages\solana\rpc\types.py", line 5, in
from typing_extensions import TypedDict
ImportError: cannot import name 'TypedDict' from partially initialized module 'typing_extensions' (most likely due to a circular import) (C:\Python312\Lib\site-packages\typing_extensions.py)

command: python swapper.js

content of swapper.js:
import base58
import base64
import json

from solders import message
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction

from solana.rpc.types import TxOpts
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Processed

from jupiter_python_sdk.jupiter import Jupiter

import asyncio

private_key = Keypair.from_bytes(base58.b58decode("myKEY"))
async_client = AsyncClient("myRPC")
jupiter = Jupiter(async_client, private_key)

async def swap():
transaction_data = await jupiter.swap(
input_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
output_mint="So11111111111111111111111111111111111111112",
amount=300_000,
slippage_bps=100,
)
# Returns str: serialized transactions to execute the swap.
raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature])
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
transaction_id = json.loads(result.to_json())['result']
print(f"Transaction sent: https://explorer.solana.com/tx/{transaction_id}")

if name == "main":
asyncio.run(swap())

@0xTaoDev 0xTaoDev self-assigned this Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants