Bugs in CPython 3.1.1 [wave.py]

A

Alf P. Steinbach

Argh! This was really annoying! Much time wasted (one naturally thinks that
silly error must be one's own).

But, anyway:

Lines:

244 nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
464 self._nframes = initlength / (self._nchannels * self._sampwidth)

Need to use Python 3.x "//" integer division.

As a workaround, at least for writing wav-files (I haven't tested reading), one
may just set the number of frames exactly before writing them.

That should also fix any problems with piping (avoiding file pos seek to patch
up header).

Also, the unit test should best be improved to check that updating and
backpatching of number of frames actually works.


PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this. Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere. But hopefully it doesn't?


Cheers & hth.,

- Alf
 
T

Terry Reedy

Argh! This was really annoying! Much time wasted (one naturally thinks
that silly error must be one's own).

But, anyway:

Lines:

244 nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
464 self._nframes = initlength / (self._nchannels * self._sampwidth)

Need to use Python 3.x "//" integer division.

As a workaround, at least for writing wav-files (I haven't tested
reading), one may just set the number of frames exactly before writing
them.

That should also fix any problems with piping (avoiding file pos seek to
patch up header).

Also, the unit test should best be improved to check that updating and
backpatching of number of frames actually works.

This is a little used module that I did not even recognize. Many of the
library modules need more tests.
PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this. Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?

Asking about possible bugs here is fine. The above looks like one. One
can report at bugs.python.org. Yes, registration is needed so that you
give a name that people can recognize and an email to receive replies
and questions at. And to discourage spam on the tracker, which sometimes
slips through anyway when a spam person (rather than machine) bothers to
register.
 
C

Chris Withers

Alf said:
PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this.
http://tinyurl.com/yemcdy7

Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere.

Of course that means no-one else will know about the problem, and no-one
who can fix this problem will find out about it...

Chris
 
S

Steve Holden

Alf P. Steinbach wrote:
[...]
PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this. Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?
That's not very public-spirited, is it? Python is open source, remember.
You wouldn't be able to use it if Guido had said "you know, I'm just
going to write this language for myself. It's so much trouble building a
development community ..."

Give a little something back - create the account, and log the bug. I
promise you'll feel better about yourself ;-)

regards
Steve
 
A

Alf P. Steinbach

* Steve Holden:
Alf P. Steinbach wrote:
[...]
PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this. Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?
That's not very public-spirited, is it? Python is open source, remember.
You wouldn't be able to use it if Guido had said "you know, I'm just
going to write this language for myself. It's so much trouble building a
development community ..."

Give a little something back - create the account, and log the bug. I
promise you'll feel better about yourself ;-)

"You will shortly receive an email to confirm your registration. To complete the
registration process, visit the link indicated in the email."

Yeah, still waiting...

And I don't feel better. :-(

Oh, mail arriving!

Bah, no, t'was from my travel company.


Cheers,

- Alf
 
A

Alf P. Steinbach

* Alf P. Steinbach:
* Steve Holden:
Alf P. Steinbach wrote:
[...]
PS: It would be nice if someone(TM) could describe here in detail how to
properly report errors like this. Of course I'm not going to do it if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?
That's not very public-spirited, is it? Python is open source, remember.
You wouldn't be able to use it if Guido had said "you know, I'm just
going to write this language for myself. It's so much trouble building a
development community ..."

Give a little something back - create the account, and log the bug. I
promise you'll feel better about yourself ;-)

"You will shortly receive an email to confirm your registration. To
complete the registration process, visit the link indicated in the email."

Yeah, still waiting...

And I don't feel better. :-(

Oh, mail arriving!

Bah, no, t'was from my travel company.

Hm, similar to Google's feedback forms this, just cul de sac: still no mail!

Trying registration again...

For perhaps I wrote incorrect mail address? No. Correct. Anyway...

"Your request is being processed. Please be patient."

Well how f*****g darn patient do they expect me to be?

I've decided: I'm not.

Oh sh**, just as I typed the period above the mail finally arrived. It's been,
let's see, about 20+ minutes!

And still some miles to go.

Somebody should say THANK YOU for all this effort, pointing out not just the bug
but exactly what needs fixing, not whining about me not wasting half an hour on
going through proper channels after already wasting much time on that bug!


- Alf (grumble)
 
S

Stefan Behnel

Alf P. Steinbach, 12.01.2010 12:51:
Well how f*****g darn patient do they expect me to be?

I've decided: I'm not.

Oh sh**, just as I typed the period above the mail finally arrived. It's
been, let's see, about 20+ minutes!

And still some miles to go.

Somebody should say THANK YOU for all this effort, pointing out not just
the bug but exactly what needs fixing, not whining about me not wasting
half an hour on going through proper channels after already wasting much
time on that bug!

Maybe you should just stop using the module. Writing the code yourself is
certainly going to be faster than reporting that bug, don't you think?

Stefan
 
A

Alf P. Steinbach

* Stefan Behnel:
Alf P. Steinbach, 12.01.2010 12:51:

Maybe you should just stop using the module. Writing the code yourself
is certainly going to be faster than reporting that bug, don't you think?

It's part of the standard Python distribution.

Don't you think bugs in the standard library should be fixed?

Anyways, is there any alternative for wave output in Windows except writing the
thing from scratch?


Cheers,

- Alf
 
S

Stefan Behnel

Alf P. Steinbach, 12.01.2010 13:10:
* Stefan Behnel:

It's part of the standard Python distribution.

Don't you think bugs in the standard library should be fixed?

Sure. I was just emphasizing the fact that it might be a larger
contribution to write such a module in the first place than to fix a bug in
it. The mere fact that the existing module seems valuable enough for you to
want to use it suggests that the effort that you are putting into getting
your bug fixed in the mainline distribution is worth it.

Stefan
 
S

Steven D'Aprano

Oh sh**, just as I typed the period above the mail finally arrived. It's
been, let's see, about 20+ minutes!

Aren't you a little old to be suffering from the every decreasing
attention spans of the MTV generation? Email is not guaranteed to be
delivered at all, let alone instantly, and can on occasion be delayed by
days. A twenty minute delay is nothing to get cranky about.

Perhaps you should check the email headers to see where the delay was.
You're not using grey-listing by any chance are you?

Somebody should say THANK YOU for all this effort, pointing out not
just the bug but exactly what needs fixing, not whining about me not
wasting half an hour on going through proper channels after already
wasting much time on that bug!

You know the licence fees that you didn't pay for Python?

You know the thousands of dollars in yearly maintenance fees from the
vendor you didn't pay?

If you *had* paid them, do you think you'd be receiving any better
service? In my experience, I'd say that your ability to report bugs, let
alone patches that fix those bugs, would be even less with most
proprietary software.

So, with the greatest respect, and with a sense of sympathy for the
frustration you're feeling (as we all have, at times), I'd like to
suggest you stop your belly-aching and accept that even the best
libraries sometimes have bugs in them. You should be thankful that the
least you have had to pay is a few minutes to report a bug and 20 minutes
waiting for a confirmation email.

But in any case, even though I don't have any need for the module in
question, I'd like to thank you for taking the time to write a patch and
submit it. Without contributions like that, open source software would be
unable to thrive as it does.
 
A

Alf P. Steinbach

* Stefan Behnel:
Alf P. Steinbach, 12.01.2010 13:10:

Sure. I was just emphasizing the fact that it might be a larger
contribution to write such a module in the first place than to fix a bug
in it.

I'm not interested in credits.

But regarding contributions to the programming community I've done my share,
including writings and moderating [comp.lang.c++.moderated]. I do not feel I've
done too little and I almost take offense at that suggestion.

The mere fact that the existing module seems valuable enough for
you to want to use it suggests that the effort that you are putting into
getting your bug fixed in the mainline distribution is worth it.

Well, this is for my Python (actually, beginning programmer) writings, at

http://tinyurl.com/programmingbookP3

(I hope I spelled that right), which is why it "has" to use standard library
functionality only, and why implementing the thing from scratch is not an option
-- otherwise, if this was something I needed, I'd probably do that.

It's just to have a concrete real world example of modular arithmetic and two's
complement representation.

The example code looks like this, so far -- might of course be of help to
others :)


<code file="simple_wave.py">
"Lets you generate simple mono (single-channel) [.wav] files."
import wave
import array
import math

default_sample_rate = 44100 # Usual CD quality.

def sample_square( freq, t ):
linear = freq*t % 1.0
if linear < 0.5:
return -1.0
else:
return 1.0

def sample_sawtooth( freq, t ):
linear = freq*t % 1.0
if linear < 0.5:
return 4.0*linear - 1.0
else:
return 3.0 - 4.0*linear

def sample_sine( freq, t ):
return math.sin( 2*math.pi*freq*t )

def _append_int_to( a, i ):
if i < 0:
i = i + 65536
assert( 0 <= i < 65536 )
a.append( i % 256 )
a.append( i // 256 )

class Writer:
"Writes samples to a specified [.wav] file"
def __init__( self, filename, sample_rate = default_sample_rate ):
self._sample_rate = sample_rate
self._writer = wave.open( filename, "w" )
self._writer.setnchannels( 1 )
self._writer.setsampwidth( 2 ) # 2 bytes = 16 bits
self._writer.setframerate( sample_rate )
self._samples = []

def sample_rate( self ):
return self._sample_rate

def write( self, normalized_sample ):
assert( -1 <= normalized_sample <= +1 )
self._samples.append( normalized_sample )

def close( self ):
data = array.array( "B" ) # B -> unsigned bytes.
for sample in self._samples:
level = round( 32767*sample )
_append_int_to( data, level )
self._writer.setnframes( len( self._samples ) )
self._writer.writeframes( data )
self._writer.close()
</code>


<code file="ringtone.py">
import simple_wave

sample_rate = simple_wave.default_sample_rate
total_time = 2
n_samples = sample_rate*total_time

writer = simple_wave.Writer( "test.wav" )
for i in range( n_samples ):
t = i/sample_rate
samples = (
simple_wave.sample_sine( 440, t ),
simple_wave.sample_sawtooth( (3/2)*440, t ),
)
sample = sum( samples )/len( samples )
writer.write( sample )
writer.close()
</code>


Cheers & hth.,

- Alf
 
D

Daniel Fetchinson

PS: It would be nice if someone(TM) could describe here in detail how to
Hm, similar to Google's feedback forms this, just cul de sac: still no mail!

Trying registration again...

For perhaps I wrote incorrect mail address? No. Correct. Anyway...

"Your request is being processed. Please be patient."

Well how f*****g darn patient do they expect me to be?

I've decided: I'm not.

Oh sh**, just as I typed the period above the mail finally arrived. It's
been,
let's see, about 20+ minutes!

And still some miles to go.

Somebody should say THANK YOU for all this effort, pointing out not just the
bug
but exactly what needs fixing, not whining about me not wasting half an hour
on
going through proper channels after already wasting much time on that bug!

Thanks to this 100% true statement from Brett Cannon there is an easy
way to get rid of your disappointment:


"""
If you are doing open source for anything other than altruistic
reasons you are bound to be disappointed.
"""

HTH,
Daniel
 
A

André

Well, this is for my Python (actually, beginning programmer) writings, at

   http://tinyurl.com/programmingbookP3

Thanks for writing this book. I just had a quick look at the
beginning of it where you write:
===
As of this writing two main variants of the Python language are in
use, namely
Python 2.x and Python 3.x (versions 3.0 and greater). Mostly they’re
the same but the
effect of e.g. the / division operator changed in 3.0, so in practice
it’s hopeless to try
to create programs that work the same – or even just work – with both
variants.
===
Notwithstanding your experience (finding a bug in wave.py), this
statement is false. There are plenty of non-trivial applications that
have been ported so that they work "as is" with both Python 2.x and
Python 3.x. If you do a google search, I am sure that you can find
many examples proving this point. For example, you may want to read:
http://mail.mems-exchange.org/durusmail/qp/441/ .... or try out
Crunchy (http://code.google.com/p/crunchy). It may be required to
isolate some small parts and do conditional imports ... but this is
fairly straightforward to do if one writes a new application.

André
 
S

Steve Holden

Alf said:
* Alf P. Steinbach:
* Steve Holden:
Alf P. Steinbach wrote:
[...]
PS: It would be nice if someone(TM) could describe here in detail
how to
properly report errors like this. Of course I'm not going to do it
if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?

That's not very public-spirited, is it? Python is open source, remember.
You wouldn't be able to use it if Guido had said "you know, I'm just
going to write this language for myself. It's so much trouble building a
development community ..."

Give a little something back - create the account, and log the bug. I
promise you'll feel better about yourself ;-)

"You will shortly receive an email to confirm your registration. To
complete the registration process, visit the link indicated in the
email."

Yeah, still waiting...

And I don't feel better. :-(

Oh, mail arriving!

Bah, no, t'was from my travel company.

Hm, similar to Google's feedback forms this, just cul de sac: still no
mail!

Trying registration again...

For perhaps I wrote incorrect mail address? No. Correct. Anyway...

"Your request is being processed. Please be patient."

Well how f*****g darn patient do they expect me to be?

I've decided: I'm not.

Oh sh**, just as I typed the period above the mail finally arrived. It's
been, let's see, about 20+ minutes!

And still some miles to go.

Somebody should say THANK YOU for all this effort, pointing out not just
the bug but exactly what needs fixing, not whining about me not wasting
half an hour on going through proper channels after already wasting much
time on that bug!

Well, I can do the first bit. THANK YOU!

I am, however, confused by your description of "all this effort". I am
sorry you had to waste time running up against a bug in Python, but even
(?) Microsoft users have been known to complain about the non-responsive
nature of their vendor, and they have paid support contracts.

I am very grateful, as Chairman of the Python Software Foundation, that
you took the time to push this through to completion. I hope that even
if it took you half an hour (and I suspect you are counting the 20
minutes you spent waiting for an email, during which you should not have
been tied up by the bug reporting process, and could have done some
other task in parallel) I hope you will agree that the language has
saved you hundreds of times that in your career as a Python programmer.

Anyway, since I have doubtless already whined on too long for your
tastes, just let me say that I am interested in making the bug reporting
process *much* easier, especially for casual users. Sadly leaving a web
system open is no longer practical in this day and age, as there are
spambots that will fill up the database with rubbish in no time unless
we take precautions.

If you have any suggestions for improving things (and the same goes for
any other readers) I will be happy to listen to them. I do agree that
the bug tracker is a rather high hurdle for people to have to jump over
just to offer feedback on software faults, but the PSF doesn't have the
resources to man customer service lines and the like, so we do what we
can with web-based automation.

regards
Steve
 
S

Steve Holden

Alf said:
* Alf P. Steinbach:
* Steve Holden:
Alf P. Steinbach wrote:
[...]
PS: It would be nice if someone(TM) could describe here in detail
how to
properly report errors like this. Of course I'm not going to do it
if it
involves establishing Yet Another Account somewhere. But hopefully it
doesn't?

That's not very public-spirited, is it? Python is open source, remember.
You wouldn't be able to use it if Guido had said "you know, I'm just
going to write this language for myself. It's so much trouble building a
development community ..."

Give a little something back - create the account, and log the bug. I
promise you'll feel better about yourself ;-)

"You will shortly receive an email to confirm your registration. To
complete the registration process, visit the link indicated in the
email."

Yeah, still waiting...

And I don't feel better. :-(

Oh, mail arriving!

Bah, no, t'was from my travel company.

Hm, similar to Google's feedback forms this, just cul de sac: still no
mail!

Trying registration again...

For perhaps I wrote incorrect mail address? No. Correct. Anyway...

"Your request is being processed. Please be patient."

Well how f*****g darn patient do they expect me to be?

I've decided: I'm not.

Oh sh**, just as I typed the period above the mail finally arrived. It's
been, let's see, about 20+ minutes!

And still some miles to go.

Somebody should say THANK YOU for all this effort, pointing out not just
the bug but exactly what needs fixing, not whining about me not wasting
half an hour on going through proper channels after already wasting much
time on that bug!

Well, I can do the first bit. THANK YOU!

I am, however, confused by your description of "all this effort". I am
sorry you had to waste time running up against a bug in Python, but even
(?) Microsoft users have been known to complain about the non-responsive
nature of their vendor, and they have paid support contracts.

I am very grateful, as Chairman of the Python Software Foundation, that
you took the time to push this through to completion. I hope that even
if it took you half an hour (and I suspect you are counting the 20
minutes you spent waiting for an email, during which you should not have
been tied up by the bug reporting process, and could have done some
other task in parallel) I hope you will agree that the language has
saved you hundreds of times that in your career as a Python programmer.

Anyway, since I have doubtless already whined on too long for your
tastes, just let me say that I am interested in making the bug reporting
process *much* easier, especially for casual users. Sadly leaving a web
system open is no longer practical in this day and age, as there are
spambots that will fill up the database with rubbish in no time unless
we take precautions.

If you have any suggestions for improving things (and the same goes for
any other readers) I will be happy to listen to them. I do agree that
the bug tracker is a rather high hurdle for people to have to jump over
just to offer feedback on software faults, but the PSF doesn't have the
resources to man customer service lines and the like, so we do what we
can with web-based automation.

regards
Steve
 
S

Steve Holden

Alf said:
* Stefan Behnel:

It's part of the standard Python distribution.

Don't you think bugs in the standard library should be fixed?

Anyways, is there any alternative for wave output in Windows except
writing the thing from scratch?

For what it's worth, reporting the bug is the right decision. Had you
gone to the trouble of a rewrite and proposed your new module for the
standard library the first discovery you would have made is that nothing
gets accepted without a commitment of maintenance.

Clearly that would have been too much to accept when you merely wish to
correct a small-ish bug in an already satisfactory module.

Thanks again, and I hope the change gets into 3.2, and also the next 3.1
maintenance release. The only remaining requirement is some developer
time, but that is our scarcest resource.

regards
Steve

PS: Next time it would have helped to include a URL to the issue.

http://bugs.python.org/issue7681

FYI there is already some feedback in the tracker.
 
M

Malte Dik

I totally second Alf in this regard.

There were times you could report a bug by mail (to Debian e.g.) and it
worked perfectly (for me, the reporter).

Once I went into the maze of bug reporting software and I almost didn't find
back to the problem I tried to fix while stumbling upon the to-be-reported
bug.


My assumption is, that there's a reason why bug reporting software is so
pain-inducing. It's to make people enjoying fixing bugs, because it might be
easier compared to reporting them :D


Cheers!
 
A

Alf P. Steinbach

* André:
Thanks for writing this book. I just had a quick look at the
beginning of it where you write:
===
As of this writing two main variants of the Python language are in
use, namely
Python 2.x and Python 3.x (versions 3.0 and greater). Mostly they’re
the same but the
effect of e.g. the / division operator changed in 3.0, so in practice
it’s hopeless to try
to create programs that work the same – or even just work – with both
variants.
===
Notwithstanding your experience (finding a bug in wave.py), this
statement is false. There are plenty of non-trivial applications that
have been ported so that they work "as is" with both Python 2.x and
Python 3.x.

I'm sorry but your conclusion does not follow from the fact that you point out.

It is hopeless, especially for a newbie, to create correct Python 2.x+3.x
compatible code, except totally trivial stuff of course.

This due most of all to the language differences, but also to the fact that
there are PLENTY of libraries that haven't yet been ported, like PIL...

If you do a google search, I am sure that you can find
many examples proving this point. For example, you may want to read:
http://mail.mems-exchange.org/durusmail/qp/441/ .... or try out
Crunchy (http://code.google.com/p/crunchy). It may be required to
isolate some small parts and do conditional imports ... but this is
fairly straightforward to do if one writes a new application.

If it were straightforward then it wouldn't be darned difficult, would it?`:)

The problem isn't just writing code that runs with both Python languages.

The problem is writing code that is correct with both languages, which is
hopeless when e.g. integer division changes underfoot, like "/" meaning two
different things depending on the language, print syntax changing, so forth.


Cheers & hth.,

- Alf
 
A

Alf P. Steinbach

* Steve Holden:
For what it's worth, reporting the bug is the right decision. Had you
gone to the trouble of a rewrite and proposed your new module for the
standard library the first discovery you would have made is that nothing
gets accepted without a commitment of maintenance.

Clearly that would have been too much to accept when you merely wish to
correct a small-ish bug in an already satisfactory module.

Thanks again, and I hope the change gets into 3.2, and also the next 3.1
maintenance release. The only remaining requirement is some developer
time, but that is our scarcest resource.

regards
Steve

PS: Next time it would have helped to include a URL to the issue.

http://bugs.python.org/issue7681

FYI there is already some feedback in the tracker.

Yeah, someone who had the bright idea that maybe there isn't a bug, thinking
instead that maybe a "wrong" name in *a comment* might be the culprit -- of
all things!

He was probably just trying to be helpful.

But what do you say to someone who tries to help but is really just making a
mess of things? Obama tackled that nicely when he got Thorbjørned (Thorbjørn
Jagland applying some heavy pressure to give him the Nobel Peace Price). But I'm
not Obama...


Cheers,

- Alf
 
A

Alf P. Steinbach

* Steve Holden:
Alf P. Steinbach wrote:

If you have any suggestions for improving things (and the same goes for
any other readers) I will be happy to listen to them. I do agree that
the bug tracker is a rather high hurdle for people to have to jump over
just to offer feedback on software faults, but the PSF doesn't have the
resources to man customer service lines and the like, so we do what we
can with web-based automation.

Well, regarding the bug tracker register-an-account process, checking headers of
a duplicate confirmation mail that arrived even later than what I already
commented on,


Received: from mr1.start.no (unknown [195.159.73.42])
by mail6.start.no (Postfix) with ESMTP id 54EFE1534F8
for <[email protected]>; Tue, 12 Jan 2010 12:56:05 +0100 (CET)
Received: from psf.upfronthosting.co.za (bugs.python.org [88.198.142.26])
by mr1.start.no (Postfix) with ESMTP id B24C92B2035
for <[email protected]>; Tue, 12 Jan 2010 12:53:53 +0100 (CET)
Received: from psf.upfronthosting.co.za (localhost [10.0.0.1])
by psf.upfronthosting.co.za (Postfix) with ESMTP id AE98D786B3
for <[email protected]>; Tue, 12 Jan 2010 12:25:53 +0100 (CET)


As you can see the mail spent exactly 28 minutes (to the second) whirring about
within "psf.upfronthosting.co.za" before being sent on to my ISP, where it used
about 3 minutes on orienting itself towards my machine.

I think that mail hang-up may be easiest to fix...

Perhaps use other SMTP server (would be easiest solution).

Perhaps change to CAPTCHA instead of mail confirmation.

Other suggestions I have would, I think, require a lot of work. And I'm not sure
it's worth it. But my experience is that Google scores 0 on bug reporting, not
even allowing you to report anything, at all; Microsoft scores 8 or so, up from
1 on my scale (they used to have lead-you-around-in-circles forms leading to
punch-you-in-the nose server errors etc., like Google now, but worse because you
were paying for this!, but they totally changed their tune a few years back, now
really good, *except* for the worst most bloated MS software/malware ever, the
Microsoft installer, which unfortunately CPython uses, a light-weight installer
would be much better!); and then the GNU g++ team scores top marks, 10+, because
I've had a g++ bug reported and fixed within just hours! :)


Cheers,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top