[issue38281] "+" ignored when determining file mode in gzip.GzipFile.__init__

2019-09-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Yes, this is a breaking change, it will break the code that reads gzipped 
temporary files.

Note also that even if this change be accepted, you could not use this feature 
until Python 3.9 be released. But you can write to temporary files in all 
Python versions if specify an explicit mode.

So the benefit is small, but there is a risk of breaking existing code.

There is an opposite proposition: deprecate guessing the GzipFile mode 
(issue28286).

--
nosy: +serhiy.storchaka
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38281] "+" ignored when determining file mode in gzip.GzipFile.__init__

2019-09-25 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
pull_requests: +15986
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/16405

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38281] "+" ignored when determining file mode in gzip.GzipFile.__init__

2019-09-25 Thread __starrify__


New submission from __starrify__ :

Currently (as of df69e75) it checks only the initial letter (via 
`mode.startswith`) of "mode" in gzip.GzipFile.__init__. See also: 
https://github.com/python/cpython/blob/df69e75/Lib/gzip.py#L183

I'd personally suggest that it takes also "+" into consideration, which shall 
be regarded as writable.

One common (hm.. at least I've observed more than once recently) case where 
people may make mistakes is to use a tempfile.NamedTemporaryFile as the file 
object without specifying explicitly a mode, while expecting the GzipFile to be 
writable.

A quick example (in Python 3.7.11):
```
>>> import tempfile
>>> tempfile.NamedTemporaryFile().mode
'rb+'
>>> import gzip
>>> gzip.GzipFile(fileobj=tempfile.NamedTemporaryFile(mode='rb+')).writable()
False
>>> gzip.GzipFile(fileobj=tempfile.NamedTemporaryFile(mode='wb')).writable()
True
```

Unfortunately this change request may be backward-incompatible, since 
previously modes like "r+b" have been treated as read-only. See also: 
https://github.com/python/cpython/blob/df69e75/Lib/test/test_gzip.py#L464

--
components: Library (Lib)
messages: 353244
nosy: __starrify__
priority: normal
severity: normal
status: open
title: "+" ignored when determining file mode in gzip.GzipFile.__init__
type: enhancement
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com