[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-04 Thread Wolfgang Maier

Wolfgang Maier added the comment:

the new test:

test_exc('%x', '1', TypeError, %x format: a number is required, not str)

expects the wrong error message.

python -m unittest -v test.test_format

...
'%x' % '1' works? ... no
Unexpected  class 'TypeError' : '%x format: an integer is required, not str'
...

- it's an integer, not a number

--
nosy: +wolma

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-04 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 11e6986c794d by Serhiy Storchaka in branch 'default':
Issue #23466: Fixed expected error message in test_format.
https://hg.python.org/cpython/rev/11e6986c794d

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Good catch, Wolfgang!

Definitely we should make test_format more unittest compatible.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch that makes bytes formatting raise an OverflowError if integer 
argument of %c is out of range.

--
Added file: http://bugs.python.org/file38812/bytes_format_overflow.patch

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread STINNER Victor

STINNER Victor added the comment:

 b'%c' is still raising a TypeError.  The error message is fine (%c requires 
 an integer in range(256) or a single byte) but it should be an OverflowError 
 for backwards compatibility.

I don't understand why you care so much on the exact exception. It doesn't look 
right to me to rely on the *exact* exception raised by %c % arg. It's an 
obvious bug in the application.

Sometimes, you may want to be extra safe and catch exception while formating a 
message. The logging module does this. But the logging doesn't care of the 
exact exception, it uses a generic except Except: in StreamHandler.emit():

def emit(self, record):
try:
msg = self.format(record)
stream = self.stream
stream.write(msg)
stream.write(self.terminator)
self.flush()
except Exception:
self.handleError(record)

IMO b%c % int must raise ValueError, not OverflowError, if the value is not 
in the range 0..255.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

See also issue18184.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread Ethan Furman

Ethan Furman added the comment:

Looks good, thanks Serhiy.

--
stage: needs patch - patch review

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-03 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 313fd1c819c5 by Serhiy Storchaka in branch 'default':
Issue #23466: Raised OverflowError if %c argument is out of range.
https://hg.python.org/cpython/rev/313fd1c819c5

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-02 Thread Ethan Furman

Ethan Furman added the comment:

It's a new feature for 3.5 that is partly responsible for compatibility with 
2.7 code.

2.7 raises Overflow error, so 3.5 should also (for out of range values -- wrong 
value types raise TypeError).

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-02 Thread Ethan Furman

Ethan Furman added the comment:

b'%c' is still raising a TypeError.  The error message is fine (%c requires an 
integer in range(256) or a single byte) but it should be an OverflowError for 
backwards compatibility.

--
resolution: fixed - 
stage: resolved - needs patch
status: closed - open

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-04-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

OverflowError is for platform limitations (such as the size of machine word or 
addressed space). When limits are well defined and platform-independent, 
ValueError or may be TypeError are considered as better types. It would be 
better to change OverflowError to ValueError or TypeError in formatting.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-31 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
assignee:  - serhiy.storchaka
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-30 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cb96fd376baa by Serhiy Storchaka in branch 'default':
Issue #23466: %c, %o, %x, and %X in bytes formatting now raise TypeError on
https://hg.python.org/cpython/rev/cb96fd376baa

--
nosy: +python-dev

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-29 Thread Ethan Furman

Ethan Furman added the comment:

Patch looks good.

Changing the raised exceptions to ValueError  would require deprecation periods.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-29 Thread STINNER Victor

STINNER Victor added the comment:

 Changing the raised exceptions to ValueError  would require deprecation
periods.

bytes%args is not a new feature of python 3.5? It sounds strange to
deprecate a part of a new feature.

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-24 Thread STINNER Victor

STINNER Victor added the comment:

The patch looks good to me, except of a question added on the review.

--
nosy: +haypo

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-03-24 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ethan?

--

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-02-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch.

The difference between string and bytes formatting is that %c with out of the 
range integer raises OverflowError for str and TypeError for bytes. May be 
ValueError is more suitable in both cases.

--
keywords: +patch
stage:  - patch review
Added file: http://bugs.python.org/file38156/bytes_int_format.patch

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



[issue23466] PEP 461: Inconsistency between str and bytes formatting of integers

2015-02-15 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
title: Inconsistency between str and bytes formatting of integers - PEP 461: 
Inconsistency between str and bytes formatting of integers

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