Skip to content
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

Some type hint and examples fixes #1817

Merged
merged 5 commits into from May 21, 2020
Merged

Some type hint and examples fixes #1817

merged 5 commits into from May 21, 2020

Conversation

MightyJosip
Copy link
Contributor

@MightyJosip MightyJosip commented May 19, 2020

  • Added type hints for operators for pygame.Color and pygame.math.Vector
  • Fixed pygame.event type hints
  • Fixed types in pygame.font (bool -> int)
  • Fixed pygame.draw accepting string objects as color argument (it was added in Fuzzy color matching in all functions. Example: fill('green'), or fill('#00FF00') instead of fill(Color('green')) #1676, around the same time I did type hints so it wasn't in sync)
  • Fixed Sound constructor keywords
  • Fixed syntax error in pygame.version
  • Added flag if the class is hashable
  • Fixed scrap_clipboard.py example (You can start it at least now, it doesn't work because pygame2 doesn't support scrap module)
  • Fixed testsprite.py example

NOTE: If you use PyCharm you won't be able to see the changes with hashable/unhashable types, haven't checked if mypy recognize it, but I used example from python/typing#74 (ok just checked mypy and it also doesn't accept hash = None as non hashable object)

@MyreMylar
Copy link
Contributor

Oops, guess I missed out some ...'s in that version.py.

What's the deal with the bool to int font changes? They would seem to be inconsistent with the docs e.g. here:

https://www.pygame.org/docs/ref/font.html#pygame.font.Font.set_bold

Is this a case of the underlying c code using ints and not casting back to python's bool type?

@MightyJosip
Copy link
Contributor Author

MightyJosip commented May 19, 2020

Docs are wrong (at least when I tested those functions)

@MightyJosip MightyJosip marked this pull request as draft May 20, 2020 07:52
@MightyJosip MightyJosip marked this pull request as ready for review May 20, 2020 11:21
@MyreMylar
Copy link
Contributor

Looked over the changes and then tried it out in pygame_gui and it all seems to work well with the PyCharm inspection.

Looks like type checkers don't care actually about passing a bool into an int - though it is slightly confusing for the auto complete hints.

I think this should be merged and we can figure out any ints that should be bools later.

@MyreMylar MyreMylar added reviewed For a Pull Request that's been reviewed at least once. and removed needs-review labels May 20, 2020
@MightyJosip
Copy link
Contributor Author

Looks like type checkers don't care actually about passing a bool into an int - though it is slightly confusing for the auto complete hints.

This is because of numeric object "hierarchy". Basically it goes like float -> int -> bool -> None. So for example type hint for float will accept float, int, bool and None, int will also accept bool and None...

Copy link
Member

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 👍

@illume illume merged commit f439234 into pygame:master May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewed For a Pull Request that's been reviewed at least once.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants