srush / Tensor-Puzzles

Solve puzzles. Improve your pytorch.
MIT License
2.96k stars 242 forks source link

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

Closed dakinggg closed 2 years ago

dakinggg commented 2 years ago

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 https://github.com/srush/Tensor-Puzzles/blob/9635adab1d4d7283baff4675f22bcb45db8ca48e/test_puzzles.py#L133 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!

srush commented 2 years ago

Ah thanks. I willl update.

srush commented 2 years ago

Should be fixed now.