[issue7430] cmp still sends messages

2009-12-04 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Fixed in r76663, r76664.  Thanks for the report!

--
resolution:  - fixed
status: open - closed
versions: +Python 3.2

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



[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Zooko:  Yes; that's the sort of solution that's needed if we're not 
allowed to assume two's complement with the extraordinary value (-
sys.maxint - 1) not a trap representation.  If we are allowed to
assume this, then more efficient solutions are available.

Also, if we're not allowed to assume two's complement + no trap 
representation, then int_and, int_xor, int_or are plain wrong:

For ones' complement or sign-and-magnitude, the result of these
logical operations won't match the result of the corresponding
operations on longs, for negative operands.

For two's complement with (-sys.maxint-1) a trap representation,
int_and and int_xor should be producing a Python long instead
of a Python int in some cases: -sys.maxint ^ 1 should be -sys.maxint - 1, 
which wouldn't be representable as a Python int.

That's why I want to make these extra assumptions beyond what's
guaranteed by the C standards; working around them introduces 
inefficiencies for all implementations, for the benefit
of implementations that (probably) don't even exist.

--

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



[issue7048] decimal.py: logb: round the result if it is greater than prec

2009-12-04 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Mike Cowlishaw has confirmed that the tests scbx164, scbx165 (in version 
2.59 of the tests) are implementation-specific, so test_decimal is doing 
the right thing in skipping them.  So I think this issue can be closed.

I don't think it's worth removing the restriction on the 2nd scaleb 
argument:  while I still think it's arbitrary and unnecessary, keeping it 
allows us to say that we're in full compliance with the specification.

--
resolution:  - fixed
status: open - closed

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



[issue1923] meaningful whitespace can be lost in rfc822_escape

2009-12-04 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
assignee:  - tarek
nosy: +tarek

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



[issue7433] MemoryView memory_getbuf causes segfaults, double call to tp_releasebuffer

2009-12-04 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Why do you say that:

 There is no feasible way the bf_releasebuffer can keep track of how many
 calls to it have been made.

Because that's exactly what e.g. bytearray objects do (see the
ob_exports field in Objects/bytearrayobject.c).

--
nosy: +pitrou

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



[issue7385] MemoryView_FromObject crashes if PyBuffer_GetBuffer fails

2009-12-04 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Nice catch. I wonder whether there's a simple way of cooking up an unit
test for this (short of creating a new extension type).

--
assignee:  - pitrou
nosy: +pitrou
priority:  - high
stage:  - needs patch
versions: +Python 2.7, Python 3.2

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



[issue7433] MemoryView memory_getbuf causes segfaults, double call to tp_releasebuffer

2009-12-04 Thread Pauli Virtanen

Pauli Virtanen p...@iki.fi added the comment:

 Why do you say that:
 
  There is no feasible way the bf_releasebuffer can keep track of how 
  many calls to it have been made.

I was probably thinking about allocating new temporary arrays for
strides etc. on each *_getbuffer -- if that's done, then manually
keeping track of all the allocated memory seems like a waste of effort
(ie. not feasible).

But yes, if memory allocated for entries in Py_buffer is shared between
all exported buffer views, that sounds better -- for some reason I
didn't think about that... So we'll do it like this in Numpy then.

But still, I take it that the way it currently works is not the intended
behavior? The segmentation faults caused by this came as a bit of a
surprise to me, as the assumption about paired *_getbuffer and
*_releasebuffer calls is very natural.

--

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



[issue7433] MemoryView memory_getbuf causes segfaults, double call to tp_releasebuffer

2009-12-04 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 I was probably thinking about allocating new temporary arrays for
 strides etc. on each *_getbuffer -- if that's done, then manually
 keeping track of all the allocated memory seems like a waste of effort
 (ie. not feasible).

Yes, I know it looks very painful to do so. I am not responsible for the
Py_buffer / memorview design, however. Travis Oliphant is, and I hear
he's a member of the Numpy community: you might want to ask him for
advice.

(the general problem is that managing Py_buffers can entail memory
allocations, but Py_buffer is not a PyObject and therefore you can't
take advantage of Python's general object management facilities)

 But still, I take it that the way it currently works is not the intended
 behavior? The segmentation faults caused by this came as a bit of a
 surprise to me, as the assumption about paired *_getbuffer and
 *_releasebuffer calls is very natural.

Well, those calls still /are/ paired, aren't they?
There is one odd thing which you must be careful about, it is that
*_getbuffer can be called with a NULL Py_buffer pointer.

--

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



[issue7433] MemoryView memory_getbuf causes segfaults, double call to tp_releasebuffer

2009-12-04 Thread Pauli Virtanen

Pauli Virtanen p...@iki.fi added the comment:

I think this is an implementation issue in MemoryView rather than an
issue with the buffer interface. PEP 3118 states, This same bufferinfo
structure must be passed to bf_releasebuffer (if available) when the
consumer is done with the memory. -- this is not guaranteed by the
current MemoryView implementation.

The calls are not paired: the *_getbuf calls fill in structures with
data view1, and view2. The *_releasebuf calls receive structures
with data view1, and view1. The data filled in the second getbuf
call (view2) is never passed back to *_releasebuf, as it is
overwritten with view1 data by dup_buffer.

To work around this, *_releasebuf must be written so that it does not
use the view pointer passed to it -- the data structure may have been
shallow copied and any memory pointers in it may have already been freed.

I can try to cook up a patch fixing this.

--

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



[issue7327] format: minimum width: UTF-8 separators and decimal points

2009-12-04 Thread Eric Smith

Eric Smith e...@trueblade.com added the comment:

See the discussion on python-dev, in particular Martin's comment at
http://mail.python.org/pipermail/python-dev/2009-December/094412.html

The solutions to this seem too complex for 2.x. It is not a problem in 3.x.

--
resolution:  - wont fix
status: open - closed

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



[issue7433] MemoryView memory_getbuf causes segfaults, double call to tp_releasebuffer

2009-12-04 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 To work around this, *_releasebuf must be written so that it does not
 use the view pointer passed to it -- the data structure may have been
 shallow copied and any memory pointers in it may have already been freed.
 
 I can try to cook up a patch fixing this.

If you can do it without breaking the current unit tests
(Lib/test/test_memoryview.py) this would be nice indeed.

--

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



[issue7434] pprint doesn't know how to print a namedtuple

2009-12-04 Thread Anthony Foglia

New submission from Anthony Foglia afog...@gmail.com:

It would be nice if pprint could format namedtuples wrapping lines as it
does with tuples.

Looking at the code, this does not look like an easy task.  Completely
rewriting pprint to allow it to be extensible to user-created classes
would be best, but involve a ton of work.  Simple making all named
tuples derive from a named tuple base class (itself derived from tuple)
would be simpler, albeit more of a hack.

--
components: Library (Lib)
messages: 95968
nosy: afoglia
severity: normal
status: open
title: pprint doesn't know how to print a namedtuple
type: feature request
versions: Python 2.6

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



[issue7434] pprint doesn't know how to print a namedtuple

2009-12-04 Thread Benjamin Peterson

Changes by Benjamin Peterson benja...@python.org:


--
assignee:  - rhettinger
nosy: +rhettinger

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



[issue7427] BadStatusLine is hell to debug

2009-12-04 Thread Jake McGuire

Jake McGuire j...@youtube.com added the comment:

I think what's happening is that your connection is being closed due to 
inactivity, so the status line that comes back is empty.  Printing 
repr(line) would probably make the emptiness clear, but maybe the httplib 
code should put in a more specific message in this case...

--
nosy: +jakemcguire

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



[issue7426] StringIO and with statement

2009-12-04 Thread Brian Curtin

Brian Curtin cur...@acm.org added the comment:

#1286 looks related

--
nosy: +brian.curtin

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



[issue7426] StringIO and with statement

2009-12-04 Thread Alexandre Vassalotti

Changes by Alexandre Vassalotti alexan...@peadrop.com:


--
resolution:  - duplicate
stage:  - committed/rejected
status: open - closed
superseder:  - fileinput, StringIO, and cStringIO do not support the with 
protocol

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



[issue7435] Int/Long: some tests are duplicate and error messages refer to long

2009-12-04 Thread flox

New submission from flox la...@yahoo.fr:

In python 3.x there's a single type for integer: int.
The automatic conversion of the test suite has created many tests which
are duplicate of each other.

The attached patch removes duplication of tests, and fix the strings for
these modules:

  Lib/random.py
  Lib/test/mapping_tests.py
  Lib/test/pickletester.py
  Lib/test/string_tests.py
  Lib/test/test_binop.py
  Lib/test/test_builtin.py
  Lib/test/test_datetime.py
  Lib/test/test_decimal.py
  Lib/test/test_descr.py
  Lib/test/test_dict.py
  Lib/test/test_getargs2.py
  Lib/test/test_int.py
  Lib/test/test_long.py
  Lib/test/test_types.py

--
components: Tests
messages: 95971
nosy: flox
severity: normal
status: open
title: Int/Long: some tests are duplicate and error messages refer to long
versions: Python 3.2

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



[issue7435] Int/Long: some tests are duplicate and error messages refer to long

2009-12-04 Thread flox

Changes by flox la...@yahoo.fr:


--
keywords: +patch
Added file: http://bugs.python.org/file15449/issue7435_py3k.diff

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



[issue7436] Define 'object with assignable attributes'

2009-12-04 Thread Terry J. Reedy

New submission from Terry J. Reedy tjre...@udel.edu:

On Python list, someone asked what guarantees that functions have and
will continue to have assignable attributes. I started to say 'the docs'
but failed to find anything specific in 7.6. Function definitions or
LibRef 5.12.3. Functions (all references to 3.1/2a docs).

5.3.1 Attribute references says The primary must evaluate to an object
of a type that supports attribute references, which most objects do.
That is true for reading/getting but not for writing/setting.

6.2. Assignment statements says If the target is an attribute
reference: The primary expression in the reference is evaluated. It
should yield an object with assignable attributes; But which are those?

I propose to add a sentence like Objects with assignable attributes
include modules, user-defined (Python-coded) functions and classes, and
instances of such classes.

If this leaves anything out, it can be expanded.

I tested and was somewhat surprised to modules based on C code (_socket,
_tkinter) allowed attribute setting. I use 'user'defined' because the
docs do in several places. I added 'Python-coded' because that is the
real relevant characteristic. C-coded user-defined functions in
user-written extension modules do not have settable attributes (I
presume), whereas imported Python-coded functions, in stdlib or 3-rd
party modules do. LibRef 5.12.3 There are really two flavors of
function objects: built-in functions and user-defined functions. could
leave a reader wondering about imported functions.

A sentence could also be added there User-defined (Python-coded)
functions have assignable attributes.

--
assignee: georg.brandl
components: Documentation
messages: 95972
nosy: georg.brandl, tjreedy
severity: normal
status: open
title: Define 'object with assignable attributes'

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



[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Tom Switzer

Tom Switzer thomas.swit...@gmail.com added the comment:

I am not sure I understand the reasoning behind removing the cmp
parameter (and agree with Lea Wiemann). Trying to wedge a proper
comparison into the key parameter is clumsy and unreadable (as can be
seen in the 2to3 example above). The intrinsic ordering on objects does
not necessarily match up with the way you want to sort them. For
example, a natural intrinsic order on 2 points in 2d is lexicographical,
however you often want to sort by angular order relative to some other
point instead. Clearly this can never be put in __cmp__ or __lt__,
because the sorted order is relative to some other unknown point. Trying
to do this with the key function doesn't make sense; it would not be
clear you are sorting by angular order and you'd have to instantiate a
bunch of wrapper objects just to do basic sorting. Another quick example
would be sorting hyperplanes by intersection on a ray. Sorting points
along a direction given by a vector.

I understand removing redundant features from a language, but I just
can't see how key replaces this functionality in a readable or efficient
way. This highlights an important class of cases (since it was mentioned
that none could be thought of) in which we wish to make comparisons
between values where a comparison (,  or ==) is more numerically
sound, more efficient, or the only option (perhaps the ordering is
defined explicitly) then computing the exact values (eg. angle). As far
as it seems, the only way to do this with key is by following the
example given and creating a class solely to wrap each object that
overrides __cmp__, which is certainly non-obvious (ie. there is no one,
obvious way to do it).

--
nosy: +tixxit

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



[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

I consider the binary bitwise operations, for negative ints, to be
either undefined or wrongly implemented. Consider the following (3.1)
 3^2
1
 -3^2
-1
 3^-2
-3
 -3^-2
3
 2^3
1
 -2^3
-3

Something change sign just flips the sign of the result, sometimes it
also changes the magnitude. From the viewpoint of arithmetic, and signed
base-two representations, the latter seems senseless.

The doc says only The ^ operator yields the bitwise XOR (exclusive OR)
of its arguments, which must be integers. But it does not define what
bitwise XOR means for signed ints, as opposed to unsigned bit strings,
possible interpreted as (unsigned) counts, which is the traditional
domain of bit-operation definition. So there is no way to predict the
result for negative ints. Or rather, the sensible prediction does not
match the observed behavior.

My impression is that Python longs are signed magnitudes. If so, the
bitwise ops should arguably be the signed result of the op on the
magnitudes.

--
nosy: +tjreedy

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



[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Guido van Rossum

Guido van Rossum gu...@python.org added the comment:

Can someone provide a code sample to make this argument more 
understandable for those of us who don't compare points by angular order 
for a living... :-)

I'm not sure what the 2to3 example (I presume you mean msg59937) shows 
except that conversion from a cmp function to a key function may require 
you to actually think...

Also, for all of you asking for cmp back, I hope you realize that 
sorting N values using a custom cmp function makes about N log N calls 
calls to cmp, whereas using a custom key calls the key function only N 
times.  This means that even if your cmp function is faster than the 
best key function you can write, the advantage is lost as N increases 
(which is just where you'd like it to matter most :-).

--

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



[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Tim Peters

Tim Peters tim.pet...@gmail.com added the comment:

Terry, the language reference also says:


For the purpose of shift and mask operations, a binary representation is
assumed, and negative numbers are represented in a variant of 2's
complement which gives the illusion of an infinite string of sign bits
extending to the left.


That explains every result you saw:

 3 = ...11
 2 = ...10
 1 = ...01

-3 = ...01
 2 = ...10
-1 = ...11

 3 = ...11
-2 = ...10
-3 = ...01

-3 = ...01
-2 = ...10
 3 = ...11

 2 = ...10
 3 = ...11
 1 = ...01

-2 = ...10
 3 = ...11
-3 = ...01

In every case, the result is simply the xor of the inputs viewed as
infinite bitstrings.  And it works exactly the same way if you use |, ,
, , or unary ~.

It's true that CPython's longs are /implemented/ via sign-magnitude, but
that should never be visible in the result of any operation.

--
nosy: +tim_one

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



[issue6594] json C serializer performance tied to structure depth on some systems

2009-12-04 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Here is a new patch with an internal memo dict to reuse equal keys, and
some tests.

--
stage:  - patch review
versions: +Python 3.2
Added file: http://bugs.python.org/file15450/json-opts2.patch

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



[issue6594] json C serializer performance tied to structure depth on some systems

2009-12-04 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


Removed file: http://bugs.python.org/file15444/json-opts.patch

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



[issue7435] Int/Long: some tests are duplicate and error messages refer to long

2009-12-04 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +eric.smith, mark.dickinson

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



[issue7437] OS X 2.6.4 installer fails on 10.3 with two corrupted file names, ignored on 10.4

2009-12-04 Thread Ned Deily

New submission from Ned Deily n...@acm.org:

See the thread starting at http://mail.python.org/pipermail/pythonmac-
sig/2009-December/021907.html for full details.

It appears two vestigial gif files included in the 2.6.4 OS installer 
are being installed under corrupted file names by the OS X Installer.app 
under 10.3 and 10.4.  While the error is silently ignored on 10.4, it 
apparently causes the whole install to fail on 10.3.  The problem does 
not seem to occur when installing on 10.5 or 10.6.  It is also not 
limited to that installer image: I was able to reproduce the problem 
with an installer I built on 10.5.  However, an installer built on 10.4 
from the same source snapshot seems to have the correct file names.

Without knowing exactly why those two file names, and only those two, 
are corrupted, it seems risky to let this seemingly minor problem go 
unresolved.  And it apparently prevents 2.6.4 from being installed on 
10.3, a more serious problem.

--
assignee: ronaldoussoren
components: Macintosh
messages: 95978
nosy: ned.deily, ronaldoussoren
severity: normal
status: open
title: OS X 2.6.4 installer fails on 10.3 with two corrupted file names, 
ignored on 10.4
versions: Python 2.6

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



[issue1923] meaningful whitespace can be lost in rfc822_escape

2009-12-04 Thread Tarek Ziadé

Tarek Ziadé ziade.ta...@gmail.com added the comment:

Notice that we are also losing something else that can mean a lot
in reST : empty lines. They also need to be escaped.

But we can't do it properly unless we encode empty lines with something
else than a 8 space line because when rfc822.Message reads it, it
removes it.

--

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



[issue7438] Allow to use a part of subprocess module during building Python

2009-12-04 Thread Arfrever Frehtes Taifersar Arahesis

New submission from Arfrever Frehtes Taifersar Arahesis 
arfrever@gmail.com:

It is sometimes useful to call subprocess.Popen() in setup.py of
Python. Currently it would fail, because subprocess module tries to
import some modules, which not always are used. I suggest to delay some
imports.

--
components: Library (Lib)
files: subprocess.py-2.7.patch
keywords: patch
messages: 95980
nosy: Arfrever
severity: normal
status: open
title: Allow to use a part of subprocess module during building Python
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file15451/subprocess.py-2.7.patch

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



[issue7438] Allow to use a part of subprocess module during building Python

2009-12-04 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


Added file: http://bugs.python.org/file15452/subprocess.py-3.2.patch

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



[issue7439] Bug or expected behavior? I cannot tell.

2009-12-04 Thread David W. Lambert

New submission from David W. Lambert b49p23t...@stny.rr.com:

Raymond Hettinger posted clever Hamming number generator,
http://code.activestate.com/recipes/576961/
which I tried to modify.  The function gives incorrect output when
called as hamming_numbers(shorthand = True).  It seemed reasonable to
expect the two arrangements of statements controlled by the shorthand
boolean to be functionally equivalent. 
http://docs.python.org/3.1/reference/executionmodel.html is relevant,
and makes me think this is not a bug, but I wish it were.  I'd
appreciate your determination.  Thanks, Dave.



from itertools import tee, chain, islice, groupby
from heapq import merge

def hamming_numbers(shorthand = False):

def deferred_output():
for i in output:
yield i

result, p2, p3, p5 = tee(deferred_output(), 4)

if shorthand:   # Lambert modification
m = [(a*x for x in p) for (a,p,) in ((2,p2),(3,p3),(5,p5))]
assert m[0] is not m[2]
merged = merge(*m)
else:   # original
m2 = (2*x for x in p2)
m3 = (3*x for x in p3)
m5 = (5*x for x in p5)
merged = merge(m2, m3, m5)

combined = chain([1], merged)
output = (k for k, v in groupby(combined))

return result


if __name__ == '__main__':
print(list(islice(hamming_numbers(), 10)))
print(list(islice(hamming_numbers(True), 10)))

--
components: Interpreter Core
messages: 95981
nosy: LambertDW
severity: normal
status: open
title: Bug or expected behavior?  I cannot tell.
type: behavior
versions: Python 3.1

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



[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

FWIW, we had a long discussion on comp.lang.python and the net result
was that no use cases were found that required a cmp function.  One
complex case (sorting recursive tree structures) at first appeared to
need a cmp-function but was found to be simpler and faster using a
key-function.  The net result of the conversation was the feeling that
people who have grown-up using cmp-functions in either Python, C or some
other language feel like they've lost something but really haven't.  In
contrast, people who use SQL or spreadsheet database tools find that key
functions come naturally since neither supports cmp-functions, instead
preferring the user to specify primary and secondary key functions.   

Also, it was pointed-out the removal of cmp-functions in sorted() and
list.sort() was part of a larger effort to remove all forms of cmp from
the whole language (i.e. the builtin cmp function is gone and so it the
__cmp__ magic method).  Rich comparisons have completely supplanted all
uses of cmp-functions in the language as a whole -- having multiple ways
to do it was confusing.

In converting code from 2-to-3, we have found two sticky cases.

The first occurs when an API had exposed cmp functions to the end-user
(for example, unittest.getTestCaseNames() and unittest.makeSuite() have
an optional sortUsing parameter that allows the user to specify a
cmp-function).  To support that use case (so that end-user API's would
not have to be changed), we added a CmpToKey() tool which automatically
converts cmp-functions to key functions.  This tool is referenced in the
docs and it could be added to the 2-to-3 converter.

The second case occurs when a primary key is sorted ascending and a
secondary key is sorted descending.  The technique for that is to take
advantage of sort stability and do two sorts:

   s.sort(key=secondary, reverse=True)
   s.sort(key=primary)   
   # now sorted by primary ascending, secondary descending

That technique is going to be documented in an update of the sorting
how-to.  It doesn't seem to arise much in practice and the cmp function
equivalent seems to be harder for beginners to write (though at least it
can be done with a single cmp-function and a single sort).

--

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



[issue7434] pprint doesn't know how to print a namedtuple

2009-12-04 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

I agree with you that pprint needs to be rewritten to make it more
extensible.

I do not see a straight-forward way of handling your feature request.

First, namedtuple() is a factory function and is not itself a class, so
there is no standard way to recognize one.  Essentially, a named tuple
is concept (any class that supported both sequence behavior and
attribute access is a named tuple, for example the time structure is a
named tuple but not created by the collections.namedtuple() factory
function, instead is a C structseq which has substantially similar
characteristics).  This means that pprint has no reliable way to tell if
one of its arguments is a named tuple.

Second, collections.namedtuple() is intentionally designed to let the
user override the default __repr__() method (see an example in the
namedtuple docs).  That means that pprint cannot know in advance how a
named tuple is supposed to display.

At best, I can imagine that pprint() grows the ability to print a
multi-line repr (as specified by the object itself) but indented to a
level controlled by pprint().  The pprint() function would scan the repr
for newlines and replace them with a newline followed by the appropriate
number of spaces.

For example:

 class Point(namedtuple('Point', 'x y z')):
... 'Point with a multi-line repr'
... def __repr__(self):
... return 'Point(\n  x=%r,\n  y=%r,\n  z=%r\n
)' % self

 Point(3,4,5)
Point(
  x=3,
  y=4,
  z=5
 )

 pprint([Point(3,4,5), Point(6,7,8)])
[Point(
   x=3,
   y=4,
   z=5
  ),
 Point(
   x=6,
   y=7,
   z=8
  )
]

Alternatively, the pprint module could introduce a new magic method to
support multi-line reprs when the repr itself it too long fit in a
single line:

class MyList(list):
... def  __multirepr__(self):
... 'Return a list of strings to pprint'
... return Multi(head = 'Mylist([',
...  body = [str(x).upper() for x in self],
...  tail = '])

 pprint(MyList(['now', 'is', 'the', 'time', 'for']), width=15)
MyList(['NOW',
'IS',
'THE',
'TIME',
'FOR',
])

In summary, there are several ways to approach this problem but they are
centered on building-out pprint(), not on changing collections.namedtuple().

--
assignee: rhettinger - 

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



[issue7440] distutils shows incorrect Python version in MSI installers

2009-12-04 Thread Mario Vilas

New submission from Mario Vilas mvi...@gmail.com:

I just hit this silly bug in distutils, should be quite easy to fix.
When building MSI installers for a target_version other than the current
Python version, the target directory selection dialog shows a wrong message.

For example, here is a screen capture of an installer built using Python
2.6, but setting the target as Python 2.5. The message says:

The destination directory should contain a Python 2.6 installation

when it should be:

The destination directory should contain a Python 2.5 installation.

--
assignee: tarek
components: Distutils
files: msi_installer_wrong_message.png
messages: 95984
nosy: MarioVilas, tarek
severity: normal
status: open
title: distutils shows incorrect Python version in MSI installers
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file15453/msi_installer_wrong_message.png

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



[issue7440] distutils shows incorrect Python version in MSI installers

2009-12-04 Thread Mario Vilas

Mario Vilas mvi...@gmail.com added the comment:

My proposed patch is to change line 506 of bdist_msi.py from this:

version = sys.version[:3]+ 

to this:

version = self.target_version[:3]+ 

which is what I did to work around the problem.

--

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