cowprotocol / solver-template-py

A hollow framework for a CoW Protocol solver
MIT License
39 stars 25 forks source link

TypeError: 'type' object is not subscriptable #21

Closed witwiki closed 2 years ago

witwiki commented 2 years ago

A Type Error occur because of:

TokenDict = dict[Token, TokenInfo]

Consider assigning dummy variables when defining them?

Solution: https://stackoverflow.com/questions/26920955/typeerror-type-object-is-not-subscriptable-when-indexing-in-to-a-dictionary

bh2smith commented 2 years ago

Thanks for reporting. Could you also give example input where this happened? It would be a lot easier to check, fix and test the solution.

witwiki commented 2 years ago

Yes, sorry about that.

This was in ./src/models/token.py line 126.

I actually didn't do anything in particular. I just ran the code as per the instructions in the README.md under this repo.

Once I activated by venv as per the instructions, I ran python -m src._server under the Run Solver Server heading.

Once I ran this, it gave me the below output

File "/home/witwiki/GitHub/solver-template-py/src/models/token.py", line 126, in <module>
    TokenDict = dict[Token, TokenInfo]
TypeError: 'type' object is not subscriptable
bh2smith commented 2 years ago

Right but can you reproduce this with example input? I would love to have the input that caused this. Anyway I will take a look. Have you modified the code at all from the cloned repo? Because this looks more like a syntax error.

Actually it looks like you might be using a python version older than, say 3.7... could this be?

bh2smith commented 2 years ago

Yes, I am like 99% sure you are using an old version of python that does not support Type Declarations. Please ensure that you are using a python version >= 3.9 (as stated in the readme requirements).

If you don't want to deal with managing your own python environments, I would suggest using the docker instructions instead.

bh2smith commented 2 years ago

Also - see this answer in the stack exchange thread linked in issue description.