[issue1222] locale.format bug if thousand separator is space (french separator as example)

2008-11-14 Thread Walter Doekes

Walter Doekes <[EMAIL PROTECTED]> added the comment:

@Antoine Pitrou

Regarding "# XXX is the trailing space a bug?": I'm inclined to believe
that it is. Man 7 locale does not mention that p_sep_by_space should be
used for non-int currency symbols, nor that it shouldn't. However, it
does say:

""" char *int_curr_symbol; /* First three chars are a currency symbol
from ISO 4217.  Fourth char is the separator. Fifth char is ’ ’. */ """

I haven't seen that fifth character, and in the libc sources I can't
find one either:

glibc-2.7/localedata/locales/nl_NL:66:int_curr_symbol
""

I do however see a separator.

In libc documentation I found here (
http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_19.html#SEC325
), it says the following:

""" In other words, treat all nonzero values alike in these members.
These members apply only to currency_symbol. When you use
int_curr_symbol, you never print an additional space, because
int_curr_symbol itself contains the appropriate separator. The POSIX
standard says that these two members apply to the int_curr_symbol as
well as the currency_symbol. But an example in the ANSI C standard
clearly implies that they should apply only to the
currency_symbol---that the int_curr_symbol contains any appropriate
separator, so you should never print an additional space. Based on what
we know now, we recommend you ignore these members when printing
international currency symbols, and print no extra space. """

This is probably not right either, because this forces you to use an
n_sign_posn and p_sign_posn that have the symbol on the same side of the
value. (Although that might not be such an awful assumption.) And, more
importantly, a grep through the sources reveal that no language has a
preceding space. (But they do, I assume, have *_sign_posn's that want a
trailing symbol.)

""" glibc-2.7/localedata/locales$ grep ^int_curr_symbol * | grep -vE
'(| )"' | wc -l
0 """

That leaves us with two more options. Option three: the fourth character
is optional and defines what the separator is but not _where_ it should
be. I.e. you might have to move it according to what *_sign_posn says.

And finally, option four: international formatting should ignore all of
*_cs_precedes, *_sep_by_space and *_sign_posn. Locale(7) explicitly
mentions currency_symbol, not int_cur_symbol. Perhaps one should assume
that international notation is universal. (I would guess that most
common is:
)


Personally I would go with option three. It has the least impact on
formatting because it only cleans up spaces. I'm guessing however that
option four is the Right One.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4323] Wrong encoding in files saved from IDLE (3.0rc2 on Windows)

2008-11-14 Thread André

New submission from André <[EMAIL PROTECTED]>:

When saving a source file with non-ascii characters from an IDLE window,
on Windows platform (XP and Server 2003 at least)
with locale English US  

  locale.getdefaultlocale()
  ('en_US', 'cp1252')

IDLE prompts in IOBinding.py with the message 
"non Ascii found, yet no encoding declared, Add a line like # -*- 
coding: cp1252 -*-"

If accepted, the file is saved with the wrong encoding.
Afterwards, it is read back by IDLE without any problem and it looks 
good in the IDLE window.

However, if a string with non-ascii characters is sent to another 
module (i.e. email  MIMEText)
the string is wrong.

The same source would be rejected by python in terminal mode and by 
IDLE on Linux.

--
messages: 75855
nosy: andre
severity: normal
status: open
title: Wrong encoding in files saved from IDLE (3.0rc2 on Windows)
type: behavior
versions: Python 3.0

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4323] Wrong encoding in files saved from IDLE (3.0rc2 on Windows)

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

> If accepted, the file is saved with the wrong encoding

"accept" means click on the "OK" button. You have to click on the 
biggest button "Edit my file" to create a valid file.

The problem here is the text in the dialog but also the possibility to 
create an invalid file. 

Two solutions:
 - don't ask user for a confirmation (always insert the header)
 - replace "OK" button by "Cancel" button: the user wants maybe an 
ASCII only file but inserted by error an unicode character (eg. non 
breaking space!)

--
nosy: +haypo
Added file: http://bugs.python.org/file12003/idle_dialog.png

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4323] Wrong encoding in files saved from IDLE (3.0rc2 on Windows)

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Quick but ugly solution: force the #coding: header without asking the 
user for that.

Added file: http://bugs.python.org/file12004/idle_remove_coding_dialog.py

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4323] Wrong encoding in files saved from IDLE (3.0rc2 on Windows)

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Implementation of the second solution: replace Ok button by a Cancel 
button. Escape key is Cancel, whereas Return key is the default 
action: edit the file.

--
keywords: +patch
Added file: http://bugs.python.org/file12005/idle_coding_dialog_cancel.patch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1673409] datetime module missing some important methods

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

>>> (t - epoch) // timedelta(seconds=1)

I don't like this syntax, because I can't guess the result unit:
  datetime - datetime -> timedelta
but:
  timedelta / timedelta -> seconds? days? nanoseconds?

If you example, you used timedelta(seconds=1), but what is the result 
unit if you use timedelta(hours=1)? or timedelta(days=1, 
microseconds=1)?

The problem is that timedelta has no unit (or has multiple units), 
whereas timedelta.toseconds() are seconds. So about your example:

>>> (t - epoch).toseconds()
--> fractional seconds
>>> int((t - epoch).toseconds())
--> whole seconds

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1673409] datetime module missing some important methods

2008-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

> timedelta / timedelta -> seconds? days? nanoseconds?

The quotient of two timedelta is a dimensionless number with no unit:
timedelta(hours=1) / timedelta(minutes=5) == 12.0
This seems well defined, where is the ambiguity?

--
nosy: +amaury.forgeotdarc

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4324] locale documentation is inconsistent

2008-11-14 Thread Kai Willadsen

New submission from Kai Willadsen <[EMAIL PROTECTED]>:

The documentation for locale.getlocale is not consistent with the
example given. The docs for getlocale([category]) say:
  "category may be one of the LC_* values except LC_ALL."
but the example at the bottom of the documentation starts with:
  >>> import locale
  >>> loc = locale.getlocale(locale.LC_ALL) # get current locale
  ...

--
assignee: georg.brandl
components: Documentation
messages: 75861
nosy: georg.brandl, kaiw
severity: normal
status: open
title: locale documentation is inconsistent
versions: Python 2.6

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4320] optparse: "1 2 3" should be seen as one string

2008-11-14 Thread Raghuram Devarakonda

Raghuram Devarakonda <[EMAIL PROTECTED]> added the comment:

I had the same need in my small command line client (that uses Cmd.Cmd)
and I solved it by using shlex.split() instead of regular string split.
I haven't looked at optparse code lately and perhaps it can do the same.

--
nosy: +draghuram

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1673409] datetime module missing some important methods

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

I was going to say the same as Amaury: timedelta / timedelta is
dimensionless (time units cancel each other in division) and the
advantage of this notation is that you get a way to express
timedelta.toxxx for all units accepted in constructor and even toweeks
becomes simple d / timedelta(7).

I've started flashing out a patch and then recalled that I've seen one
at issue2706 .  So instead of attaching a new patch here, I am going
to review the one in issue2706 now.

There was also some related discussion at issue4291 .   Apparently it
has been suggested that timedelta to integer and float conversions
would be a better alternative to timedelta / timedelta division.   I
disagree.  Integer conversion is ambiguous - should it be to seconds,
to microseconds or to timedelta.resolution (whatever that will become
in the future)?  Floating point conversion may loose precision as Tim
pointed out in msg26266 .  That would lead users to scratching their
heads over what to use float(d1)/float(d2) or float(d1)/int(d2) or
even int(d1)/int(d2) with true division on.

This said, let's move this discussion to issue2706 now.

On Fri, Nov 14, 2008 at 7:17 AM, Amaury Forgeot d'Arc
<[EMAIL PROTECTED]> wrote:
>
> Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:
>
>> timedelta / timedelta -> seconds? days? nanoseconds?
>
> The quotient of two timedelta is a dimensionless number with no unit:
>timedelta(hours=1) / timedelta(minutes=5) == 12.0
> This seems well defined, where is the ambiguity?
>
> --
> nosy: +amaury.forgeotdarc
>
> ___
> Python tracker <[EMAIL PROTECTED]>
> 
> ___
>

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1767933] Badly formed XML using etree and utf-16

2008-11-14 Thread Richard urwin

Richard urwin <[EMAIL PROTECTED]> added the comment:

This is a bug in two halves.

1. Not all characters in the file are UTF-16. The initial xml header
isn't, and the individual < > etc characters are not. This is just a
matter of extending the methodology to encode all characters and not
just the textual bits. There is no work-around except a five-minute hack
of the ElementTree.write() method.

2. Every write has a BOM, so corrupting the file in a manner analogous
to bug 555360. This is a result of using string.encode() and is a
well-known feature. It can be worked around by using UTF-16LE or
UTF-16BE which do not prepend a BOM, but then the file doesn't have any
BOM. A complete solution would be to rewrite ElementTree.write() to use
a different encoding methodology such as StreamWriter.

I have made the above hack and work-around for my own use, and I can
report that it produces perfect UTF-16.

--
nosy: +rurwin
versions: +Python 2.6

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4325] Installer crash on cancel installation.

2008-11-14 Thread dreamlusion

New submission from dreamlusion <[EMAIL PROTECTED]>:

Steps to reproduce:

1. Start the installer (python-2.6.msi)
2. Choose install for all users, next.
3. Select default directory, next.
4. Click "Advanced".
5. Click "Cancel" and confirm (click yes).
Bang.

--
components: Installation
messages: 75865
nosy: dreamlusion
severity: normal
status: open
title: Installer crash on cancel installation.
versions: Python 2.6

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4325] Installer crash on cancel installation.

2008-11-14 Thread dreamlusion

Changes by dreamlusion <[EMAIL PROTECTED]>:


--
type:  -> crash

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1767933] Badly formed XML using etree and utf-16

2008-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

Would you provide a patch?

--
nosy: +amaury.forgeotdarc

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4289] Python 2.6 installer crashes when selecting 'advanced' and cancelling it

2008-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

issue4325 describes the same crash, except that the user chose "all
users" and did not change the destination directory.

--
nosy: +amaury.forgeotdarc

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4325] Installer crash on cancel installation.

2008-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

It's a duplicate of issue4289, with almost the same sequence.

--
nosy: +amaury.forgeotdarc
resolution:  -> duplicate
status: open -> closed
superseder:  -> Python 2.6 installer crashes when selecting 'advanced' and 
cancelling it

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4323] Wrong encoding in files saved from IDLE (3.0rc2 on Windows)

2008-11-14 Thread Martin v. Löwis

Martin v. Löwis <[EMAIL PROTECTED]> added the comment:

The entire dialog should go away. The default source encoding is UTF-8
in Python 3.0, and IDLE should know that. The locale's encoding
shouldn't ever be considered.

--
nosy: +loewis

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4289] Python 2.6 installer crashes when selecting 'advanced' and cancelling it

2008-11-14 Thread dreamlusion

Changes by dreamlusion <[EMAIL PROTECTED]>:


--
nosy: +dreamlusion

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread Hirokazu Yamamoto

Hirokazu Yamamoto <[EMAIL PROTECTED]> added the comment:

After long random investigation, I found idle_crash_1.py can reproduce
the crash. And I noticed in idle_crash_2.py WidgetRedirector#dispatch,
last element of args cannot be printed. Here is result.

10
0 -foreground
1 black
2 -selectforeground
3 black
4 -selectbackground
5 black
6 -background
7 black
8 -insertbackground
9 Traceback (most recent call last):
  File "c.py", line 52, in 
selectbackground=color,
  File "e:\python-dev\py3k\lib\tkinter\__init__.py", line 1199, in configure
return self._configure('configure', cnf, kw)
  File "e:\python-dev\py3k\lib\tkinter\__init__.py", line 1190, in
_configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError

And I found this crash can be fixed by reverting r57540. This revision
was applied to fix issue1028, but I think we should solve this issue in
different way.

--
nosy: +ocean-city
type:  -> crash
Added file: http://bugs.python.org/file12006/idle_crash_1.py

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread Hirokazu Yamamoto

Changes by Hirokazu Yamamoto <[EMAIL PROTECTED]>:


Added file: http://bugs.python.org/file12007/idle_crash_2.py

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4293] Thread Safe Py_AddPendingCall

2008-11-14 Thread Kristján Valur Jónsson

Kristján Valur Jónsson <[EMAIL PROTECTED]> added the comment:

Here is a revised version.
Since there is no portable way to block signals, and no way at all on 
windows (apparently) the simplest way is to simply use NOWAIT_LOCK when 
adding a new pending call.  While this does not guarantee that we are 
always able to append a call (we may be unlucky in all our N tries and 
there is also no portable way to yield the thread timeslice between 
tries) such are also the semantics of the method.  Sometimes the buffer 
may be full, or we fail to get the lock in time, and a -1 is returned.  
It is up to the caller to respond appropriately, perhaps by trying again 
later.

Added file: http://bugs.python.org/file12008/pendingalls.patch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread Hirokazu Yamamoto

Hirokazu Yamamoto <[EMAIL PROTECTED]> added the comment:

Can I revert r57540 and reopen issue1028?

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

> Can I revert r57540 and reopen issue1028?

Would it be possible to revert and fix the issue in the same 
commit? :-)

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread Hirokazu Yamamoto

Hirokazu Yamamoto <[EMAIL PROTECTED]> added the comment:

Sorry, I cannot reproduce the bug described in issue1028, so it's
difficult for me.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1767933] Badly formed XML using etree and utf-16

2008-11-14 Thread Richard urwin

Richard urwin <[EMAIL PROTECTED]> added the comment:

Here is a patch of my quick hack, more for interest than any suggestion
it gets used. Although it does produce good output so long as you avoid
the BOM.

The full solution is beyond my (very weak) Python skills. The character
encoding is tied in with XML character substitution (& etc. and
hexadecimal representation of multibyte characters). I could disentangle
it, but I probably wouldn't produce optimal Python, or indeed anything
that wouldn't inspire mirth and/or incredulity.

NB. The workaround suggested by Fredrik Lundh doesn't solve our
particular problems, since the downsize to UTF-8 causes the multi-byte
characters to be represented in hex. Our software doesn't read those. (I
know that's our problem.)

Added file: http://bugs.python.org/file12009/patch.txt

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

I attaching webograph's patch updated to revision 67223 where I added a 
few tests.

I am +1 on the floor divide changes (allowing timedelta // timedelta), 
but I am not sure how true division should work if at all.  For the sake 
of argument, let's assume from __future__ import division or py3k.  
Currently: 

>>> timedelta(1)/2
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 
'int'
>>> timedelta(1)/timedelta(2)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 
'datetime.timedelta'

With this patch, timedelta(1)/2 is still unsupported, but

>>> timedelta(1)/timedelta(2)
0.5

Note that this is probably correct behavior because timedelta/int true 
division does not make much sense, but there is a proposal (see issue1083) to 
make timedelta/int equivalent to timedelta//int.  (I am 
against issue1083 proposal and for webograph's approach, but this needs 
to be further discussed.)

Also, I've added a test that demonstrates the following behavior:

>>> int(timedelta.min/(timedelta.min//3))
2

This is not a bug in webograph's patch, but rather a bug in long true 
division, but it shows that true division may not be as useful as it 
seems.

--
nosy: +belopolsky
Added file: http://bugs.python.org/file12010/timedeltadiv.parch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Changes by Alexander Belopolsky <[EMAIL PROTECTED]>:


--
nosy: +amaury.forgeotdarc, jribbens
versions: +Python 2.7, Python 3.1

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Why not also implementing divmod()? It's useful to split a timedelta 
into, for example, (hours, minutes, seconds):

def formatTimedelta(delta):
"""
>>> formatTimedelta(timedelta(hours=1, minutes=24, seconds=19))
'1h 24min 19sec'
"""
hours, minutes = divmodTimedelta(delta, timedelta(hours=1))
minutes, seconds = divmodTimedelta(minutes, timedelta(minutes=1))
seconds, fraction = divmodTimedelta(seconds, timedelta(seconds=1))
return "{0}h {1}min {2}sec".format(hours, minutes, seconds)

My implementation gives divmod(timedelta, timedelta) -> (long, 
timedelta). It's a little bit strange to get two different types in 
the result. The second return value is the remainder. My example works 
in the reverse order of the classical code:

def formatSeconds(seconds):
"""
>>> formatTimedelta(1*3600 + 24*60 + 19)
'1h 24min 19sec'
"""
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
return "{0}h {1}min {2}sec".format(hours, minutes, seconds)

About my new patch:
 - based on datetime_datetime_division_dupcode.patch
 - create divmod() operation on (timedelta, timedelta)
 - add unit tests for the division (floor and true division) and 
divmod
 - update the documentation for the true division and divmod

--
nosy: +haypo
Added file: http://bugs.python.org/file12011/timedelta_true_divide_divmod.patch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

On Fri, Nov 14, 2008 at 12:51 PM, STINNER Victor <[EMAIL PROTECTED]> wrote:
>
> STINNER Victor <[EMAIL PROTECTED]> added the comment:
>
> Why not also implementing divmod()? It's useful to split a timedelta
> into, for example, (hours, minutes, seconds):

I agree and in this case mod should probably be implemented too.

With your patch:

Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for %: 'datetime.timedelta' and
'datetime.timedelta'

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4321] unintended syntax error with decorators, parenthesis, and dots?

2008-11-14 Thread Georg Brandl

Georg Brandl <[EMAIL PROTECTED]> added the comment:

Closing; changing this will at least need a python-dev discussion, and
thorough motivation.

--
nosy: +georg.brandl
resolution:  -> wont fix
status: open -> closed

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

Also, why not

>>> divmod(timedelta(3), 2)
(datetime.timedelta(1), datetime.timedelta(1))

?

And where do we stop? :-)

On Fri, Nov 14, 2008 at 1:02 PM, Alexander Belopolsky
<[EMAIL PROTECTED]> wrote:
> On Fri, Nov 14, 2008 at 12:51 PM, STINNER Victor 
<[EMAIL PROTECTED]> wrote:
>>
>> STINNER Victor <[EMAIL PROTECTED]> added the comment:
>>
>> Why not also implementing divmod()? It's useful to split a timedelta
>> into, for example, (hours, minutes, seconds):
>
> I agree and in this case mod should probably be implemented too.
>
> With your patch:
>
 timedelta(3)%timedelta(2)
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: unsupported operand type(s) for %: 'datetime.timedelta' and
> 'datetime.timedelta'
>

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Since timedelta(3) // 2 is already accepted, divmod should also accept 
integers (but not float).

With the last patch and "from __future__ import division", we support:
  timedelta // 
  timedelta / timedelta
  divmod(timedelta, timedelta)

What do you think about:
  timedelta /   # only with __future__.divison
  timedelta // 
  timedelta % 
  divmod(timedelta, )
with:
  timedelta // int -> timedelta
  timedelta // timedelta -> int
  timedelta % int -> timedelta
  timedelta % timedelta -> int
  divmod(timedelta, int) -> (timedelta, timedelta)
  divmod(timedelta, timedelta) -> (int, timedelta)
  timedelta /  -> float # __future__.divison

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

While I agree that divmod may be useful, your particular use case is
not convincing. The same can be done easier without divmod:

def formatTimedelta(delta):
   return "{0}h {1}min {2}sec".format(*str(delta).split(':'))

or you can convert delta to time using an arbitrary anchor date and
extract hms that way:

(1, 24, 19)

(depending on your needs you may want to add delta.days*24 to the hours)

On Fri, Nov 14, 2008 at 12:51 PM, STINNER Victor <[EMAIL PROTECTED]> wrote:
>
> STINNER Victor <[EMAIL PROTECTED]> added the comment:
>
> Why not also implementing divmod()? It's useful to split a timedelta
> into, for example, (hours, minutes, seconds):
>
> def formatTimedelta(delta):
>"""
>>>> formatTimedelta(timedelta(hours=1, minutes=24, seconds=19))
>'1h 24min 19sec'
>"""
>hours, minutes = divmodTimedelta(delta, timedelta(hours=1))
>minutes, seconds = divmodTimedelta(minutes, timedelta(minutes=1))
>seconds, fraction = divmodTimedelta(seconds, timedelta(seconds=1))
>return "{0}h {1}min {2}sec".format(hours, minutes, seconds)
>

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

On Fri, Nov 14, 2008 at 1:28 PM, STINNER Victor <[EMAIL PROTECTED]> wrote:
..
> What do you think about:
>  timedelta /   # only with __future__.divison
>  timedelta // 
>  timedelta % 
>  divmod(timedelta, )
> with:
>  timedelta // int -> timedelta
already there

+1

+1

+1

timedelta % float -> timedelta (because int % float -> int works) ?

+1

+1

divmod(timedelta, float) -> (timedelta, timedelta) ?

-1

Only timedelta / timedelta should produce dimensionless numbers.
timedelta /  should be disallowed in true division mode.
 I am +0 on timedelta / timedelta -> float in true division mode.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

Oops, the tracker ate some lines from e-mail.  Reposting through the 
web:

On Fri, Nov 14, 2008 at 1:28 PM, STINNER Victor <[EMAIL PROTECTED]> 
wrote:
..
> What do you think about:
>  timedelta /   # only with 
__future__.divison
>  timedelta // 
>  timedelta % 
>  divmod(timedelta, )
> with:
>  timedelta // int -> timedelta
already there

>  timedelta // timedelta -> int
+1

>  timedelta % int -> timedelta
+1

>  timedelta % timedelta -> int
+1

timedelta % float -> timedelta (because int % float -> int works) ?

>  divmod(timedelta, int) -> (timedelta, timedelta)
+1

>  divmod(timedelta, timedelta) -> (int, timedelta)
+1

divmod(timedelta, float) -> (timedelta, timedelta) ?

>  timedelta /  -> float # __future__.divison
-1

Only timedelta / timedelta should produce dimensionless numbers.
timedelta /  should be disallowed in true division mode.
 I am +0 on timedelta / timedelta -> float in true division mode.
Reply

Forward

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread chafporte

New submission from chafporte <[EMAIL PROTECTED]>:

from UserList import UserList
lu = UserList()
type(lu)

python2.6 prints: 
python2.5 prints: 

--
components: None
messages: 75885
nosy: chafporte
severity: normal
status: open
title: type of UserList instance returns class instead of instance
type: behavior
versions: Python 2.6

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4322] function with modified __name__ uses original name when there's an arg error

2008-11-14 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

This is because these errors use the code object's name attribute
(f.func_code.co_name) for error messages.

--
nosy: +benjamin.peterson
priority:  -> normal

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread Raymond Hettinger

Raymond Hettinger <[EMAIL PROTECTED]> added the comment:

That is because UserList is now a new-style class as a result of it
inheriting from the new abstract base classes.  I believe this is the
way Guido wanted it and do not see any deleterious impacts from the change.

Recommend closing as "won't fix" or "invalid".

--
nosy: +rhettinger

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

Isn't policy to keep old-style classes around for compatibility in 2.x?
Especially one like UserList which is meant to be used as a base class.

--
nosy: +benjamin.peterson

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4327] Patch: simplify complex constant assignment statements

2008-11-14 Thread David Turner

New submission from David Turner <[EMAIL PROTECTED]>:

This patch adds functionality to the optimizer to simplify complex
constant assignments like:

a, (b, c) = d, e = 1, (2, 3)

The simplification is:

a = 1
d = 1
b, c = e = 2, 3

Of course, the simplified version is semantically identical.  But the
bytecode generated is faster, because there is less need to unpack
tuples.  Naturally, this only works on constants:

a, b = 1, a is not the same as
a = 1
b = a

--
files: tlee-ast-optimize-multiassign.diff
keywords: patch
messages: 75889
nosy: novalis_dt
severity: normal
status: open
title: Patch: simplify complex constant assignment statements
Added file: http://bugs.python.org/file12012/tlee-ast-optimize-multiassign.diff

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4327] Patch: simplify complex constant assignment statements

2008-11-14 Thread David Turner

David Turner <[EMAIL PROTECTED]> added the comment:

Oh, and this also involved the creation of an additional statement type,
unfortunately. The statement type, Seq, represents a sequence of
statements.  This is so that we can replace a single assign with
multiple assigns.  If that's no good, then we could do an If with test=1
instead, since the compiler knows to optimize that out.  We could also
go into the parent statement and replace the body, but that would
require significant rejiggering of the optimizer, and significant
additional complexity.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread Raymond Hettinger

Raymond Hettinger <[EMAIL PROTECTED]> added the comment:

It has been the practice to not switch old-style to new-style just for
the hell of it.  However, we do switch as part of large PEP driven
efforts like the ABC backport.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

> def formatTimedelta(delta):
>return "{0}h {1}min {2}sec".format(*str(delta).split(':'))

OMG, this is ugly! Conversion to string and reparse the formatted text :-/ 
Your code doesn't work with different units than hours, minutes or seconds:

['4 days, 1', '32', '01']
>>> str(timedelta(hours=1, minutes=32, seconds=1, microseconds=2)).split(":")
['1', '32', '01.02']

> or you can convert delta to time using an arbitrary anchor date
> and extract hms that way:

How? I don't understand your suggestion.

> (depending on your needs you may want to add delta.days*24 to the hours)

The goal of the new operators (timedelta / timedelta, divmod(timedelta, 
timedelta), etc.) is to avoid the use of the timedelta "internals" (days, 
seconds and microseconds attributes) and give a new "natural" way to process 
time deltas.

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

Fair enough.

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

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

haypo> How? I don't understand your suggestion.

Sorry, another case of mail to tracker bug.  Here is what I wrote:

"""
.. you can convert delta to time using an arbitrary anchor date and
extract hms that way:

>>> x = datetime(1,1,1) + timedelta(hours=1, minutes=24, seconds=19)
>>> x.hour,x.minute,x.second
(1, 24, 19)

(depending on your needs you may want to add delta.days*24 to the hours)
"""

but tracker ate the '>>>' lines :-(

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2706] datetime: define division timedelta/timedelta

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

@webograph: time_gmtime() and time_localtime() already use function 
pointer. I prefer function pointer than code duplication!

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread chafporte

chafporte <[EMAIL PROTECTED]> added the comment:

but like that there is no way to detect if the object
is a class or an instance. type() says it's a class in both case !

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread Raymond Hettinger

Raymond Hettinger <[EMAIL PROTECTED]> added the comment:

>>> import inspect
>>> from UserList import UserList
>>> lu = UserList()
>>> inspect.isclass(UserList)
True
>>> inspect.isclass(lu)
False

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4326] type of UserList instance returns class instead of instance

2008-11-14 Thread chafporte

chafporte <[EMAIL PROTECTED]> added the comment:

but for a user define class we have:
>class AAA:
>...  pass
>
>a = AAA()
>type(a)

and you can compare this with types.InstanceType
and it says True

where for the UserList instance the comparison with 
types.InstanceType says False

it is just not homogenous. and it make the comparison with
types.InstanceType unusable !!!

are you sure this is not breaking the API ?

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2736] datetime needs and "epoch" method

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

I like the method, but I have some comments about the new method:
 - datetime_totimestamp() is not well indented
 - "PyObject *time" should be defined at the before the first 
instruction
 - why not using "if (time == NULL) return NULL;" directly instead of 
using a block in case of time is not NULL?
 - there are reference leaks: timetuple, timestamp and 
PyFloat_FromDouble()

I wrote a similar patch before reading 
add-datetime-totimestamp-method.diff which does exactly the same... I 
attach my patch but both should be merged.

Added file: http://bugs.python.org/file12013/datetime_totimestamp.patch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2736] datetime needs and "epoch" method

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Here is a merged patch of the three patches. Except the C 
implementation of datetime_totimestamp() (written by me), all code is 
written by hodgestar.

Added file: http://bugs.python.org/file12014/datetime_totimestamp-2.patch

___
Python tracker <[EMAIL PROTECTED]>

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



[issue1726687] Bug found in datetime for Epoch time = -1

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Can anyone review the last patch?

--
keywords: +needs review
stage:  -> patch review

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2736] datetime needs and "epoch" method

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

I would like to voice my opposition the totimestamp method.

Representing time as a float is a really bad idea (originated at 
Microsoft as I have heard).  In addition to the usual numeric problems 
when dealing with the floating point, the resolution of the floating 
point timestamp varies from year to year making it impossible to 
represent high resolution historical data.

In my opinion both time.time() returning float and 
datetime.fromtimestamp() taking a float are both design mistakes and 
adding totimestamp that produces a float will further promote a bad 
practice.

I would not mind integer based to/from timestamp methods taking and 
producing seconds or even (second, microsecond) tuples, but I don't 
think changing fromtimestamp behavior is an option.

--
nosy: +belopolsky

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2736] datetime needs and "epoch" method

2008-11-14 Thread STINNER Victor

STINNER Victor <[EMAIL PROTECTED]> added the comment:

Le Saturday 15 November 2008 02:15:30 Alexander Belopolsky, vous avez écrit :
> I don't think changing fromtimestamp behavior is an option.

It's too late to break the API (Python3 is in RC stage ;-)), but we can create 
new methods like:
   datetime.fromepoch(seconds, microseconds=0)# (int/long, int)
   datetime.toepoch() -> (seconds, microseconds)  # (int/long, int)

___
Python tracker <[EMAIL PROTECTED]>

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



[issue2736] datetime needs and "epoch" method

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky <[EMAIL PROTECTED]> added the comment:

On Fri, Nov 14, 2008 at 8:37 PM, STINNER Victor <[EMAIL PROTECTED]> wrote:
> .. but we can create new methods like:
>   datetime.fromepoch(seconds, microseconds=0)# (int/long, int)

While 1970 is the most popular epoch, I've seen 1900, 2000 and even
2035 (!) being used as well.  Similarly, nanoseconds are used in high
resolution time sources at least as often as microseconds.  This makes
fromepoch() ambiguous and it is really unnecessary because it can be
written as epoch + timedelta(0, seconds, microseconds).

>   datetime.toepoch() -> (seconds, microseconds)  # (int/long, int)

I would much rather have divmod implemented as you suggested in
issue2706 .  Then toepoch is simply

def toepoch(d):
x, y = divmod(d, timedellta(0, 1))
return x, y.microseconds

___
Python tracker <[EMAIL PROTECTED]>

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



[issue3679] pressing HOME key in IDLE editor ends IDLE

2008-11-14 Thread Terry J. Reedy

Changes by Terry J. Reedy <[EMAIL PROTECTED]>:


--
resolution:  -> fixed
status: open -> closed

___
Python tracker <[EMAIL PROTECTED]>

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



[issue4313] IDLE segfault at exit

2008-11-14 Thread Hirokazu Yamamoto

Changes by Hirokazu Yamamoto <[EMAIL PROTECTED]>:


--
nosy: +kbk

___
Python tracker <[EMAIL PROTECTED]>

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