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

GH-132445: Allowing to reset parameters of Wave_write#132448

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

Open
ygerlach wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromygerlach:wave_parameters

Conversation

ygerlach
Copy link

@ygerlachygerlach commentedApr 12, 2025
edited by bedevere-appbot
Loading

This allows to re-set a parameter of Wave_write to the same value without causing anError. This allows to implemet repeated writes to a wav file without special care for the first write.

@python-cla-bot
Copy link

python-cla-botbot commentedApr 12, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

I'm still not convinced but in any case, if this feature is to be accepted, we need tests and a NEWS entry, as well as a doc change.

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ygerlach
Copy link
Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-appbedevere-appbot requested a review frompicnixzApril 30, 2025 16:26
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

TBH, I am neutral on this addition. I can understand that it's annoying for people passing around wave objects and forcibly changing the parameters, but OTOH I still believe it's incorrect to forcibly reset a parameter even if it's the same. Users should instead check thecurrent value itself, and if it's not yet set, they should wrap it in atry-except call.

To ease their life, we could however expose the number of bytes that were already written so that they don't need a try-except but just something like:

ifself.has_data:assertself.getnchannels()==EXPECT_NCHANNELSelse:self.setnchannels(EXPECT_NCHANNELS)

It could be annoying but I think it's more an API misuse rather an API flaw. For your use case, I think the correct way to do it is to usesynthesize_stream_raw() or to have amerge_and_synthesize function which

forsinpiper.synthesize_stream_raw(...):wav_file.writeframes(s)

So, while I have reviewed your code, I don't really think we'll make the change in the stdlib itself. Another reason is that it makes maintainability harder (if we add more setters in the future, it could be annoying if some values are inter-dependent as well).

@serhiy-storchaka should decide whether or not we accept this change.

@@ -198,11 +198,20 @@ Wave_write Objects

Set the number of channels.

Raises an :exc:`wave.Error`, if the value is set after data was written.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Raises an:exc:`wave.Error`, ifthe value is set after data was written.
Raise:exc:`wave.Error` ifa different value is set after data was written.

Comment on lines +203 to +204
.. versionchanged:: 3.14
:exc:`wave.Error` is not raised, if the value is the same.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
..versionchanged::3.14
:exc:`wave.Error` isnotraised, if the valueis the same.
..versionchanged::next
No:exc:`wave.Error` is raised if the valuedoes not change.

Same for the rest of the docs.

Comment on lines +174 to +176
writer.setnchannels(2)
writer.setsampwidth(2)
writer.setframerate(2)
Copy link
Member

Choose a reason for hiding this comment

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

We also need to test rounded values.

@@ -502,27 +502,28 @@ def getsampwidth(self):
return self._sampwidth

def setframerate(self, framerate):
if self._datawritten:
rounded_framerate = int(round(framerate))
Copy link
Member

Choose a reason for hiding this comment

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

Theint(round(framerate)) should be tested when two distinct input framerates give the same rounded framerate.

raise Error('cannot change parameters after starting to write')
ifframerate <= 0:
ifrounded_framerate <= 0:
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that before this change we could writeself.setframerate(0.5) and the framerate would be set to 0. With this change, we prevent a bad framerate.

So also test thatself.setframerate(0.5) raises an exception, but notself.setframerate(0.51).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz requested changes

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@ygerlach@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp