-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Added type hints in utils package #964
Added type hints in utils package #964
Conversation
Finally got a chance to look this over a bit, thanks for helping out with this. I see there are a few TypeErrors to fix (https://github.com/Farama-Foundation/PettingZoo/actions/runs/4897571285/jobs/8745765176?pr=964):
|
Yeah I saw them, however they are only present in Python version <3.10, because all the tests for python 3.10 pass. Do you think I should substitute the | operator with Union? |
The | should work fine but you need to do from __futute__ import
annotations I believe (in other files we use those and they work fine)
…On Thu, May 11, 2023 at 10:49 AM Lorenzo Cavuoti ***@***.***> wrote:
Yeah I saw them, however they are only present in Python version <3.10,
because all the tests for python 3.10 pass. Do you think I should
substitute the | operator with Union?
For example, a: int | None -> a: Union[int, None]
—
Reply to this email directly, view it on GitHub
<#964 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHVPVA5LVUGJMRMBK4TDPQLXFT37ZANCNFSM6AAAAAAXXS3AA4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I imported annotations in all files apart from clip_out_of_bounds_wrapper which caused the error. Pushed the changes and now it all seems ok. I forgot to mention that I haven't added type hints to utils/conversions as I am not familiar with that part of the library and the code seems very complicated. |
Looks like all the comments are resolved, I’ll rise one final look through today but probably good to go. Would you mind making a separate PR changing the self state to be ndarray or any? Or I guess just any. I think I’ve seen something or any before as a way of suggesting but not enforcing |
Just pushed the last changes, I think we can close this PR as well. If I understand correctly, in subsequent PRs what remains to do is:
Should I open an issue as a reminder? Because I don't think I'll have time to do this till next weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor nitpicks but overall very good, thanks again for this it is very nice to have.
Description
Type hinted all python modules under pettingzoo/utils. Pyright pre-commit checks were disabled on specific lines of code because they gave an error. More details in screenshots section.
When adding type hints I spotted some bugs, so I also edited some lines of code.
Type of change
Screenshots
Error present even if we check attribute presence beforehand.
Same error but different way to check attribute presence. There are a few more errors like these, I won't show all of them here.
It says that
action
could be None, even if we perform a check at line 31.In this case
space
is an instance of gymnasium.spaces.Space that does not have .low and .high attributes. However, we check in__init__
that the action spaces are Box spaces which in turn have the .low and .high attributes.Checklist:
pre-commit
checks withpre-commit run --all-files
(seeCONTRIBUTING.md
instructions to set it up)pytest -v
and no errors are present.pytest -v
has generated that are related to my code to the best of my knowledge.