Fix FileBasedBuffer (and ReadOnlyFileBasedBuffer) to act more like iterators #82

Merged
merged 4 commits into from Mar 16, 2016

Projects

None yet

2 participants

@bertjwregeer
Member

FileBasedBuffer is the parent class for a variety of sub-classes,
including ReadOnlyFileBasedBuffer. Since FileBasedBuffer can be used as
an app_iter return (and by extension it's sub-classes can as well) it
should probably behave more like an iterator, and the file returned from
open().

Even if an iterator contains no more objects, calling bool() will still
return True, in the case of FileBasedBuffer this is not true until this
fix.


Without this fix, if an application calls a second WSGI application that
returns an wsgi.file_wrapper (aka ReadOnlyFileBasedBuffer) they can't
simply test to see if the application returned a valid iterator or not
by testing it's truthiness.

This is documented in bug report: #76

While one could argue that testing the truthiness of a return from an
WSGI application is the wrong thing to do, I would argue that an
iterator like object should not return False when tested with bool.
bool(iter([])) == True after all.

Fixes: #76

bertjwregeer added some commits Feb 7, 2015
@bertjwregeer bertjwregeer Remove __nonzero__ and bool from FileBasedBuffer
FileBasedBuffer is the parent class for a variety of sub-classes,
including ReadOnlyFileBasedBuffer. Since FileBasedBuffer can be used as
an app_iter return (and by extension it's sub-classes can as well) it
should probably behave more like an iterator, and the file returned from
open().

Even if an iterator contains no more objects, calling bool() will still
return True, in the case of FileBasedBuffer this is not true until this
fix.

----

Without this fix, if an application calls a second WSGI application that
returns an wsgi.file_wrapper (aka ReadOnlyFileBasedBuffer) they can't
simply test to see if the application returned a valid iterator or not
by testing it's truthiness.

This is documented in bug report:
Pylons#76

While one could argue that testing the truthiness of a return from an
WSGI application is the wrong thing to do, I would argue that an
iterator like object should not return False when tested with bool.
bool(iter([])) == True after all.
7be6c83
@bertjwregeer bertjwregeer Fix test for __bool__ 18a0893
@bertjwregeer bertjwregeer Add changelog entry b39a287
@mmerickel
Member

LGTM I could go either way but it seems harmless to change this.

@bertjwregeer bertjwregeer added a commit to bertjwregeer/waitress that referenced this pull request Mar 16, 2016
@bertjwregeer bertjwregeer Merge branch 'fix/app_iter_falsy'
Closes pr #82
ee3efc9
@bertjwregeer bertjwregeer merged commit ef5a1a2 into Pylons:master Mar 16, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment