[issue23096] Implementation-depended pickling floats with protocol 0

2014-12-21 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Python and C implementations of pickle produce different results when pickle 
floats with protocol 0.

>>> pickle.dumps(4.2, 0)
b'F4.2002\n.'
>>> pickle._dumps(4.2, 0)
b'F4.2\n.'

--
components: Library (Lib)
messages: 232992
nosy: alexandre.vassalotti, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Implementation-depended pickling floats with protocol 0
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

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



[issue23097] unittest can unnecessarily modify sys.path (and with the wrong case)

2014-12-21 Thread Chris Jerdonek

New submission from Chris Jerdonek:

I have observed that when running unit tests using unittest's test discovery, 
unittest can simultaneously (1) modify sys.path unnecessarily (by adding a path 
that is already in sys.path with a different case), and (2) modify sys.path by 
adding a path of the "wrong" case.

This occurs for me on Mac OS X with the default case-insensitive file system.

If the path--

'/Users/chris/Dev/python/my_package'

is already in sys.path, running unittest's test discovery will prepend sys.path 
with the following:

'/Users/chris/dev/python/my_package'

Aside from causing unnecessary modifications of sys.path, this also causes an 
issue in coverage, for example:

https://bitbucket.org/ned/coveragepy/issue/348

The relevant code is here in unittest/loader.py (with `top_level_dir` starting 
out as os.curdir):

top_level_dir = os.path.abspath(top_level_dir)

if not top_level_dir in sys.path:
# all test modules must be importable from the top level directory
# should we *unconditionally* put the start directory in first
# in sys.path to minimise likelihood of conflicts between installed
# modules and development versions?
sys.path.insert(0, top_level_dir)
self._top_level_dir = top_level_dir

(from 
https://hg.python.org/cpython/file/75ede5bec8db/Lib/unittest/loader.py#l259 )

The issue occurs when os.path.abspath(top_level_dir) is already in sys.path but 
with a different case.  (Note that if os.path.abspath() returned a path with 
the "right" case, then the unittest code would be okay.)

See also these two threads regarding obtaining the correct case for a path:

1. https://mail.python.org/pipermail/python-dev/2010-September/103823.html
2. https://mail.python.org/pipermail/python-ideas/2010-September/008153.html

--
components: Library (Lib)
messages: 232993
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: unittest can unnecessarily modify sys.path (and with the wrong case)
type: behavior
versions: Python 3.4, Python 3.5

___
Python tracker 

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



[issue23094] Unpickler failing with PicklingError at frame end on readline due to a broken comparison

2014-12-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
keywords: +patch
Added file: http://bugs.python.org/file37521/pickle_frame_readline.patch

___
Python tracker 

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



[issue21279] str.translate documentation incomplete

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

Patch v4 with John’s doc string wording

--
Added file: http://bugs.python.org/file37522/issue21279.v4.patch

___
Python tracker 

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



[issue23096] Implementation-depended pickling floats with protocol 0

2014-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Python implementation uses repr(value) and C implementation uses '%.17g' % 
value.

--

___
Python tracker 

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



[issue23094] Unpickler failing with PicklingError at frame end on readline due to a broken comparison

2014-12-21 Thread CensoredUsername

CensoredUsername added the comment:

Indeed. In my case the problem was caused a subclassed Pickler which still used 
GLOBAL instead of STACK_GLOBAL in protocol 4.

My own minimized test case was:

data = b"\x80\x04\x95\x11\x00\x00\x00\x00\x00\x00\x00cpickle\nPickler\n."
>>> pickletools.dis(data)
0: \x80 PROTO  4
2: \x95 FRAME  17
   11: cGLOBAL 'pickle Pickler'
   27: .STOP
highest protocol among opcodes = 4

which should return pickle.Pickler

--

___
Python tracker 

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



[issue23093] repr() on detached stream objects fails

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

Here is patch v2, which ignores any exception derived from the Exception base 
class when reading the self.name etc properties. I’m interested what people 
think of this approach.

--
Added file: http://bugs.python.org/file37523/detach-indep.v2.patch

___
Python tracker 

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



[issue23093] repr() on detached stream objects fails

2014-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It looks reasonable to me.

--

___
Python tracker 

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



[issue21279] str.translate documentation incomplete

2014-12-21 Thread John Posner

John Posner added the comment:

Patch of 12-21 looks good, Martin.

--

___
Python tracker 

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



[issue21279] str.translate documentation incomplete

2014-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Proposed wording looks superfluously verbose to me.

Look also at description in Include/unicodeobject.h:

/* Translate a string by applying a character mapping table to it and
   return the resulting Unicode object.

   The mapping table must map Unicode ordinal integers to Unicode
   ordinal integers or None (causing deletion of the character).

   Mapping tables may be dictionaries or sequences. Unmapped character
   ordinals (ones which cause a LookupError) are left untouched and
   are copied as-is.

*/

It is repeated (more detailed) in Doc/c-api/unicode.rst. Isn't it pretty clear?

--
components: +Unicode
nosy: +ezio.melotti, georg.brandl, haypo, serhiy.storchaka

___
Python tracker 

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



[issue22836] Broken "Exception ignored in:" message on exceptions in __repr__

2014-12-21 Thread R. David Murray

R. David Murray added the comment:

See also issue 6294 for a related problem.

--

___
Python tracker 

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



[issue21279] str.translate documentation incomplete

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

Serhiy can you point out which bits are too verbose? Perhaps you prefer it 
without the bullet list like in the earlier 2014-12-13 version of the patch.

Looking at the C API, I see a couple problems there:
* Omits mentioning that an ordinal can map to a replacement string
* It looks like the documented None behaviour applies when errors="ignore", 
otherwise it invokes a codec error handler

--

___
Python tracker 

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



[issue6294] Improve shutdown exception ignored message

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

Not sure what the original method to cause this message is. I’m guessing some 
code was trying to call a function that was set to None by the shutdown 
process, causing the exception message, and that repr() was also failing, 
causing the broken wording. Like this:

$ python2 << PYTHON
> class C:
> def __repr__(self): return None()
> def __del__(self): None()
> x = C()
> PYTHON
Exception TypeError: "'NoneType' object is not callable" in  ignored

If this is the case, then it is the same problem as Issue 22836, where I have 
posted a test and a fix for Python 3.

--
nosy: +vadmium

___
Python tracker 

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



[issue23098] mknod devices can be >32 bits

2014-12-21 Thread Jesús Cea Avión

New submission from Jesús Cea Avión:

Dan MacDonald told me that "os.mknod()" should accept devices >32 bits.

I wrote this code in linux 64 bits:

"""
#include 
#include 
#include 
#include 
#include 

int main(void) {
printf("%d", sizeof(dev_t));
return 0;
}
"""

The result of running this is "8". We need a long long.

I did this change in Python 2.7 branch:

"""
diff -r f00412d32b41 Modules/posixmodule.c
--- a/Modules/posixmodule.c Sat Dec 20 13:41:14 2014 -0600
+++ b/Modules/posixmodule.c Sun Dec 21 23:30:00 2014 +0100
@@ -7009,9 +7009,9 @@
 {
 char *filename;
 int mode = 0600;
-int device = 0;
+long long device = 0;
 int res;
-if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))
+if (!PyArg_ParseTuple(args, "s|iL:mknod", &filename, &mode, &device))
 return NULL;
 Py_BEGIN_ALLOW_THREADS
 res = mknod(filename, mode, device);
"""

Looks like this patch is trivial. Please, comment.

--
assignee: jcea
keywords: easy
messages: 233004
nosy: jcea
priority: normal
severity: normal
stage: patch review
status: open
title: mknod devices can be >32 bits
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

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



[issue22836] Broken "Exception ignored in:" message on exceptions in __repr__

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

Patch v2 revises the unit tests so they are cleaner. Also now tests that the 
 placeholders are in the exception reports.

--
Added file: http://bugs.python.org/file37524/unraisable-continue.v2.patch

___
Python tracker 

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



[issue23093] repr() on detached stream objects fails

2014-12-21 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f3ff3e424b6f by Benjamin Peterson in branch '3.4':
allow more operations to work on detached streams (closes #23093)
https://hg.python.org/cpython/rev/f3ff3e424b6f

New changeset afa8d8ab0937 by Benjamin Peterson in branch '2.7':
allow more operations to work on detached streams (closes #23093)
https://hg.python.org/cpython/rev/afa8d8ab0937

New changeset f2cfa8a348dd by Benjamin Peterson in branch 'default':
merge 3.4 (#23093)
https://hg.python.org/cpython/rev/f2cfa8a348dd

--
nosy: +python-dev
resolution:  -> fixed
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



[issue19539] The 'raw_unicode_escape' codec buggy + not appropriate for Python 3.x

2014-12-21 Thread Martin Panter

Martin Panter added the comment:

[Edit Error: 'utf8' codec can't decode byte 0xe2 in position 212: invalid 
continuation byte]


Re-reading the suggested description, it struck me that for encoding, this is 
redundant with the “backslashreplace” error handler:

>>> test = "".join(map(chr, range(sys.maxunicode + 1)))
>>> test.encode("raw-unicode-escape") == test.encode("latin-1", 
>>> "backslashreplace")
True

However, decoding also seems similar to “unicode_escape”, except that only 
\u and \U seem to be supported.

Maybe there should be a warning that backslashes are not escaped:

>>> "\\u005C".encode("raw-unicode-escape").decode("raw-unicode-escape")
'\\'

--

___
Python tracker 

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



[issue23061] Update pep8 to specify explicitly 'module level' imports at top of file

2014-12-21 Thread Ian Lee

Ian Lee added the comment:

So one concern that was brought up on GitHub was the fact that currently this 
is not actually followed universally in the Python standard library. In 
particular there are 636 errors in the standard library ``python pep8.py 
--select E402 --statistics /usr/lib/python3.4``.

The vast majority are due to issues with dunder definitions 
``__{all,author,copyright,credits,version,etc...}__`` before the imports. A 
lesser cause is imports in the middle of files. ``Lib/tokenize.py`` has pretty 
much all of these issues. In particular ``__all__`` is specifically mentioned 
that it should be declared AFTER the imports by PEP-8. That said, I would argue 
this is a good time to clean up that code in the standard library.

Additionally, its possible that there might need to be some wording in the PEP 
about intermixing "try,except,else,finally" and possibly "if,elif,else" into 
the imports. E.g. 

```
try: 
import unittest2
except:
import unittest
```

```
if sys.platform == 'win32':
import foo
```

--

___
Python tracker 

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



[issue23061] Update pep8 to specify explicitly 'module level' imports at top of file

2014-12-21 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +ezio.melotti

___
Python tracker 

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



[issue23061] Update pep8 to specify explicitly 'module level' imports at top of file

2014-12-21 Thread Ian Lee

Ian Lee added the comment:

I should add that I would be happy to patch the standard libraries to be 
compliant w.r.t. the imports at top of the files.

--

___
Python tracker 

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



[issue21279] str.translate documentation incomplete

2014-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> Serhiy can you point out which bits are too verbose? Perhaps you prefer it
> without the bullet list like in the earlier 2014-12-13 version of the
> patch.

I prefer it without the bullet list and without LookupError expansion (there 
is a link to LookupError definition where IndexError and KeyError should be 
mentioned). Instead of new term "subscriptable objects" use "mappings or 
sequences" with links to glossary.

> Looking at the C API, I see a couple problems there:

Yes, it is slightly outdated and needs updates.

--

___
Python tracker 

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