[issue35533] argparse standard error usage for exit / error

2019-02-07 Thread paul j3


paul j3  added the comment:

The proposed PR does not address this issue.  It just adds comments to the 
method code, which aren't really needed.  The method is short and obvious.  We 
don't need, at this time, to get into questions of whether comments in 
argparse.py conform to one of the PEPs.

All this issue needs is a change to the documentation.  Changing:

ArgumentParser.exit(status=0, message=None)

This method terminates the program, exiting with the specified status and, if 
given, it prints a message before that.

to:

ArgumentParser.exit(status=0, message=None)

This method terminates the program, exiting with the specified status and, if 
given, it prints a message to **standard error** before that.

While I'm not opposed to this change, I don't think it is important.  

The documentation makes these two methods public, which I believe serves two 
purposes:

- developers may want to issue their own `parser.error('...')` call, during 
post-parsing value checking, or issue their own `parser.exit()` call in a 
custom 'Action' class (much like what '_HelpAction' does).

- developers might want to modify one or both of these in a ArgumentParser 
subclass.  The unittesting code in argparse does this to capture and redirect 
errors.

In both cases I expect the developer will want to read the code as well as the 
documentation.  The fact that `exit()` uses stderr is quite obvious from the 
code.  

It's worth keeping in mind that the documentation never replicates the code.  
For example, in this case the documentation says error(), "terminates the 
program with a status code of 2.", when what it really does is "terminates with 
a call to exit(status=2)".

--

___
Python tracker 

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



[issue35937] Add instancemethod to types.py

2019-02-07 Thread Dan Snider


New submission from Dan Snider :

Having the ability to add binding behavior to any callable is an incredibly 
useful feature if one knows how to take advantage of it, but unfortunately, 
nothing that currently (publicly) exists comes close to filling the gap 
`instancemethod`s secrecy leaves.

There really isn't anything else to say about it because it's simply amazing at 
what it does, and publicly exposing it has zero drawback that I could possibly 
imagine.
Here's a benchmark I just ran 3.6 (can't check 3.7 but shouldn't be 
significantly different):

if 1:
from functools import _lru_cache_wrapper, partial
method = type((lambda:0).__get__(0))
for cls in object.__subclasses__():
if cls.__name__ == 'instancemethod':
instancemethod = cls
break
del cls

class Object:
lrx = _lru_cache_wrapper(id, 0, 0, tuple)
imx = instancemethod(id)
smx = property(partial(method, id))
fnx = lambda self, f=id: f(self)

>>> ob = Object()
>>> stex.Compare.load_meth_call('ob', '', None, 'lrx', 'imx', 'smx', 'fnx')


[*] Trial duration: 0.5 seconds
[*] Num trials: 20
[*] Verbose: True
[*] Imports: ('ob',)

+---+---+---+---+
+-INDEX +-INSTRUCTION   + OPARG-+ STACK-+
+---+---+---+
|[   22]  FOR_ITER > (   12)   1|
|[   24]  STORE_FAST --> (2)   0|
|[   26]  LOAD_FAST ---> (0)   1|
|[   28]  LOAD_ATTR ---> (2)   1|
|[   30]  CALL_FUNCTION ---> (0)   1|
|[   32]  POP_TOP -0|
|[   34]  JUMP_ABSOLUTE ---> (   22)   0|
+---+---+---+---+---+---+---+
+-STATEMENT +   NANOSEC-+ NUM LOOPS-+ EACH LOOP-+
+---+---+---+---+
| "ob.lrx()"  ->   10.000(b)   55_902(k) 179(ns)
| "ob.imx()"  ->   10.000(b)   80_053(k) 125(ns)
| "ob.smx()"  ->   10.000(b)   48_040(k) 208(ns)
| "ob.fnx()"  ->   10.000(b)   42_759(k) 234(ns)

--
components: Library (Lib)
messages: 335058
nosy: bup
priority: normal
severity: normal
status: open
title: Add instancemethod to types.py
type: enhancement
versions: Python 3.8

___
Python tracker 

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



[issue35904] Add statistics.fmean(seq)

2019-02-07 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

> On my current 3.8 build, this code given an approx 500x speed-up

On my system, I only get a 30x speed-up using your timeit code. Using 
ints instead of random floats, I only get a 9x speed-up.

This just goes to show how sensitive these timing results are on 
platform and hardware.

What do you think of this implementation?

def floatmean(data:Iterable) -> Float:
try:
n = len(data)
except TypeError:
# Handle iterators with no len.
n = 0
def count(x):
nonlocal n
n += 1
return x
total = math.fsum(map(count, data))
return total/n
else:
return math.fsum(data)/n

Compared to the "no frills" fsum()/len() version:

- I see no visible slowdown on lists of floats;
- it handles iterators as well.

On my computer, the difference between the sequence path and the 
iterator path is just a factor of 3.5. How does it compare on other 
machines?

As for the name, I think we have three reasonable candidates:

float_mean
fast_mean
fmean

(with or without underscores for the first two). Do people have a 
preference?

--
title: Add statistics.fastmean(seq) -> Add statistics.fmean(seq)

___
Python tracker 

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



[issue35935] threading.Event().wait() not interruptable with Ctrl-C on Windows

2019-02-07 Thread Eryk Sun


Eryk Sun  added the comment:

Python's C signal handler sets a flag and returns, and the signal is eventually 
handled in the main thread. In Windows, this means the Python SIGINT handler 
won't be called so long as the main thread is blocked. (In Unix the signal is 
delivered on the main thread and interrupts most blocking calls.) 

In Python 3, our C signal handler also signals a SIGINT kernel event object. 
This gets used in functions such as time.sleep(). However, threading wait and 
join methods do not support this event. In principle they could, so long as the 
underlying implementation continues to use kernel semaphore objects, but that 
may change. There's been pressure to adopt native condition variables instead 
of using semaphores.

When you enable the default handler, that's actually the default console 
control-event handler. It simply exits via ExitProcess(STATUS_CONTROL_C_EXIT). 
This works because the console control event is delivered by creating a new 
thread that starts at a private CtrlRoutine function in kernelbase.dll, so it 
doesn't matter that the main thread may be blocked. By default SIGBREAK also 
executes the default handler, so Ctrl+Break almost always works to kill a 
console process. Shells such as cmd.exe usually ignore it, because it would be 
annoying if Ctrl+Break also killed the shell and destroyed the console window. 

Note also that Python's signal architecture cannot support CTRL_CLOSE_EVENT, 
even though it's also mapped to SIGBREAK. The problem is that our C handler 
simply sets a flag and returns. For the close event, the session server waits 
on the control thread for up to 5 seconds and then terminates the process. Thus 
the C signal handler returning immediately means our process will be killed 
long before our Python handler gets called.

We may need to actually handle the event, such as ensuring that atexit 
functions are called. Currently the only way to handle closing the console 
window and cases where the main thread is blocked is to install our own console 
control handler using ctypes or PyWin32. Usually we do this to ensure a clean, 
controlled shutdown. Here's what this looks like with ctypes:

import ctypes
from ctypes import wintypes

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

CTRL_C_EVENT = 0
CTRL_BREAK_EVENT = 1
CTRL_CLOSE_EVENT = 2

HANDLER_ROUTINE = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
kernel32.SetConsoleCtrlHandler.argtypes = (
HANDLER_ROUTINE,
wintypes.BOOL)

@HANDLER_ROUTINE
def handler(ctrl):
if ctrl == CTRL_C_EVENT:
handled = do_ctrl_c()
elif ctrl == CTRL_BREAK_EVENT:
handled = do_ctrl_break()
elif ctrl == CTRL_CLOSE_EVENT:
handled = do_ctrl_close()
else:
handled = False
# If not handled, call the next handler.
return handled 

if not kernel32.SetConsoleCtrlHandler(handler, True):
raise ctypes.WinError(ctypes.get_last_error())

The do_ctrl_* functions could simply be sys.exit(1), which will ensure that 
atexit handlers get called.

--
nosy: +eryksun

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

3.6 is also on security-fix-only status

--
versions:  -Python 3.6

___
Python tracker 

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



[issue20020] "modernize" the modulefinder module

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
keywords: +patch, patch
pull_requests: +11788, 11789
stage: needs patch -> patch review

___
Python tracker 

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



[issue17396] modulefinder fails if module contains syntax error

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11781, 11782, 11783, 11784

___
Python tracker 

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



[issue17396] modulefinder fails if module contains syntax error

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11781, 11782, 11783

___
Python tracker 

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



[issue25160] Stop using deprecated imp module; imp should now emit a real DeprecationWarning

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11786
stage: needs patch -> patch review

___
Python tracker 

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



[issue17396] modulefinder fails if module contains syntax error

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11781, 11782

___
Python tracker 

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



[issue20020] "modernize" the modulefinder module

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


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

___
Python tracker 

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



[issue25160] Stop using deprecated imp module; imp should now emit a real DeprecationWarning

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11786, 11787
stage: needs patch -> patch review

___
Python tracker 

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



[issue35376] modulefinder skips nested modules with same name as top-level bad module

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11785

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
keywords: +patch
pull_requests: +11779
stage:  -> patch review

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
keywords: +patch, patch
pull_requests: +11779, 11780
stage:  -> patch review

___
Python tracker 

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



[issue17396] modulefinder fails if module contains syntax error

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
pull_requests: +11781

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-02-07 Thread Brandt Bucher


New submission from Brandt Bucher :

I've written a patch here that includes a few useful fixes. Namely:

- It doesn't crash if it encounters a syntax error. (17396)
- It doesn't report certain name collisions as bad. (35376)
- It doesn't use mutable default arguments in its initializer.
- Most importantly, it now uses `importlib` instead of `imp`, which is 
deprecated. (25160) As a benefit, frozen built-in modules (`zip import`, for 
example), are now correctly reported.

With the exception of these bug fixes, I've been very careful to preserve the 
original behavior, and have not changed any part of the API. This patch also 
includes 2 new regression tests.

--
versions: +Python 3.8 -Python 3.4

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Dong-hee Na


Change by Dong-hee Na :


--
keywords: +patch, patch, patch
pull_requests: +11776, 11777, 11778
stage: needs patch -> patch review

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Dong-hee Na


Change by Dong-hee Na :


--
keywords: +patch, patch
pull_requests: +11776, 11777
stage: needs patch -> patch review

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Dong-hee Na


Change by Dong-hee Na :


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

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-02-07 Thread Brandt Bucher


Change by Brandt Bucher :


--
components: Library (Lib)
nosy: brandtbucher
priority: normal
severity: normal
status: open
title: Give modulefinder some much-needed updates.
type: enhancement
versions: Python 3.4

___
Python tracker 

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



[issue35932] Interpreter gets stuck while applying a regex pattern

2019-02-07 Thread Tim Peters


Tim Peters  added the comment:

Without re.IGNORECASE, the leading

^[_a-z0-9-]+

can't even match the first character (`val` starts with uppercase Z), so it 
fails instantly.

With re.IGNORECASE, it's not "stuck", but is taking a verry long time to 
try an enormous number of (ultimately doomed) possibilities due to the way the 
regexp is written.

This is due to using nested quantifiers for no apparent reason.  For any 
character class C,

(C+)*

matches the same set of strings as

C*

but the former way can _try_ to match in an exponential (in the length of the 
string) number of ways.  So replace

([\.'_a-z0-9-]+)*
and
([\.a-z0-9-]+)*

with

[\.'_a-z0-9-]*
and
[\.a-z0-9-]*

and it fails to match `val` quickly (even with re.IGNORECASE).

For more on this (which applies to many regexp implementations, not just 
Python's), here's a start:

https://www.mathworks.com/matlabcentral/answers/95953-why-can-nested-quantifiers-in-regexp-can-cause-inefficient-failures-in-matlab-6-5-r13

The "Mastering Regular Expressions" book referenced in that answer is an 
excellent book-length treatment of this (and related) topic(s).

--
nosy: +tim.peters
resolution:  -> not a bug
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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Hi @corona10, Antoine's message is from 2013 and inspect.getabsfile() is still 
not documented, I think it's safe to say he's not working on it.

You can work on the issue and open a new PR on GitHub when you think it is 
ready for review :)

--
nosy: +remi.lapeyre
versions: +Python 3.6, Python 3.7, Python 3.8 -Python 3.3, Python 3.4

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-07 Thread Dong-hee Na


Dong-hee Na  added the comment:

@pitrou
Hi, Can I work on this issue?

--
nosy: +corona10

___
Python tracker 

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



[issue35899] '_is_sunder' function in 'enum' module fails on empty string

2019-02-07 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +corona10

___
Python tracker 

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



[issue35935] threading.Event().wait() not interruptable with Ctrl-C on Windows

2019-02-07 Thread Chris Billington


Chris Billington  added the comment:

If I add:

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

before the wait() call, then the call is interruptible on both Python versions 
without needing to add a timeout.

--

___
Python tracker 

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



[issue35935] threading.Event().wait() not interruptable with Ctrl-C on Windows

2019-02-07 Thread Chris Billington


New submission from Chris Billington :

I'm experiencing that the following short program:

import threading
event = threading.Event()
event.wait()

Cannot be interrupted with Ctrl-C on Python 2.7.15 or 3.7.1 on Windows 10 
(using the Anaconda Python distribution).

However, if the wait is given a timeout:

import threading
event = threading.Event()
while True:
if event.wait(1):
break

then this is interruptable on Python 2.7.15, but is still uninterruptible on 
Python 3.7.1.

--
components: Windows
messages: 335049
nosy: Chris Billington, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: threading.Event().wait() not interruptable with Ctrl-C on Windows
type: behavior
versions: Python 2.7, Python 3.7

___
Python tracker 

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



[issue4356] Add "key" argument to "bisect" module functions

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +remi.lapeyre
versions: +Python 3.8 -Python 3.7

___
Python tracker 

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



[issue35931] pdb: "debug print(" crashes with SyntaxError

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +remi.lapeyre

___
Python tracker 

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



[issue35904] Add statistics.fastmean(seq)

2019-02-07 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
title: Add statistics.fmean(seq) -> Add statistics.fastmean(seq)

___
Python tracker 

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



[issue35904] Add statistics.fmean(seq)

2019-02-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

>>def fmean(seq: Sequence[float]) -> float:
>>return math.fsum(seq) / len(seq)
>
> Is it intentional that this doesn't support iterators?

Since we need both the sum and the length, this seemed like a good starting 
point.  Also, the existing mean() function already covers the more general 
cases.

I suspect that it is common to keep the data in memory so that more than one 
descriptive statistic can be generated:

data = load_measurements()
data.sort()
n = len(data)
mu = fastmean(data)
sigma = stdev(data, xbar=mu)
low, q1, q2, q3, high = data[0], data[n//4], data[n//2], data[3*n//4], 
data[-1]
popular = mode(data, first_tie=True)


It's possible (though possibly not desirable) to provide an fallback path:

def fastmean(data: Iterable) -> float:
try:
return fsum(data) / len(data)
except TypeError:
# Slow alternative   
return float(mean(data))
# Memory intensive alternative
data = list(data)
return fsum(data) / len(data)  
# Less accurate alternative
total = n = 0
for n, x in enumerate(data, start=1):
total += x
return total / n

--

___
Python tracker 

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



[issue35925] test_httplib test_nntplib test_ssl fail on ARMv7 Debian buster buildbot

2019-02-07 Thread Gregory P. Smith


Change by Gregory P. Smith :


--
title: test_httplib test_nntplib test_ssl fail on ARMv7 buster/sid buildbots -> 
test_httplib test_nntplib test_ssl fail on ARMv7 Debian buster buildbot

___
Python tracker 

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



[issue35925] test_httplib test_nntplib test_ssl fail on ARMv7 buster/sid buildbots

2019-02-07 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

I had emailed Christian around the same time you filed this.

"""
The problem likely not related to your hardware. I guess it's caused by
tightened crypto polices. OpenSSL 1.1.1 has disabled some weak crypto.
Some platforms like Debian and RHEL require even larger key sizes or
have disable some algorithms. Does the test also fail with the env var
OPENSSL_CONF set to a non-existing path?
""" - christian.heimes

testing that theory... setting OPENSSL_CONF=/invalid-path does indeed "fix" 
(work around) the failures.  Presumably by relaxing the default system 
constraints.

I could have that env var set for this buildbot and eliminate the failure.  But 
do we _want_ to do that?  Anyone who compiles CPython and tries to run the test 
suite on a modern system with such an OpenSSL configuration is going to see 
similar failures and likely come to us first asking about them.

It seems like we'd be better off adjusting our test suite to work around the 
constraints or disable them only for the duration of a test intentionally 
violating them?

--
title: test_httplib test_nntplib test_ssl fail on ARMv7 Ubuntu 3.7 and ARMv7 
Ubuntu 3.x buildbots -> test_httplib test_nntplib test_ssl fail on ARMv7 
buster/sid buildbots

___
Python tracker 

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



[issue35932] Interpreter gets stuck while applying a regex pattern

2019-02-07 Thread Sateesh Kumar


Sateesh Kumar  added the comment:

@SilentGhost, You are right, when I pass the flag "re.IGNORECASE" for example 
in Variant-2 the python process do gets stuck.  

Here is the revised code for Variant-2:

* Variant-2
%cat match.py
import re
pattern = 
"^[_a-z0-9-]+([\.'_a-z0-9-]+)*@[a-z0-9]+([\.a-z0-9-]+)*(\.[a-z]{2,4})$"
val = "Z230-B900_X-Suite_Migration_Shared_Volume"
re.match(pattern, val, re.IGNORECASE)

~/workbench$ python match.py 
^^^ The interpreter gets stuck.

Thanks for the correction. I have also modified the title of this issue 
accordingly.

--
title: Interpreter gets stuck while applying a compiled regex pattern -> 
Interpreter gets stuck while applying a regex pattern

___
Python tracker 

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



[issue35904] Add statistics.fmean(seq)

2019-02-07 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

>def fmean(seq: Sequence[float]) -> float:
>return math.fsum(seq) / len(seq)

Is it intentional that this doesn't support iterators?

--

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Interestingly, you can also put an instance dict in slots:

>>> class A:
__slots__ = ['x', '__dict__']

>>> a = A()
>>> a.x = 5
>>> a.y = 6
>>> a.__dict__
{'y': 6}
>>> a.x
5

--
nosy: +rhettinger

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

You can have both a dict and slots by subclassing:

>>> class A: 
...: __slots__ = ('x',) 
...:

   
>>> class B(A): pass
>>> 
>>>
>>> 
>>> 
>>>
>>> b = B() 
>>> 
>>>
>>> b.x = 5 
>>> 
>>>
>>> b.y = 6 
>>> 
>>>
>>> b.__dict__  
>>> 
>>>
{'y': 6}
>>> A.x 
>>> 
>>>

>>> A.x.__get__(b)  
>>> 
>>>
5

--

___
Python tracker 

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



[issue14094] ntpath.realpath() should use GetFinalPathNameByHandle()

2019-02-07 Thread Steve Dower


Steve Dower  added the comment:

Posted a review. I suggest a few changes for the sake of tidying up, but I 
agree that I'd like to see more tests added.

--

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


Change by Pierre Glaser :


Added file: https://bugs.python.org/file48113/test_slots.py

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


Change by Pierre Glaser :


Removed file: https://bugs.python.org/file48112/test_slots.py

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


Change by Pierre Glaser :


Removed file: https://bugs.python.org/file48111/test_slots.py

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


Change by Pierre Glaser :


Added file: https://bugs.python.org/file48112/test_slots.py

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


Pierre Glaser  added the comment:

It turns out that both pickle and _pickle implement this feature, but the 
behavior is inconsistent.

- As a reminder, instances of slotted classes do not have a dict attribute (1)
- On the other side, when pickling slotted class instances, __getstate__ can 
return a tuple of 2 dicts. The first dict represents the __dict__ attribute. 
Because of (1), this first dict should simply be a sentinel value. In pickle, 
the condition is that it evaluates to False, but in _pickle, it should be 
explicitly None.

(- Finally, The second dict in state contains the slotted attribute. )

Here are the lines in the two files causing the inconsistent behavior:
https://github.com/python/cpython/blob/master/Modules/_pickle.c#L6236
https://github.com/python/cpython/blob/master/Lib/pickle.py#L1549

I included an example that illustrates it.

--
Added file: https://bugs.python.org/file48111/test_slots.py

___
Python tracker 

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



[issue14094] ntpath.realpath() should use GetFinalPathNameByHandle()

2019-02-07 Thread Eryk Sun


Eryk Sun  added the comment:

Ping on PR 11248. It would be nice to get this into 3.8.

--

___
Python tracker 

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



[issue14094] ntpath.realpath() should use GetFinalPathNameByHandle()

2019-02-07 Thread Eryk Sun


Change by Eryk Sun :


--
components: +Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware

___
Python tracker 

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



[issue14094] ntpath.realpath() should use GetFinalPathNameByHandle()

2019-02-07 Thread Eryk Sun


Change by Eryk Sun :


--
components:  -Windows

___
Python tracker 

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



[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:


New changeset 48769a28ad6ef4183508951fa6a378531ace26a4 by Antoine Pitrou (Miss 
Islington (bot)) in branch '3.7':
bpo-35615: Fix crashes when copying a Weak{Key,Value}Dictionary. (GH-11384) 
(GH-11785)
https://github.com/python/cpython/commit/48769a28ad6ef4183508951fa6a378531ace26a4


--

___
Python tracker 

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



[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

2019-02-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +11773, 11774, 11775

___
Python tracker 

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



[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:


New changeset 96d37dbcd23e65a7a57819aeced9034296ef747e by Antoine Pitrou (Fish) 
in branch 'master':
bpo-35615: Fix crashes when copying a Weak{Key,Value}Dictionary. (GH-11384)
https://github.com/python/cpython/commit/96d37dbcd23e65a7a57819aeced9034296ef747e


--

___
Python tracker 

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



[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

2019-02-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +11773, 11774

___
Python tracker 

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



[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

2019-02-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +11773

___
Python tracker 

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



[issue35911] add a cell construtor, and expose the cell type in Lib/types.py

2019-02-07 Thread Antoine Pitrou


Change by Antoine Pitrou :


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



[issue35911] add a cell construtor, and expose the cell type in Lib/types.py

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:


New changeset df8d2cde63c865446468351f8f648e1c7bd45109 by Antoine Pitrou 
(Pierre Glaser) in branch 'master':
bpo-35911: add cell constructor (GH-11771)
https://github.com/python/cpython/commit/df8d2cde63c865446468351f8f648e1c7bd45109


--

___
Python tracker 

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



[issue35932] Interpreter gets stuck while applying a compiled regex pattern

2019-02-07 Thread SilentGhost


SilentGhost  added the comment:

In your variant 2 you're not using re.IGNORECASE flag, if you do you're likely 
to encounter the same behaviour as for the compiled pattern. At least I do on 
python3.6

--
components: +Regular Expressions
nosy: +SilentGhost, ezio.melotti, mrabarnett
type: crash -> behavior

___
Python tracker 

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



[issue17561] Add socket.create_server_sock() convenience function

2019-02-07 Thread Giampaolo Rodola'


Giampaolo Rodola'  added the comment:

After careful thinking I realize I'm not completely sure about how to expose 
the IPv4/6 functionality yet. I prefer to defer it for later and start landing 
a bind_socket() utility function which serves as a base for this functionality. 
See: issue17561.

--

___
Python tracker 

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



[issue35934] Add socket.bind_socket() utility function

2019-02-07 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


--
keywords: +patch
pull_requests: +11769

___
Python tracker 

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



[issue35934] Add socket.bind_socket() utility function

2019-02-07 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


--
keywords: +patch, patch, patch
pull_requests: +11769, 11770, 11771

___
Python tracker 

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



[issue35934] Add socket.bind_socket() utility function

2019-02-07 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


--
keywords: +patch, patch
pull_requests: +11769, 11770

___
Python tracker 

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



[issue35934] Add socket.bind_socket() utility function

2019-02-07 Thread Giampaolo Rodola'


New submission from Giampaolo Rodola' :

The main point of this patch is to automatize all the necessary tasks which are 
usually involved when creating a server socket, amongst which:

* determining the right family based on address, similarly to 
socket.create_connection()
* whether to use SO_REUSEADDR depending on the platform
* set AI_PASSIVE flag for getaddrinfo()
* set a more optimal default backlog

This is somewhat related to issue17561 which I prefer to leave pending for now 
(need to think about it more carefully). issue17561 is complementary to this 
one so it appears it can be integrated later (or never) without altering the 
base functionality implemented in here.

--
components: Library (Lib)
messages: 335034
nosy: asvetlov, cheryl.sabella, giampaolo.rodola, jaraco, josiah.carlson, 
loewis, neologix, pitrou
priority: normal
severity: normal
stage: patch review
status: open
title: Add socket.bind_socket() utility function
versions: Python 3.8

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

Does it still work?  With both the C and Python pickler?
Can you post an example?

--

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

(also, OSError will automatically convert to more specific subclasses for some 
errnos, see PEP 3151:

>>> raise OSError(errno.ENOENT, "foobar")   
>>> 
>>>
Traceback (most recent call last):
  File "", line 1, in 
raise OSError(errno.ENOENT, "foobar")
FileNotFoundError: [Errno 2] foobar

)

--

___
Python tracker 

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



[issue35932] Interpreter gets stuck while applying a compiled regex pattern

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +remi.lapeyre

___
Python tracker 

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



[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser


New submission from Pierre Glaser :

Hello all,
This 16-year old commit (*) allows an object's state to be updated
using its slots instead of its __dict__ at unpickling time. To use this
functionality, the state keyword-argument of Pickler.save_reduce (which maps to
the third item of the tuple returned by __reduce__) should be a length-2 tuple.
As far as I can tell, this is not mentioned in the documentation (**). I 
suggest having the docs updated. What do you think?

(*) 
https://github.com/python/cpython/commit/ac5b5d2e8b849c499d323b0263ace22e56b4f0d9
(**) https://docs.python.org/3.8/library/pickle.html#object.__reduce__

--
assignee: docs@python
components: Documentation
messages: 335031
nosy: alexandre.vassalotti, docs@python, pierreglaser, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: python doc does not say that the state kwarg in Pickler.save_reduce can 
be a tuple (and not only a dict)
versions: Python 3.8

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-07 Thread Neil Schemenauer


Neil Schemenauer  added the comment:

I didn't finish reviewing completely yet but here are some comments.

I think the random filename generation can be pulled out of
_posixshmem.  Make it require that a filename is passed into it.
That moves a fair bit of complexity out of C and into Python.  In
the Python module, I suggest that you could use secrets.token_hex()
to build the filename.  Put the loop that retries because of name
collisions in the Python module as well.

If you like, I can try to make a patch that does the above.

When looking at at how the Python code would handle a name collision,
I see this code:


+switch (errno) {
+case EACCES:
+PyErr_Format(pPermissionsException,
+"No permission to %s this segment",
+(flags & O_TRUNC) ? "truncate" : "access"
+);
+break;
+
+case EEXIST:
+PyErr_SetString(pExistentialException,
+"Shared memory with the specified name already 
exists");
+break;
+
+case ENOENT:
+PyErr_SetString(pExistentialException,
+"No shared memory exists with the specified 
name");
+break;
+
+case EINVAL:
+PyErr_SetString(PyExc_ValueError, "Invalid parameter(s)");
+break;
+
+case EMFILE:
+PyErr_SetString(PyExc_OSError,
+ "This process already has the maximum number 
of files open");
+break;
+
+case ENFILE:
+PyErr_SetString(PyExc_OSError,
+ "The system limit on the total number of open 
files has been reached");
+break;
+
+case ENAMETOOLONG:
+PyErr_SetString(PyExc_ValueError,
+ "The name is too long");
+break;
+
+default:
+PyErr_SetFromErrno(PyExc_OSError);
+break;
+}


I think it might be cleaner just to make it:

PyErr_SetFromErrno(PyExc_OSError);

Then, if you need a customized exception or message, you can
re-raise inside the Python code.  To me, it seems simpler and more
direct to just preserve the errno and always raise OSError.  Changing things
to ValueError means that callers need to look at the message text to 
differentiate between some errno values.

Is it the case that _posixshmem started life as a module that would
be used directly and not something hidden by another layer of
abstraction?  If so, having these customized exceptions and having
it do the filename generation itself makes sense.  However, it is an
internal implementation detail of shared_memory.py, I think it
should be simplified to do only what is needed.  E.g. a thin layer
of the system calls.

--
nosy: +nascheme

___
Python tracker 

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



[issue35932] Interpreter gets stuck while applying a compiled regex pattern

2019-02-07 Thread Sateesh Kumar


New submission from Sateesh Kumar :

The python interpreter gets stuck while applying a compiled regex pattern 
against a given string.

The regex matching doesn't get stuck if uncompiled regex pattern is used, or if 
the flag "re.IGNORECASE" is not used for regex match. 

Below code snippets gives more details.

* Variant-1
# Python process gets stuck

~/workbench$ cat match.py 
import re
pattern = 
"^[_a-z0-9-]+([\.'_a-z0-9-]+)*@[a-z0-9]+([\.a-z0-9-]+)*(\.[a-z]{2,4})$"
compiled_pattern = re.compile(pattern, re.IGNORECASE)
val = "Z230-B900_X-Suite_Migration_Shared_Volume"
re.match(compiled_pattern, val)

~/workbench$ python match.py 
^^^ The interpreter gets stuck.

* Variant-2 (Using uncompiled pattern) 
# python interpreter doesn't get stuck

~/workbench$ cat match.py
import re
pattern = 
"^[_a-z0-9-]+([\.'_a-z0-9-]+)*@[a-z0-9]+([\.a-z0-9-]+)*(\.[a-z]{2,4})$"
compiled_pattern = re.compile(pattern, re.IGNORECASE)
val = "Z230-B900_X-Suite_Migration_Shared_Volume"
re.match(pattern, val)

* Variant-3 (Using compiled pattern, but without flag re.IGNORECASE)
# Python interpreter doesn't get stuck

~/workbench$ cat match.py
import re
pattern = 
"^[_a-z0-9-]+([\.'_a-z0-9-]+)*@[a-z0-9]+([\.a-z0-9-]+)*(\.[a-z]{2,4})$"
compiled_pattern = re.compile(pattern)
val = "Z230-B900_X-Suite_Migration_Shared_Volume"
re.match(compiled_pattern, val)

# Platform details
~/workbench$ python -V
Python 2.7.12

~/workbench$ uname -a
Linux ubuntu16-template 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 
2017 x86_64 x86_64 x86_64 GNU/Linux

Though above details are from Python/2.7 I see similar beahviour with 
Python/3.5.2 too.

--
files: gdb_trace
messages: 335029
nosy: Sateesh Kumar
priority: normal
severity: normal
status: open
title: Interpreter gets stuck while applying a compiled regex pattern
type: crash
versions: Python 2.7
Added file: https://bugs.python.org/file48110/gdb_trace

___
Python tracker 

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



[issue35899] '_is_sunder' function in 'enum' module fails on empty string

2019-02-07 Thread Ethan Furman


Ethan Furman  added the comment:

Yes, the first solution will be fine.  Maxwell, can you create a github pull 
request with that?

--
keywords: +easy
stage:  -> needs patch
type: crash -> behavior

___
Python tracker 

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



[issue34572] C unpickling bypasses import thread safety

2019-02-07 Thread Eric Snow


Eric Snow  added the comment:

Perhaps PyImport_GetModule() should aquire-release the module's lock before the 
lookup?  This would effectively be a call to _lock_unlock_module() in 
importlib._bootstrap.

The alternative is to encourage using PyImport_Import() instead, like the PR 
has done.  In the case the docs for PyImport_GetModule() should make it clear 
that it is guaranteed that the module is fully imported yet (and recommend 
using PyImport_Import() for the guarantee).

Either way there should be a new issue for the more general change (and it 
should reference this issue).

--
type: crash -> behavior

___
Python tracker 

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



[issue28411] Eliminate PyInterpreterState.modules.

2019-02-07 Thread Eric Snow


Change by Eric Snow :


--
assignee:  -> eric.snow
type:  -> behavior

___
Python tracker 

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



[issue28411] Eliminate PyInterpreterState.modules.

2019-02-07 Thread Eric Snow


Eric Snow  added the comment:

FTR, gh-9047 (for issue #34572) mentions this issue.

--

___
Python tracker 

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



[issue28411] Eliminate PyInterpreterState.modules.

2019-02-07 Thread Eric Snow


Change by Eric Snow :


--
pull_requests:  -11714

___
Python tracker 

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



[issue28411] Eliminate PyInterpreterState.modules.

2019-02-07 Thread Eric Snow


Change by Eric Snow :


--
pull_requests:  -11713

___
Python tracker 

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



[issue35931] pdb: "debug print(" crashes with SyntaxError

2019-02-07 Thread daniel hahler


New submission from daniel hahler :

`debug print(` will make pdb crash with a SyntaxError:

% python -c '__import__("pdb").set_trace()'  
--Return--
> (1)()->None
(Pdb) print(
*** SyntaxError: unexpected EOF while parsing
(Pdb) debug print(
ENTERING RECURSIVE DEBUGGER
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib64/python3.7/bdb.py", line 92, in trace_dispatch
return self.dispatch_return(frame, arg)
  File "/usr/lib64/python3.7/bdb.py", line 151, in dispatch_return
self.user_return(frame, arg)
  File "/usr/lib64/python3.7/pdb.py", line 293, in user_return
self.interaction(frame, None)
  File "/usr/lib64/python3.7/pdb.py", line 352, in interaction
self._cmdloop()
  File "/usr/lib64/python3.7/pdb.py", line 321, in _cmdloop
self.cmdloop()
  File "/usr/lib64/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
  File "/usr/lib64/python3.7/pdb.py", line 418, in onecmd
return cmd.Cmd.onecmd(self, line)
  File "/usr/lib64/python3.7/cmd.py", line 217, in onecmd
return func(arg)
  File "/usr/lib64/python3.7/pdb.py", line 1099, in do_debug
sys.call_tracing(p.run, (arg, globals, locals))
  File "/usr/lib64/python3.7/bdb.py", line 582, in run
cmd = compile(cmd, "", "exec")
  File "", line 1
print(
 ^
SyntaxError: unexpected EOF while parsing

--
components: Library (Lib)
messages: 335025
nosy: blueyed
priority: normal
severity: normal
status: open
title: pdb: "debug print(" crashes with SyntaxError
versions: Python 3.8

___
Python tracker 

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



[issue35931] pdb: "debug print(" crashes with SyntaxError

2019-02-07 Thread daniel hahler


Change by daniel hahler :


--
keywords: +patch, patch
pull_requests: +11767, 11768
stage:  -> patch review

___
Python tracker 

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



[issue35931] pdb: "debug print(" crashes with SyntaxError

2019-02-07 Thread daniel hahler


Change by daniel hahler :


--
keywords: +patch
pull_requests: +11767
stage:  -> patch review

___
Python tracker 

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



[issue35929] Spam

2019-02-07 Thread Zachary Ware


Change by Zachary Ware :


--
components:  -2to3 (2.x to 3.x conversion tool), Build, Demos and Tools, 
Distutils, Documentation, Extension Modules, FreeBSD, Library (Lib), SSL, 
email, macOS
nosy:  -Mariatta, barry, docs@python, dstufft, eric.araujo, koobs, ned.deily, 
r.david.murray, ronaldoussoren, roufique7
title: rtat.net -> Spam
versions:  -Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

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



[issue34572] C unpickling bypasses import thread safety

2019-02-07 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
nosy: +brett.cannon, eric.snow, ncoghlan

___
Python tracker 

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



[issue35929] rtat.net

2019-02-07 Thread Mariatta Wijaya


New submission from Mariatta Wijaya :

Please provide more info about the bug you're reporting.

As it is, this looks like spam, so I'm closing it.

--
assignee: docs@python -> 
nosy: +Mariatta
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type: resource usage -> 

___
Python tracker 

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



[issue34572] C unpickling bypasses import thread safety

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

Interesting I could not reproduce here, even by throwing Pandas into the mix 
and spawning 1024 workers...

--
nosy: +pitrou

___
Python tracker 

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



[issue4356] Add "key" argument to "bisect" module functions

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
pull_requests: +11764, 11765, 11766

___
Python tracker 

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



[issue4356] Add "key" argument to "bisect" module functions

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
pull_requests: +11764

___
Python tracker 

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



[issue4356] Add "key" argument to "bisect" module functions

2019-02-07 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
pull_requests: +11764, 11765

___
Python tracker 

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



[issue35930] Raising an exception raised in a "future" instance will create reference cycles

2019-02-07 Thread Jesús Cea Avión

New submission from Jesús Cea Avión :

Try this in a terminal:

"""
import gc
import concurrent.futures
executor = concurrent.futures.ThreadPoolExecutor(999)

def a():
  1/0

future=executor.submit(a)
future.result()
# An exception is raised here. That is normal
gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect()
gc.garbage
"""

You will see (python 3.7) that 23 objects are collected when cleaning the cycle.

The problem is the attribute "future._exception". If the exception provided by 
the "future" is raised somewhere else, we will have reference cycles because we 
have the same exception/traceback in two different places in the traceback 
framestack.

I commonly do this in my code:

"""
try:
  future.result()  # This will raise an exception if the future did it
except Exception:
   ... some clean up ...
  raise  # Propagate the "future" exception
"""

This approach will create reference cycles. They will eventually cleaned up, 
but I noticed this issue because the cycle clean up phase was touching big 
objects with many references but unused for a long time, so they were living in 
the SWAP. The cycle collection was hugely slow because of this and the 
interpreter is completely stopped until done.

Not sure about what to do about this. I am currently doing something like:

"""
try:
  future.result()  # This will raise an exception if the future did it
except Exception:
   if future.done():
   del future._exception
  raise  # Propagate the exception
"""

I am breaking the cycle manually. I do not use "future.set_exception(None) 
because side effects like notifying waiters.

I think this is a bug to be solved. Not sure how to do it cleanly.

What do you think? Ideas?.

--
messages: 335022
nosy: jcea
priority: normal
severity: normal
status: open
title: Raising an exception raised in a "future" instance will create reference 
cycles
versions: 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



[issue35929] rtat.net

2019-02-07 Thread Rohit travels and tours


Change by Rohit travels and tours :


--
assignee: docs@python
components: 2to3 (2.x to 3.x conversion tool), Build, Demos and Tools, 
Distutils, Documentation, Extension Modules, FreeBSD, Library (Lib), SSL, 
email, macOS
nosy: barry, docs@python, dstufft, eric.araujo, koobs, ned.deily, 
r.david.murray, ronaldoussoren, roufique7
priority: normal
severity: normal
status: open
title: rtat.net
type: resource usage
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

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



[issue17561] Add socket.create_server_sock() convenience function

2019-02-07 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

In issue24209, I ended up settling on this implementation 
(https://github.com/python/cpython/blob/f289084c83190cc72db4a70c58f007ec62e75247/Lib/http/server.py#L1227-L1234),
 which seems to work well.

--

___
Python tracker 

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



[issue24209] Allow IPv6 bind in http.server

2019-02-07 Thread Jason R. Coombs


Change by Jason R. Coombs :


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



[issue24209] Allow IPv6 bind in http.server

2019-02-07 Thread Jason R. Coombs


Jason R. Coombs  added the comment:


New changeset f289084c83190cc72db4a70c58f007ec62e75247 by Jason R. Coombs in 
branch 'master':
bpo-24209: In http.server script, rely on getaddrinfo to bind to preferred 
address based on the bind parameter. (#11767)
https://github.com/python/cpython/commit/f289084c83190cc72db4a70c58f007ec62e75247


--

___
Python tracker 

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



[issue30130] array.array is not an instance of collections.MutableSequence

2019-02-07 Thread Cheryl Sabella


Cheryl Sabella  added the comment:

As Jim mentioned, issue 29727 also discusses registering array.array.

See issue 23864, issue 25737, issue 35190, and issue 35349 for discussions 
about collections.abc in general.

Closing this as a duplicate.

--
nosy: +cheryl.sabella
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> collections.abc.Reversible doesn't fully support the reversing 
protocol

___
Python tracker 

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



[issue32972] unittest.TestCase coroutine support

2019-02-07 Thread Dave Shawley


Dave Shawley  added the comment:

PR 10296 is my implementation of a unittest.TestCase subclass solution to this 
issue.  This comment explains the approach and rationale in detail.  Let's 
discuss this and see if the implementation meets expectations or should be 
abandoned.

I refactored unittest.TestCase to isolate the running of test methods into a 
new helper method named _runTest and add a new hook named _terminateTest.  The 
_runTest method is used to customize test method execution in sub-classes.  The 
_terminateTest method is called from within the finally block in 
unittest.TestCase.run.  It is an empty method in unittest.TestCase.  This was 
the only change to unittest.TestCase.  A new class unittest.AsyncioTestCase was 
added that implements async-based testing.  It is a direct sub-class of 
unittest.TestCase that:

* uses a @property named loop to lazily create an event loop instance
* destroys the event loop instance in _terminateTest
* re-implements _runTest to call new asynchronous hook methods
* adds asyncSetUp and asyncTearDown methods that simply call the synchronous 
methods
* re-implements doCleanups to call co-routines asynchronously

Rationale
-
I used asyncio.iscoroutinefunction to detect if test methods or callbacks are 
co-routines.  You explicitly opt-in to async behavior using the async marker on 
things that you want to run on the loop.  This will cause problems with using 
the patch decorator on test methods since they will no not be detected as 
co-routines.  I took this approach primarily to simplify the code and enforce 
explicitness.  Since the implementation is a new sub-class, it cannot break 
existing code and new code can place the patch inside of the test method 
instead of decorating the method.

I believe that creating an destroying the loop with each test method execution 
is the safest approach for managing the lifecycle.  I view having the loop 
exist at the class level is an unnecessary optimization.  I also ensure that 
code under test that calls asyncio.get_event_loop or asyncio.get_running_loop 
will receive the loop by calling asyncio.set_event_loop with the new loop.  
This came up in PR review with Petter S.

The management of the loop is isolated into a property which makes it possible 
to create custom sub-classes that instantiate 3rd party loops that are asyncio 
compatible.  This is the only concession that my implementation makes to 
supporting other loop classes.

If it is not clear, I believe that a new sub-class of unittest.TestCase is 
necessary for a clean implementation.  It preserves unittest.TestCase so the 
risk of breaking existing code is minimized and the async functionality is 
isolated in a new class that is explicitly meant to test async code. This is 
also necessary if the implementation should exist in the asyncio module.

--

___
Python tracker 

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



[issue35928] socket makefile read-write discards received data

2019-02-07 Thread Palle Ravn


New submission from Palle Ravn :

Using socket.makefile in read-write mode had a bug introduced between version 
3.6.6 and 3.6.7. The same bug is present in version 3.7.x.

The below code example will behave very differently between 3.6.6 and 3.6.7. 
It's based on the echo-server example from the docs.

import socket

HOST = '127.0.0.1'
PORT = 0

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))

print(f'Waiting for connection on port {s.getsockname()[1]}')
s.listen(1)

conn, addr = s.accept()
print(f'Connected by {addr}')

with conn:
f = conn.makefile(mode='rw')

while True:
m = f.readline()
print(f'msg: {m!r}')

if not m:
exit(0)

f.write(m)
f.flush()


Python 3.6.7:
Sending the string "Hello\nYou\n" will only print "Hello\n" and also only 
return "Hello\n" to the client.
Removing the lines with f.write(m) and f.flush() and both "Hello\n" and "You\n" 
will be returned to the client.
It's like the call to f.write() somehow empties the read buffer.

Python 3.6.6:
Sending "Hello\nYou\n" will return "Hello\n" and "You\n" to the client without 
any modifications to the above code.

--
components: IO
messages: 335017
nosy: pravn
priority: normal
severity: normal
status: open
title: socket makefile read-write discards received data
type: behavior
versions: 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



[issue32972] unittest.TestCase coroutine support

2019-02-07 Thread Dave Shawley


Dave Shawley  added the comment:

Hi everyone, I'm trying to reboot conversation on this issue since I would love 
for this to land in Python 3.8.  At the recommendation of Terry Jan Reedy, here 
is my summary of where I think that the discussion is currently.  If anything 
is misrepresented, incorrectly linked, or if I misspelled anyones name, I 
apologize.  Feel free to correct any mistakes that you notice.

New subclass of TestCase versus enhancing unittest.TestCase
---

This was one of the primary discussion points since the start of this BPO.  I 
believe that Petter S (msg313454), Yury Selivanov (msg313695), and Andrew 
Svetlov (msg313481) were +1 on having a new sub-class of unittest.TestCase 
whereas Zachary Ware (msg313696) and R. David Murray (msg313413) would prefer 
that unittest.TestCase be enhanced to support async methods directly.

This is (in my opinion) the most contentious of the issues.  It also is the one 
with the largest impact on the implementation.  I feel that it is still largely 
up in the air amongst the core developers.

Lifecycle of the loop
-

Whether the loop should live for the entire execution of a TestCase or for the 
execution of an individual test method came up a few times.  Nathaniel Smith 
(msg313455) was concerned about callbacks leaking between tests.  Yury 
Selivanov and Zachary Ware agreed that having a single event loop per class was 
acceptable (msg313696 and msg313700).

Support for other loops
---

Supporting 3rd party loop implementations (e.g., Tornado, Twisted, curio/trio) 
was discussed briefly.  The conclusion that I drew from the discussion is that 
the built-in testing class was not required to offer direct support to 
non-asyncio compatible loops.  Most notably msg313481 from Andrew Svetlov 
influenced my implementation.

Where should support live?
--

This is only relevant if we are not enhancing unittest.TestCase.  Petter S 
favored that the separate test case implementation live in asyncio instead of 
unittest.  I don't believe that anyone else had a strong opinion on this issue.

Should we have explicit methods for async behavior?
---

Yury Selivanov was most outspoken on explicitly named "async" methods like 
"asyncSetup", "asyncAddCallback", and the like.  Particularly in msg313695 and 
msg313700.  Zachary Ware seemed to agree that the separation was necessary but 
the functionality could be implemented by calling the async methods from the 
existing setUp and setUpClass methods (msg313699).


Did I miss anything?

--

___
Python tracker 

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



[issue22213] Make pyvenv style virtual environments easier to configure when embedding Python

2019-02-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Yeah, I mainly cc'ed Victor and Eric since making this easier ties into one of 
the original design goals for PEP 432 (even though I haven't managed to 
persuade either of them to become co-authors of that PEP yet).

--

___
Python tracker 

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



[issue35904] Add statistics.fmean(seq)

2019-02-07 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

In the PEP, I did say that I was making no attempt to compete with numpy 
for speed, and that correctness was more important than speed.

That doesn't mean I don't care about speed. Nor do I necessarily care 
about absolute precision when given nothing but float arguments. Mark 
suggests that using fsum() will be accurate to within 1.5 ulp which 
satisfies me for float arguments.

I doubt that stdev etc would be able to promise that accuracy, so 
provided your data is all floats, that seems like a pretty good result 
for the mean.

But I'm not super-keen on having two separate mean() functions if that 
opens the floodgates to people wanting every statistics function to grow 
a fast-but-floats-only twin. That would make me sad. But maybe mean() is 
special enough to justify twinning it.

In my ideal world, I'd have a single mean() function that had a 
fast-path for float data, but would automatically drop down to a slower 
but more accurate path for other types, out-of-range data, etc. I 
believe that the the built-in sum() function does something like this.

When I say "more accurate", this isn't a complaint about fsum(). It 
refers to the limitation of floats themselves. Call me Mr Silly if you 
like, but if I need to take the average of numbers bigger than 2**1074 I 
would like to be able to, even if it takes a bit longer :-)

--

___
Python tracker 

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



[issue2506] Add mechanism to disable optimizations

2019-02-07 Thread Ned Batchelder


Ned Batchelder  added the comment:

FWIW, Yury started a pull request: https://github.com/python/cpython/pull/9693

--
keywords:  -patch

___
Python tracker 

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:


New changeset 15526f5be72f547288c16d53526fc74f15ee61ed by Antoine Pitrou in 
branch '3.7':
[3.7] bpo-35917: Test multiprocessing manager classes and shareable types 
(GH-11772) (GH-11780)
https://github.com/python/cpython/commit/15526f5be72f547288c16d53526fc74f15ee61ed


--

___
Python tracker 

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

Thanks Giampaolo!

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
pull_requests: +11761, 11762, 11763

___
Python tracker 

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
pull_requests: +11761

___
Python tracker 

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
pull_requests: +11761, 11762

___
Python tracker 

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



[issue35917] multiprocessing: provide unit-tests for manager classes and shareable types

2019-02-07 Thread Antoine Pitrou


Antoine Pitrou  added the comment:


New changeset 2848d9d29914948621bce26bf0d9a89f2e19b97b by Antoine Pitrou 
(Giampaolo Rodola) in branch 'master':
bpo-35917: Test multiprocessing manager classes and shareable types (GH-11772)
https://github.com/python/cpython/commit/2848d9d29914948621bce26bf0d9a89f2e19b97b


--

___
Python tracker 

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



[issue35913] asyncore: allow handling of half closed connections

2019-02-07 Thread Isaac Boukris


Isaac Boukris  added the comment:

if not data:
# a closed connection is indicated by signaling
# a read condition, and having recv() return 0.
self.handle_close()
return b''

This above is the current code. Do you agree that it makes a wrong assumption 
and therefore behave incorrectly? If so, how do you suggest fixing it without 
adding a new method?

Otherwise; maybe we can at least amend the comment in the code, and perhaps add 
a word or two to the doc.

--

___
Python tracker 

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



  1   2   >