[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I concur with the others.  This is unnecessary feature creep that doesn't make 
sense for typical use cases.

--
nosy: +rhettinger
resolution:  -> rejected
stage:  -> 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



Re: Need help with getting Key, Value out of dicts in lists

2017-04-08 Thread Irv Kalb
[ Sorry, forgot the important stuff! ]

What you want to do is tricky because your data structure is difficult to deal 
with.  My guess is that it has to do with a misconception about how a Python 
dictionary works. Yes, it is a series of key/value pairs, but not the way you 
have it.   It looks like you put together dictionaries where each dictionary 
has a 'Value' and a 'Key'.

Instead, _each_ item in a dictionary is a key value pair. The key is typically 
a string, and the value is obviously some value associated with that key.  For 
example, if you have the ability to rebuild your data a different way, it looks 
like it would be better to deal with it something like this:

aList = [
   {'Name':'shibboleth-prd', 'Billing':'kmvu', 'Resource_group_id': 
'20179204-181622543367489'},
   {'Name':'shibboleth-tst', 
'Resource_group_id':'20172857-152037106154311'}
   ]

This is a list of dictionaries.  However, I'm not sure what you are trying to 
do with this data.  I'm guessing that you want to match a resource group id, 
and if you find it, print the name and the billing info if they exist.  If so, 
you may want something like this (untested):

def printInfo(thisGroupID):
   for thisDict in aList:# loop through all dictionaries in the list
if thisGroupID == aList['Resource_group_id']:
   if 'Name' in thisDict:   # if thisDict has a key called 'Name'
   print ('Name is', thisDict['Dict'])
   if 'Billing' in thisDict:   #  if thisDict has a key called 'Billing'
   print ('Billing is', thisDict['Billing'])

Hope this helps,

Irv
> On Apr 8, 2017, at 9:04 PM, Irv Kalb  wrote:
> 
> What you want to do is tricky because your data structure is difficult to 
> deal with.  My guess is that it has to do with a misconception about how a 
> Python dictionary works. Yes, it is a series of key/value pairs, but not the 
> way you have it.   It looks like you put together dictionaries where each 
> dictionary has a 'Value' and a 'Key'.
> 
> Instead, _each_ item in a dictionary is a key value pair. The key is 
> typically a string, and the value is obviously some value associated with 
> that key.  For example, if you have the ability to rebuild your data a 
> different way, it looks like it would be better to deal with it something 
> like this:
> 
> aList = [
>{'Name':'shibboleth-prd', 'Billing':'kmvu', 'Resource_group_id': 
> '20179204-181622543367489'},
>{'Name':'shibboleth-tst', 
> 'Resource_group_id':'20172857-152037106154311'}
>]
> 
> This is a list of dictionaries.  However, I'm not sure what you are trying to 
> do with this data.  I'm guessing that you want to match a resource group id, 
> and if you find it, print the name and the billing info if they exist.  If 
> so, you may want something like this (untested):
> 
> def printInfo(thisGroupID):
>for thisDict in aList:# loop through all dictionaries in the list
>   if thisGroupID == aList['Resource_group_id']:
>if 'Name' in thisDict:   # if thisDict has a key called 'Name'
>print ('Name is', thisDict['Dict'])
>if 'Billing' in thisDict:   #  if thisDict has a key called 
> 'Billing'
>print ('Billing is', thisDict['Billing'])
> 
> Hope this helps,
> 
> Irv
> 
> 
> 
>> On Apr 8, 2017, at 5:55 PM, Kenton Brede  wrote:
>> 
>> This is an example of the data I'm working with.  The key/value pairs may
>> come in any order. There are some keys like the 'Resource_group_id' key and
>> the 'Name' key which will always be present, but other lists may have
>> unique keys.
>> 
>> alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu',
>> u'Key': 'Billing'},
>>   {u'Value': '20179204-181622543367489', u'Key':
>> 'Resource_group_id'}],
>>  [{u'Value': '20172857-152037106154311', u'Key':
>> 'Resource_group_id'},
>>   {u'Value': 'shibboleth-tst', u'Key': 'Name'}]]
>> 
>> What I want to do is something along the lines of:
>> 
>> for a in alist:
>>   if a['Resource_group_id'] == '01234829-2041523815431':
>>   print the Value of 'Name'
>>   print the Value of 'Billing'
>> 
>> I've found I can do the following, to print the value of 'Name' but that
>> only works if the 'Resource_group_id' key is the first key in the list and
>> the 'Name' key is in the second slot.  If each list contained the same
>> keys, I could probably sort the keys and use [num] to pull back values, but
>> they don't.
>> 
>> for a in alist:
>>   if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] ==
>> '20172857-152037106154311':
>>   print a[1]['Value']
>> 
>> There has to be a way to do this but I've been pounding away at this for
>> hours.  Any help appreciated.  I'm new to Python and not a programmer, so
>> go easy on me. :)
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
>> 
> 

-- 

Re: Need help with getting Key, Value out of dicts in lists

2017-04-08 Thread Irv Kalb

> On Apr 8, 2017, at 5:55 PM, Kenton Brede  wrote:
> 
> This is an example of the data I'm working with.  The key/value pairs may
> come in any order. There are some keys like the 'Resource_group_id' key and
> the 'Name' key which will always be present, but other lists may have
> unique keys.
> 
> alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu',
> u'Key': 'Billing'},
>{u'Value': '20179204-181622543367489', u'Key':
> 'Resource_group_id'}],
>   [{u'Value': '20172857-152037106154311', u'Key':
> 'Resource_group_id'},
>{u'Value': 'shibboleth-tst', u'Key': 'Name'}]]
> 
> What I want to do is something along the lines of:
> 
> for a in alist:
>if a['Resource_group_id'] == '01234829-2041523815431':
>print the Value of 'Name'
>print the Value of 'Billing'
> 
> I've found I can do the following, to print the value of 'Name' but that
> only works if the 'Resource_group_id' key is the first key in the list and
> the 'Name' key is in the second slot.  If each list contained the same
> keys, I could probably sort the keys and use [num] to pull back values, but
> they don't.
> 
> for a in alist:
>if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] ==
> '20172857-152037106154311':
>print a[1]['Value']
> 
> There has to be a way to do this but I've been pounding away at this for
> hours.  Any help appreciated.  I'm new to Python and not a programmer, so
> go easy on me. :)
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue29944] Argumentless super() fails in classes constructed with type()

2017-04-08 Thread Dan Snider

Dan Snider added the comment:

Just wanted to add that I found this when I was trying to find a way to 
decorate all methods in a class without using a metaclass or modifying 
__getattr__.


Using Josh's workaround, here's a simple demonstration that (at least at first 
glance) prints a message when a method is called and when it is finished:

def mydec(*, enter=True, exit=True):
def make_closure(__class__):
return (lambda: super).__closure__
def outer(cls):
def wrapper(method):
@functools.wraps(method)
def inner(*args, **kwargs):
if enter:
print('entering', method.__qualname__)
r = method(*args, **kwargs)
if exit:
print('exiting', method.__qualname__)
return method(*args, **kwargs)
return inner
for name, value in cls.__dict__.items():
if isinstance(value, types.FunctionType):
method = types.FunctionType(getattr(cls, name).__code__,
globals(),
closure=make_closure(cls))
setattr(cls, name, wrapper(method))
return cls
return outer

--

___
Python tracker 

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



Re: Python and the need for speed

2017-04-08 Thread Chris Angelico
On Sun, Apr 9, 2017 at 10:20 AM,   wrote:
> I've an idea that http://www.mos6581.org/python_need_for_speed is a week late 
> for April Fool's but just in case I'm sure that some of you may wish to 
> comment.
>

>From that page:

> Other candidates for banishment from TurboPython include eval and exec.

Bye bye namedtuple. And compile() is going to have to go, since you
could implement eval/exec by creating a new function:

>>> runme = r"""
  print("Hello, world!")
  import sys
  sys.stdout.write("I can import modules.\n")
"""
>>> type(lambda: 1)(compile("def f():" + runme, "exec", "exec").co_consts[0], 
>>> globals())()
Hello, world!
I can import modules.

So if compile() goes, you also lose ast.parse, which means you lose
introspection tools, plus you lose literal_eval and friends. I'm also
not sure whether the import machinery would have to be rewritten, but
a quick 'git grep' suggests that it would. Removing eval and exec is
not as simple as removing them from the standard library.

In fact, extreme dynamism is baked deep into the language. You'd have
to make some fairly sweeping language changes to get any real benefits
from restricting things. There are better ways to improve performance,
which is why statickification isn't really pursued.

These kinds of posts always come from people who haven't actually
tried it. They think that, hey, it'd be easy to just make a subset of
Python that's optimizable! But if you actually *do* it, you'd have to
either restrict the language HUGELY, or reimplement all sorts of
things in a slower way.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and the need for speed

2017-04-08 Thread Thomas Nyberg
On 04/08/2017 05:20 PM, breamore...@gmail.com wrote:
> I've an idea that http://www.mos6581.org/python_need_for_speed is a week late 
> for April Fool's but just in case I'm sure that some of you may wish to 
> comment.
> 
> Kindest regards.
> 
> Mark Lawrence.
> 
Regarding your restricted subset of python you call turbopython, have
you looked into rpython which is a restricted subset of python used by
pypy to implement their jit?

http://rpython.readthedocs.io/en/latest/faq.html#what-is-this-rpython-language
-- 
https://mail.python.org/mailman/listinfo/python-list


Need help with getting Key, Value out of dicts in lists

2017-04-08 Thread Kenton Brede
This is an example of the data I'm working with.  The key/value pairs may
come in any order. There are some keys like the 'Resource_group_id' key and
the 'Name' key which will always be present, but other lists may have
unique keys.

alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu',
u'Key': 'Billing'},
{u'Value': '20179204-181622543367489', u'Key':
'Resource_group_id'}],
   [{u'Value': '20172857-152037106154311', u'Key':
'Resource_group_id'},
{u'Value': 'shibboleth-tst', u'Key': 'Name'}]]

What I want to do is something along the lines of:

for a in alist:
if a['Resource_group_id'] == '01234829-2041523815431':
print the Value of 'Name'
print the Value of 'Billing'

I've found I can do the following, to print the value of 'Name' but that
only works if the 'Resource_group_id' key is the first key in the list and
the 'Name' key is in the second slot.  If each list contained the same
keys, I could probably sort the keys and use [num] to pull back values, but
they don't.

for a in alist:
if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] ==
'20172857-152037106154311':
print a[1]['Value']

There has to be a way to do this but I've been pounding away at this for
hours.  Any help appreciated.  I'm new to Python and not a programmer, so
go easy on me. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Python and the need for speed

2017-04-08 Thread breamoreboy
I've an idea that http://www.mos6581.org/python_need_for_speed is a week late 
for April Fool's but just in case I'm sure that some of you may wish to comment.

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: read in a list in a file to list

2017-04-08 Thread Rick Johnson
@John

General debugging methodology dictates that when your output
does not match your expectation, you must never assume
anything. Here you made the fatal mistake of assuming that:
(1) files are stored as list objects, or (2) Python
automatically converts file data to list objects, or (3)
that python can read your mind, and knowing that you wanted
a list, gave you a list. But in any of those cases, you
would be wrong.

To discover the source of the problem, use Python's
wonderful introspection capabilities. In this case, the
built-in function named "type" is your friend.

> apefile = open("apefile.txt")
> apelist = apefile.read()

print(type(apelist))

I would also make a slight quibble reguarding your choice of
variable names. I would recommend "fileObj" and "fileData"
respectively. Unless you are comparing the contents of two
or more files (say: "apeData", "monkeyData" and
"marmosetData") there is no need for the "ape" mnemonic. Use
a generic name instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue23674] super() documentation isn't very clear

2017-04-08 Thread Martin Panter

Martin Panter added the comment:

The magical no-argument call could also be clarified:

8. Define in the main text what happens when you omit the first argument (the 
subclass) to “super”. At the moment, I think the reader could infer that it is 
the method’s class, but this is only hinted by reading the comment in the 
illustration and Raymond’s external web page. The documentation should also 
clarify how it works, or at least be clear when it is not supported (e.g. one 
method assigned to multiple classes, functions defined outside a class 
definition, decorators that re-create the class, “super” renamed).

9. The no-argument call creates an instance bound to the first argument of the 
method, not an unbound instance. Determining the “self” argument is also 
magical: it does not seem to work with default arguments, variable positional 
arguments, nor keyword-only arguments. List comprehensions, generator 
expressions, etc seem to override it, and the argument is not seen by exec and 
eval.

--

___
Python tracker 

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



[issue29944] Argumentless super() fails in classes constructed with type()

2017-04-08 Thread Martin Panter

Martin Panter added the comment:

In Issue 23674, I posted a patch that changes to consistent parameter names 
(subclass, self). The exception message would avoid “type”, becoming

super(subclass, self): self must be an instance or subtype of subclass

--
nosy: +martin.panter

___
Python tracker 

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



[issue29957] unnecessary LBYL for key contained in defaultdict, lib2to3/btm_matcher

2017-04-08 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
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



[issue26860] Make os.walk and os.fwalk yield namedtuple instead of tuple

2017-04-08 Thread Giampaolo Rodola'

Giampaolo Rodola' added the comment:

Should we have concerns about performances? Accessing a namedtuple value is 
almost 4x times slower compared to a plain tuple [1] and os.walk() may iterate 
hundreds of times.

http://stackoverflow.com/questions/2646157/what-is-the-fastest-to-access-struct-like-object-in-python

--
nosy: +giampaolo.rodola

___
Python tracker 

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



[issue30008] OpenSSL 1.1.0 deprecated functions

2017-04-08 Thread Mike Gilbert

Mike Gilbert added the comment:

Thanks for the reply.

OpenSSL 1.1.0 added functions to control the SSL/TLS version used by SSL 
contexts created using TLS_method(). You might consider updating the code for 
existing Python branches to use these functions.

SSL_CTX_set_min_proto_version
SSL_CTX_set_max_proto_version

https://www.openssl.org/docs/man1.1.0/ssl/SSL_CTX_set_min_proto_version.html

--

___
Python tracker 

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



Re: read in a list in a file to list

2017-04-08 Thread boB Stepp
On Sat, Apr 8, 2017 at 3:21 PM,   wrote:
> On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote:
>> Hi,
>>
>> I am using Python 3.6 on Windows 7.
>>
>> I have a file called apefile.txt. apefile.txt's contents are:
>>
>> apes =  "Home sapiens", "Pan troglodytes", "Gorilla gorilla"
>>
>> I have a script:
>>
>> apefile =  open("apefile.txt")
>> apelist =  apefile.read()

I think you misunderstand what the read() method is doing here.  It
does not return a list.  Instead, it returns the entire file as a
single string.

>> for ape in apelist:

So here despite the variable name you chose, you are acutally
iterating over the entire file contents character by character.  See
Mark's answer/hint below on how to iterate over the file contents by
line.  You might want to look up the docs on how to use these file
objects and their methods.

>> print("one of the apes is " + ape)
>> apefile.close()
>>
>> The output from the script does not print the ape names, instead it
>> prints each letter in the file. For example:
>>
>> one of the apes is a
>> one of the apes is p
>> one of the apes is e
>>
>> What should I do instead to get something like
>>
>> one of the apes is Home sapiens
>> one of the apes is Pan troglodytes
>> one of the apes is Gorilla gorilla
>>
>> John
>
> I'll start you off.
>
> with open("apefile.txt") as apefile:
> for line in apefile:
> doSomething(line)
>
> String methods and/or the csv module might be used here in doSomething(line), 
> but I'll leave that to you so that you can learn.  If you get stuck please 
> ask again, we don't bite :)


-- 
boB
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: read in a list in a file to list

2017-04-08 Thread breamoreboy
On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote:
> Hi,
> 
> I am using Python 3.6 on Windows 7.
> 
> I have a file called apefile.txt. apefile.txt's contents are:
> 
> apes =  "Home sapiens", "Pan troglodytes", "Gorilla gorilla"
> 
> I have a script:
> 
> apefile =  open("apefile.txt")
> apelist =  apefile.read()
> for ape in apelist:
> print("one of the apes is " + ape)
> apefile.close()
> 
> The output from the script does not print the ape names, instead it 
> prints each letter in the file. For example:
> 
> one of the apes is a
> one of the apes is p
> one of the apes is e
> 
> What should I do instead to get something like
> 
> one of the apes is Home sapiens
> one of the apes is Pan troglodytes
> one of the apes is Gorilla gorilla
>  
> John

I'll start you off.

with open("apefile.txt") as apefile:
for line in apefile:
doSomething(line)

String methods and/or the csv module might be used here in doSomething(line), 
but I'll leave that to you so that you can learn.  If you get stuck please ask 
again, we don't bite :)

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I vote -1 too.

1. As was said, this doesn't work with all attribute names.
2. This adds circular dependency between operator and collections modules.
3. This increases memory consumption and startup time for small programs that 
don't use the collections module.
4. Performance. Creating a namedtuple is slower than creating a tuple, and many 
code is optimized for raw tuples.
5. This increases the complexity of attrgetter() implementation and can 
introduce new bugs.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue30008] OpenSSL 1.1.0 deprecated functions

2017-04-08 Thread Christian Heimes

Christian Heimes added the comment:

Thanks for your report.

Python is going to require legacy functions like TLSv1_method() for a while. 
They are required to provide constants like PROTOCOL_TLSv1. I have deprecated 
these constants in 3.6 and they will be removed in 3.8. In the mean time Python 
is not compatible with OpenSSL api=1.1.0.

--

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Christian Heimes

Christian Heimes added the comment:

I'm with RDM and vote -1, too.

A namedtuple is a bit more costly than a normal tuple. That's especially try 
for dynamic attrgetter() that are defined ad-hoc, e.g. as key function for 
sorted(). The creation of type classes doesn't come for free.

--
nosy: +christian.heimes

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread R. David Murray

R. David Murray added the comment:

This is a clever idea, but I vote -1 for this proposal.  I think it makes 
attrgetter more complex for little purpose.  The fact that only some attribute 
names work and the others get mangled makes the API very ugly and not, IMO, 
desirable.

Finally, if you want this, you can pretty easily write a function that wraps 
attrgetter to do it.  I don't think it has enough utility to justify being in 
the stdlib.

--
nosy: +r.david.murray

___
Python tracker 

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



read in a list in a file to list

2017-04-08 Thread john polo

Hi,

I am using Python 3.6 on Windows 7.

I have a file called apefile.txt. apefile.txt's contents are:

apes =  "Home sapiens", "Pan troglodytes", "Gorilla gorilla"

I have a script:

apefile =  open("apefile.txt")
apelist =  apefile.read()
for ape in apelist:
   print("one of the apes is " + ape)
apefile.close()


The output from the script does not print the ape names, instead it 
prints each letter in the file. For example:


one of the apes is a
one of the apes is p
one of the apes is e


What should I do instead to get something like

one of the apes is Home sapiens
one of the apes is Pan troglodytes
one of the apes is Gorilla gorilla



John
--
https://mail.python.org/mailman/listinfo/python-list


[issue30014] Speedup DefaultSelectors.modify() by 2x

2017-04-08 Thread Giampaolo Rodola'

Giampaolo Rodola' added the comment:

For the sake of experiment I'm attaching a toy echo server which uses modify() 
to switch between EVENT_READ and EVENT_WRITE. Without patch I get 35000 
req/sec, with patch around 39000 req/sec (11.4% faster).
To be entirely honest a smarter echo server would switch between EVENT_READ / 
EVENT_WRITE only in case of BlockingIOError on send() or recv(), but 
unfortunately it's a condition which (for send()) does not occur often by 
testing on localhost (for recv() it naturally occurs +27000 times out of 
39000). On the other hand, by experimenting with a real network it occurs quite 
soon:

import socket
sock = socket.socket()
sock.connect(('google.com', 80))
sock.setblocking(False)
print(sock.send(b'x' * 5))
print(sock.send(b'x' * 5))  # raise BlockingIOError

So basically my benchmark is emulating a worst case scenario in which send() 
always blocks on the first call and succeed on the next one, in order to mimic 
recv() which blocks half of the times.
The whole point is that the speedup entirely depends on how many times send() 
or recv() will block in a real world app connected to the internet (because 
that's when modify() is supposed to be used) but that's hard to determine, 
especially under heavy server loads which is hard to emulate. This also 
involves the SSL handshake when it fails with WANT_READ / WANT_WRITE, which is 
another circumstance where modify() is going to be used and for which I have no 
benchmarks.
I personally don't mind about selectors module per-se, but given that it's the 
core of important libs such as asyncio and curio I would like to hear a better 
rationale than "let's reject this 1.5x speedup because DRY does not apply in 
this case".
Also please consider that Tornado, Twisted and gevent use native modify() 
method.

--
Added file: http://bugs.python.org/file46792/echo_server.py

___
Python tracker 

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



[issue30014] Speedup DefaultSelectors.modify() by 2x

2017-04-08 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' :


Added file: http://bugs.python.org/file46793/echo_client.py

___
Python tracker 

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



[issue29957] unnecessary LBYL for key contained in defaultdict, lib2to3/btm_matcher

2017-04-08 Thread Jim Fasarakis-Hilliard

Jim Fasarakis-Hilliard added the comment:

bump to close issue now that PR was merged

--
nosy: +Jim Fasarakis-Hilliard

___
Python tracker 

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



[issue29963] Remove obsolete declaration PyTokenizer_RestoreEncoding in tokenizer.h

2017-04-08 Thread Jim Fasarakis-Hilliard

Changes by Jim Fasarakis-Hilliard :


--
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



[issue29944] Argumentless super() fails in classes constructed with type()

2017-04-08 Thread Jim Fasarakis-Hilliard

Changes by Jim Fasarakis-Hilliard :


--
nosy: +Jim Fasarakis-Hilliard

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Isaac Morland

Isaac Morland added the comment:

What are the "other issues"?

As to the issue you raise here, that's why I use rename=True.

First create a type with an underscore attribute:

>>> t = namedtuple ('t', ['a', '1234'], rename=True)

(just an easy way of creating such a type; used of namedtuple specifically is 
admittedly a bit of a red herring)

Now create an object and illustrate its attributes:

>>> tt = t ('c', 'd')
>>> tt.a
'c'
>>> tt._1
'd'

Now use my modified attrgetter to get the attributes as a namedtuple:

>>> attrgetter ('a', '_1') (tt)
attrgetter(a='c', _1='d')
>>> 

And the example from the help, used in the test file I've already attached, 
illustrates that the dotted attribute case also works.

Essentially, my patch provides no benefit for attrgetter specified attributes 
that aren't valid namedtuple attribute names, but because of rename=True it 
still works and doesn't break anything.  So if you give "a" as an attribute 
name, the output will have an "a" attribute; if you give "_b" as an attribute 
name, the output will have an "_1" (or whatever number) attribute.  Similarly, 
it doesn't help with dotted attributes, but it doesn't hurt either.

--

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Josh Rosenberg

Josh Rosenberg added the comment:

Aside from other issues, namedtuples can't have fields beginning with 
underscores, attrgetter can get attributes beginning with underscores (and 
dotted attributes for that matter). There isn't going to be an obvious or 
intuitive mapping to apply here.

--
nosy: +josh.r

___
Python tracker 

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



[issue19225] lack of PyExc_BufferError doc

2017-04-08 Thread KINEBUCHI Tomohiko

KINEBUCHI Tomohiko added the comment:

Oh, I have overlooked these sentences.
I will create an additional pull request to remove duplication.

--

___
Python tracker 

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



[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-08 Thread Berker Peksag

Berker Peksag added the comment:

> row_factory seems to be another parameter that can be set in the Cursor 
> object.
> https://github.com/python/cpython/blob/master/Modules/_sqlite/cursor.c#L65 
> 
> This can addressed in a different issue/ pr.

Like I already said in msg290943, Cursor.row_factory is kept for backwards 
compatibility reasons and it shouldn't be documented.

--

___
Python tracker 

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



[issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

2017-04-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Multi-inheritance is tricky to get right, both for the class being extended and 
the class extending it.  The APIs mentioned here were never designed for 
multiple inheritance and aren't supposed to support it.

Your use case would probably be better served by using composition rather than 
inheritance.  Speaking personally, I almost never subclass Thread, instead I 
make it an attribute of whatever class I'm writing.

--
nosy: +pitrou

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Isaac Morland

Isaac Morland added the comment:

I've attached a file which illustrates what I'm proposing to happen with the 
examples from the help.  Note that attrgetter (attr) is not affected, only 
attrgetter (*attrs) for more than one attribute.  The idea is that tuples 
resulting from attrgetter functions will retain the attribute names from the 
original object.  In some work I have done recently this would have been very 
handy with groupby.

I had some initial confusion because changing the Python attrgetter 
implementation didn't make any difference.  Once I realized I needed to turn 
off import of the C implementation, I figured the rest out fairly quickly.  
Here is the diff:

diff --git a/Lib/operator.py b/Lib/operator.py
index 0e2e53e..9b2a8fa 100644
--- a/Lib/operator.py
+++ b/Lib/operator.py
@@ -247,8 +247,12 @@ class attrgetter:
 else:
 self._attrs = (attr,) + attrs
 getters = tuple(map(attrgetter, self._attrs))
+
+from collections import namedtuple
+nt = namedtuple ('attrgetter', self._attrs, rename=True)
+
 def func(obj):
-return tuple(getter(obj) for getter in getters)
+return nt._make (getter(obj) for getter in getters)
 self._call = func
 
 def __call__(self, obj):
@@ -409,7 +413,7 @@ def ixor(a, b):
 
 
 try:
-from _operator import *
+pass
 except ImportError:
 pass
 else:

There are some issues that still need to be addressed.  The biggest is that 
I've turned off the C implementation.  I assume that we'll need a C 
implementation the new version.  In addition to this:

1) I just call the namedtuple type "attrgetter".  I'm thinking something 
obtained by mashing together the field names or something similar might be more 
appropriate.  However, I would prefer not to repeat the logic within namedtuple 
that deals with field names that aren't identifiers.  So I'm wondering if maybe 
I should also modify namedtuple to allow None as the type name, in which case 
it would use an appropriate default type name based on the field names.

2) I import from collections inside the function.  It didn't seem to work at 
the top-level, I'm guessing because I'm in the library and collections isn't 
ready when operator is initialized.  This may be fine I just point it out as 
something on which I could use advice.

I'm hoping this provides enough detail for people to understand what I'm 
proposing and evaluate whether this is a desireable enhancement.  If so, I'll 
dig into the C implementation next, although I may need assistance with that.

--
Added file: http://bugs.python.org/file46791/test_attrgetter.py

___
Python tracker 

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



[issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> rhettinger

___
Python tracker 

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



[issue30006] Deadlocks in `concurrent.futures.ProcessPoolExecutor`

2017-04-08 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +bquinlan, davin, pitrou
stage:  -> patch review

___
Python tracker 

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



[issue30022] Get rid of using EnvironmentError and IOError

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1203

___
Python tracker 

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



[issue30022] Get rid of using EnvironmentError and IOError

2017-04-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

EnvironmentError and IOError now are aliases to OSError. But some code still 
use them. Proposed patch replaces all uses of EnvironmentError and IOError 
(except tests and scripts) with OSError. This will make the code cleaner and 
more uniform.

--
messages: 291332
nosy: serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Get rid of using EnvironmentError and IOError
type: enhancement
versions: Python 3.7

___
Python tracker 

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



[issue29943] PySlice_GetIndicesEx change broke ABI in 3.5 and 3.6 branches

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

PR 1049 and PR 1050 restore ABI compatibility in 3.5 and 2.7. Unfortunately 
this restores the original bug with using PySlice_GetIndicesEx in third-party 
code (but CPython core and standard extensions no longer use 
PySlice_GetIndicesEx).

Can we consider 3.6.0 rather than 3.6.1 as broken release?

--
components: +Interpreter Core
stage:  -> patch review
type:  -> behavior

___
Python tracker 

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



[issue29943] PySlice_GetIndicesEx change broke ABI in 3.5 and 3.6 branches

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1202

___
Python tracker 

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



[issue29943] PySlice_GetIndicesEx change broke ABI in 3.5 and 3.6 branches

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1201

___
Python tracker 

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



Re: Elastic Search

2017-04-08 Thread Paul Rubin
Steve D'Aprano  writes:
> What's elastic search?
> And what does this have to do with Python?

https://www.elastic.co/  (formerly elasticsearch.org).

It's a Lucene-based distributed search engine, something like Solr if
you're used to that.  It has Python client libraries.  That's the
closest Python connection that I know of.  I've never used it but I've
used Solr.  These things are good tools to have available if you need to
index a lot of text.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

New changeset b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8 by Serhiy Storchaka in 
branch 'master':
Expand the PySlice_GetIndicesEx macro. (#1023)
https://github.com/python/cpython/commit/b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8

New changeset c26b19d5c7aba51b50a4d7fb5f8291036cb9da24 by Serhiy Storchaka in 
branch '3.6':
Expand the PySlice_GetIndicesEx macro. (#1023) (#1046)
https://github.com/python/cpython/commit/c26b19d5c7aba51b50a4d7fb5f8291036cb9da24

New changeset fa25f16a4499178d7d79c18d2d68be7f70594106 by Serhiy Storchaka in 
branch '3.5':
Expand the PySlice_GetIndicesEx macro. (#1023) (#1045)
https://github.com/python/cpython/commit/fa25f16a4499178d7d79c18d2d68be7f70594106

--

___
Python tracker 

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



[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset e41390aca51e4e3eb455cf3b70f5d656a2814db9 by Serhiy Storchaka in 
branch '2.7':
bpo-27867: Expand the PySlice_GetIndicesEx macro. (#1023) (#1046)
https://github.com/python/cpython/commit/e41390aca51e4e3eb455cf3b70f5d656a2814db9


--

___
Python tracker 

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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset e63f8f293a96ceebf06de15b4e1c97dbbff0f6a8 by Serhiy Storchaka in 
branch '3.5':
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010) 
(#1043)
https://github.com/python/cpython/commit/e63f8f293a96ceebf06de15b4e1c97dbbff0f6a8


--

___
Python tracker 

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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset af685f9050416da8050e0ec11a8dff9afd4130e7 by Serhiy Storchaka in 
branch '3.6':
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010) 
(#1042)
https://github.com/python/cpython/commit/af685f9050416da8050e0ec11a8dff9afd4130e7


--

___
Python tracker 

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



[issue30021] Add examples for re.escape()

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1200

___
Python tracker 

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



[issue30021] Add examples for re.escape()

2017-04-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Proposed patch adds examples of using re.escape().

See also issue29995.

--
assignee: docs@python
components: Documentation, Regular Expressions
messages: 291326
nosy: docs@python, ezio.melotti, mrabarnett, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Add examples for re.escape()
type: enhancement
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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



[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-08 Thread Peter

Peter added the comment:

OK, thanks. Given this is regarded as an enhancement rather than a bug fix, I 
understand the choice not to change this in Python 2.7.

--

___
Python tracker 

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



[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1198

___
Python tracker 

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



[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1197

___
Python tracker 

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



[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1199

___
Python tracker 

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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1196

___
Python tracker 

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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1195

___
Python tracker 

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



[issue29914] Incorrect signatures of object.__reduce__() and object.__reduce_ex__()

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
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



[issue29998] Pickling and copying ImportError doesn't preserve name and path

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset b785396ab451b0c9d6ae9ee5a9e56c810209a6cb by Serhiy Storchaka in 
branch 'master':
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010)
https://github.com/python/cpython/commit/b785396ab451b0c9d6ae9ee5a9e56c810209a6cb


--

___
Python tracker 

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



[issue29914] Incorrect signatures of object.__reduce__() and object.__reduce_ex__()

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset 205e00c5cfd495a4dc6dae8e8fa0fb828fb3dca9 by Serhiy Storchaka in 
branch 'master':
bpo-29914: Fix default implementations of __reduce__ and __reduce_ex__(). (#843)
https://github.com/python/cpython/commit/205e00c5cfd495a4dc6dae8e8fa0fb828fb3dca9


--

___
Python tracker 

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



[issue29956] math.exp documentation is misleading

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Not always. For example for x = 0 both methods give the same exact result.

--

___
Python tracker 

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



[issue23894] lib2to3 doesn't recognize rb'...' and f'...' in Python 3.6

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Should this issue be closed now?

--

___
Python tracker 

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



[issue30020] Make attrgetter use namedtuple

2017-04-08 Thread Steven D'Aprano

Steven D'Aprano added the comment:

Before writing a patch that may be rejected, can you explain in detail what 
change you propose? Example(s) will be good.

For example:

py> from operator import attrgetter
py> f = attrgetter('keys')
py> f({})


I don't see a tuple here, so what (if anything) are you planning to change?


How about the example from help(attrgetter)?

 |  After h = attrgetter('name.first', 'name.last'), the call h(r) returns
 |  (r.name.first, r.name.last).

--
nosy: +steven.daprano

___
Python tracker 

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



[issue30017] zlib.error: Error -2 while flushing: inconsistent stream state

2017-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1194

___
Python tracker 

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



[issue30017] zlib.error: Error -2 while flushing: inconsistent stream state

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I agree, that close() should be an idempotent operation. Proposed patch fixes 
this.

--
assignee:  -> serhiy.storchaka
components: +Library (Lib)
stage: needs patch -> patch review
versions: +Python 3.7

___
Python tracker 

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



[issue19225] lack of PyExc_BufferError doc

2017-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset 7f85947106aff5b1f166a57f644f987db4d38bf0 by Serhiy Storchaka 
(cocoatomo) in branch '2.7':
[2.7] bpo-19225: Lack of c api exceptions doc (#964)
https://github.com/python/cpython/commit/7f85947106aff5b1f166a57f644f987db4d38bf0


--

___
Python tracker 

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