srush / Tensor-Puzzles

Solve puzzles. Improve your pytorch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with python 3.9 due to change in behavior of typing.get_type_hints

dakinggg opened this issue · comments

It seems that between 3.8 (https://docs.python.org/3.8/library/typing.html#typing.get_type_hints) and 3.9 (https://docs.python.org/3.9/library/typing.html#typing.get_type_hints), the argument include_extras was added to get_type_hints, and it defaults to False, but the behavior in 3.8 was as if the argument was True. It appears that using x.__annotations__ instead of

gth = typing.get_type_hints(x)
works with both python versions, but I can't totally verify since I haven't done all the puzzles and don't totally understand the testing setup.

The error I get on 3.9 without any modifications is

test_puzzles.py:287: in <module>
    run_test(test_sum)
test_puzzles.py:191: in run_test
    fn()
test_puzzles.py:171: in test_problem
    def test_problem(d):
test_puzzles.py:165: in spec
    ret["return"][:] = 0
E   KeyError: 'return'

and appears to be a result of this line of the documentation for get_type_hints:

The function recursively replaces all Annotated[T, ...] with T, unless include_extras is set to True

Thanks for the puzzles!

Ah thanks. I willl update.

Should be fixed now.