[issue32065] range_iterator doesn't have length, leads to surprised result

2017-11-17 Thread yegle

New submission from yegle :

This also affects xrange in Python2, so I chose the affected version as 
python27.

range object (and xrange in Python2) has __len__(), but the range_iterator 
object created from __reversed__() doesn't have __len__.

Python2:
>>> x = xrange(10)
>>> len(x)
10
>>> reversed(x)

>>> y = reversed(x)
>>> len(y)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: object of type 'rangeiterator' has no len()

Python3.6
>>> x = range(10)
>>> len(x)
10
>>> len(reversed(x))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: object of type 'range_iterator' has no len()

--
components: Interpreter Core
messages: 306458
nosy: yegle
priority: normal
severity: normal
status: open
title: range_iterator doesn't have length, leads to surprised result
versions: Python 2.7

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



[issue32065] range_iterator doesn't have length, leads to surprised result

2017-11-17 Thread yegle

yegle  added the comment:

Hmm I think this also applies to list_listiterator. In general I'd expect these 
to be true:

l = [1,2,3]
r = range(3)

assert len(l) == len(reversed(l))
assert len(r) == len(reversed(r))

--

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



[issue10109] itertools.product with infinite iterator cause MemoryError.

2014-10-01 Thread yegle

yegle added the comment:

Found another example that shows horrible performance when using 
itertools.product:

def gen():
  l = [itertools.permutations(range(10)) for _ in range(10)]
  g = itertools.product(*l)
  for i in g:
yield i

A simple next() to this generator takes 16 seconds on my desktop.

I use this recursive product() instead and the performance is acceptable:

def product(*args):
if len(args) == 1:
for i in args[0]:
yield [i]
else:
for i in args[0]:
for j in product(*args[1:]):
j.append(i)
yield j

--
nosy: +yegle

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



[issue19861] Update What's New for Python 3.4

2013-12-23 Thread yegle

yegle added the comment:

Hi all,

It's my first time commenting on this issue tracker so bear with me if this 
looks naive.

For the `plistlib` package, from Apple's own manual[1], there's actually a 
third JSON format.

It'll be good to indicate that `plistlib` doesn't support JSON format in the 
what's new page and corresponding document page.

It takes me sometime before I realize `plistlib` in Python 3.3 doesn't support 
the so called binary property list format. So if the JSON format won't be 
supported in this Python version, it'll save someone's time by just reading the 
manual.

[1]: 
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/plutil.1.html

--
nosy: +yegle

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



[issue20482] smtplib.SMTP.sendmail: improve exception message

2014-02-01 Thread yegle

New submission from yegle:

Currently the `msg` argument of `smtplib.SMTP.sendmail` accept a `str` in Py3k 
if every characters in this `str` is in ASCII range, or a `bytes`.

This is confusing for new comer because:

1. When you send your mail using only ASCII characters, everything is fine (no 
matter you use bytes or str).
2. When sometimes you included non-ASCII characters in your email, the 
traceback is hard to understand.

Here's an example of such traceback:

Traceback (most recent call last):
  File "./manage.py", line 113, in 
manager.run()
  File 
"/data/web/cgi-bin/venv/lib/python3.3/site-packages/flask_script/__init__.py", 
line 405, in run
result = self.handle(sys.argv[0], sys.argv[1:])
  File 
"/data/web/cgi-bin/venv/lib/python3.3/site-packages/flask_script/__init__.py", 
line 384, in handle
return handle(app, *positional_args, **kwargs)
  File 
"/data/web/cgi-bin/venv/lib/python3.3/site-packages/flask_script/commands.py", 
line 145, in handle
return self.run(*args, **kwargs)
  File "./manage.py", line 108, in run
conn.send(msg)
  File "/data/web/cgi-bin/venv/lib/python3.3/site-packages/flask_mail.py", line 
168, in send
message.as_string())
  File "/data/web/cgi-bin/python-3.3.3/lib/python3.3/smtplib.py", line 747, in 
sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\u9f99' in position 
646: ordinal not in range(128)

Here's my proposal:

--- smtplib.py.orig 2014-02-01 21:26:47.0 -0500
+++ smtplib.py  2014-02-01 21:37:51.0 -0500
@@ -744,7 +744,12 @@
 esmtp_opts = []
 print(msg)
 if isinstance(msg, str):
-msg = _fix_eols(msg).encode('ascii')
+try:
+msg = _fix_eols(msg).encode('ascii')
+except UnicodeEncodeError:
+raise SMTPException(
+"msg may be a string containing characters in the "
+"ASCII range, or a byte string.")
 if self.does_esmtp:
     # Hmmm? what's this? -ddm
 # self.esmtp_features['7bit']=""

--
components: email
messages: 209943
nosy: barry, r.david.murray, yegle
priority: normal
severity: normal
status: open
title: smtplib.SMTP.sendmail: improve exception message
type: enhancement
versions: Python 3.3

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



[issue20482] smtplib.SMTP.sendmail: improve exception message

2015-02-22 Thread yegle

yegle added the comment:

I have no plan to work further, Mark can take the code and improve anyway you 
want.

--

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