Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add__new__ and__init__ functions for some types#3001

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ankith26 merged 5 commits intopygame:mainfromzoldalma999:fix-function-classes
Feb 13, 2022

Conversation

@zoldalma999
Copy link
Contributor

As per#2867, I added__init__ and/or__new__ to the following classes:

  • Event
  • Clock
  • Channel

I also documented that Joysticks do not have these functions and can only be opened trough thepygame.joystick.Joystick function.
PixelArray seemed to have already exported it's class properly. I did not want to touch the Camera class, since I do not have a camera to test with.

Starbuck5 and ankith26 reacted with heart emojiStarbuck5 and ankith26 reacted with rocket emoji
@Starbuck5
Copy link
Contributor

Why not make Joystick a class like the rest? Seems simpler and prettier than dealing with JoystickTypes all over the place.

Would it be better for Clock to have an__init__ and a generictp_new rather than a "new" factory function, likeEvent andChannel?

To get rid of the failing setup.py lint CI, you can runsetup.py format, which black and clang-format installed.

@zoldalma999
Copy link
ContributorAuthor

I got my hands on a linux laptop with a builtin webcam, so I did that one as
well. I was still not able to test it on windows, so it would be nice if
someone could double check if everything is working as it should.

Why not make Joystick a class like the rest? Seems simpler and prettier than
dealing with JoystickTypes all over the place.

Because the joystick function does not always always construct a new object, but
might return an already created one. I was not sure how to implement that,
without changing a lot of code, and possibly breaking some things.

Would it be better for Clock to have an__init__ and a generic tp_new
rather than a "new" factory function, like Event and Channel?

You are right, I changed it.

To get rid of the failing setup.py lint CI, you can run setup.py format,
which black and clang-format installed.

Ah. Yeah, I forgot to do it again.

Copy link
Contributor

@ankith26ankith26 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the PR! 👍 🎉
(PS: lint is still failing 😅)

@Starbuck5
Copy link
Contributor

Starbuck5 commentedFeb 3, 2022
edited
Loading

Because the joystick function does not always always construct a new object, but
might return an already created one. I was not sure how to implement that,
without changing a lot of code, and possibly breaking some things.

We could override__new__ to return the new or old instance?

I don't want to merge this in with the current JoystickType documentation changes, because it makes it seem more complex and exposes that type as part of our API, when we might not want that.

I'd prefer the joystick status quo.

Everything else looks good, but I'll be sure to test webcam on Windows.[It still works]

For the failing format status, you can rebase the branch against main. It's because black updated, and so now all the in progress branches will potentially get a few unrelated changes. But novial put through a PR that fixes it in main, if you can rebase.

@ankith26
Copy link
Contributor

I don't really prefer status quo, I prefer things documented as accurate to the implementation as possible. We could also investigate implementingJoystick.__new__, I believe if the type is immutable, there should be no problem if__new__ returns a new reference to an existing object

@Starbuck5
Copy link
Contributor

Starbuck5 commentedFeb 3, 2022
edited
Loading

@ankith26 I have to confess my objection originally stems from it making the docs ugly.

But we haven't gotten any issues with the status quo, unlike the Event status quo which kicked off this PR.

If we haven't decided to go with JoystickType or turn Joystick into a class of its own, it shouldn't be merged with the rest of this PR. I believe everything else is good.

@illume
Copy link
Member

Sorry, there's a conflict now with _camera.c because I merged another PR.

Copy link
Contributor

@Starbuck5Starbuck5 left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks!

This is one of those things that future contributors will never think of but will help them out. Because of course the objects are objects, not functions. Why would they be functions? 😄

One sorta suspicious thing I found is that PyChannel_New is still around and used, and the new channel_init has copied the same routines. Just in case one of them is changed in the future, that could trip someone up. Maybe add a comment? What do you think?

Is Event() now the preferred way? Should the docs assert that?

I've tested this locally and it works.

Anyways, this PR is good to go code wise, AFAICT, there's a couple things to think about, but it could be merged without that. There's also conflicts now (probably from my PRs sorry)

@illumeillume added eventpygame.event mixerpygame.mixer timepygame.time camerapygame.camera docs bug typesType hint checking related tasks labelsOct 29, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

2 more reviewers

@ankith26ankith26ankith26 approved these changes

@Starbuck5Starbuck5Starbuck5 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

bugC codeInvolves changing C codecamerapygame.cameradocseventpygame.eventmixerpygame.mixertimepygame.timetypesType hint checking related tasks

Projects

None yet

Milestone

2.1.3

Development

Successfully merging this pull request may close these issues.

4 participants

@zoldalma999@Starbuck5@ankith26@illume

[8]ページ先頭

©2009-2025 Movatter.jp