Possible typing issue in dict.py?
Could there be a typing declaration error in:
https://github.com/openai/gym/blob/53d784eafed28d31ec41c36ebd9eee14b0dc6d41/gym/spaces/dict.py#L15
Looking at the definition of class Space[T_cov],
https://github.com/openai/gym/blob/53d784eafed28d31ec41c36ebd9eee14b0dc6d41/gym/spaces/space.py#L24
the generic parameter T_cov denotes the type of values returned by the sample function:
https://github.com/openai/gym/blob/53d784eafed28d31ec41c36ebd9eee14b0dc6d41/gym/spaces/space.py#L90
which cannot be of Space type.
So, should the Dict class be defined instead as follows?
class Dict(Space[TypingDict[str, object]], Mapping):
or even better, if we could pass the dictionary value type as a generic parameter that would allow for proper type checking of the dictionary values, e.g.,:
_T_cov_dict= TypeVar("_T_cov_dict", covariant=True)
class Dict(Space[_T_cov_dict], Mapping):
Yes, the type hint is currently incorrect.
I would change the proposed type hint to Dict(Space[str, Any], Mapping[str, Space[Any]])
However even this is technically incorrect as the dictionary key doesn't need to be a string however we could ignore this in the type hint
@pseudo-rnd-thoughts did you mean Space[Any] instead of Space[str, Any]? (the Space class takes only one generic type parameter).
I meant Space[TypingDict[str, Any]]
Hi, I have implemented the changes suggested by @pseudo-rnd-thoughts and made a PR. Please Close this issue if it gets resolved by the PR, otherwise let me know if there are any changes. Thanks
Hi @maintainers , Please review my PR and merge it if it closes the issue, otherwise please let me know if any modifications are needed.
Hi, the PR looks good however, we are planning on reducing the number of accepted PRs to Gym due to some work behind the scenes that we are hoping to announce soon (in the next week hopefully)