[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Ok, I hope that it's the last attempt: patch 5

* Remove hash(b) != hash(a): only keep tests on hash(b)==hash(a) when b==a
* Replace re.ASCII flag with no flag to test two patterns with different flags

--
Added file: http://bugs.python.org/file45529/pattern_compare-4.patch

___
Python tracker 

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



[issue20572] subprocess.Popen.wait() undocumented "endtime" parameter

2016-11-18 Thread Martin Panter

Changes by Martin Panter :


Removed file: http://bugs.python.org/file42579/downloadfile.htm

___
Python tracker 

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



[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There is a problem with locale-depending flags. The same pattern may be 
compiled with the LOCALE flag to different pattern objects in different 
locales. Perhaps we should compare the compiled code instead of pattern 
strings. Or both.

--

___
Python tracker 

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



[issue20572] subprocess.Popen.wait() undocumented "endtime" parameter

2016-11-18 Thread Martin Panter

Martin Panter added the comment:

I think other people wanted to add an automated deprecation warning in the code 
first, before removing it.

--
nosy: +martin.panter

___
Python tracker 

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



[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Serhiy: "There is a problem with locale-depending flags. The same pattern may 
be compiled with the LOCALE flag to different pattern objects in different 
locales."

Oh, I didn't know and you are right.

"Perhaps we should compare the compiled code instead of pattern strings. Or 
both."

PatternObject contains many fields. I used the following two fields which come 
from re.compile():

* pattern
* flags

I considered that they were enough because pattern_repr() only displays these 
ones. Other fields:

* groups
* groupindex
* indexgroup
* weakreflist
* isbytes
* codesize, code

weakreflist can be skipped, isbytes is already tested in my patch.

Would it be possible to only compare code instead of pattern? What are groups, 
groupindex and indexgroup: should we also compare them?

Maybe I can start from  pattern_compare-4.patch and only add a test comparing 
code?

--

___
Python tracker 

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



[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

'[abc]' and '[cba]' are compiled to the same code. Do we want to handle them as 
equal? This is implementation defined.

--

___
Python tracker 

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



[issue28724] Add method send_io, recv_io to the socket module.

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

FYI, multiprocessing.reduction module has send_fds and recv_fds.

--
nosy: +inada.naoki

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Patch that follows closely the conditionals in the __bootlocale module.

--
stage: patch review -> commit review
Added file: http://bugs.python.org/file45530/skip_test_2.patch

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> The problem is caused by the fact that android does not have HAVE_LANGINFO_H 
> and CODESET set

Hum, is it possible to get the locale encoding by another way?

If not, what is the locale encoding?

Does Android provide mbstowcs() and wcstombs() functions?

--
nosy: +haypo

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

New submission from INADA Naoki:

_PyDict_NewPresized(6) creates dict which keysize is 8.
But it's capacity is 5 (8 * 2 // 3 = 5).

This internal API is used by BUILD_MAP and BUILD_CONST_KEYMAP.

--
assignee: inada.naoki
files: PyDict_NewPresized-too-small.patch
keywords: patch
messages: 281092
nosy: haypo, inada.naoki
priority: high
severity: normal
stage: patch review
status: open
title: _PyDict_NewPresized() creates too small dict
type: performance
versions: Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45531/PyDict_NewPresized-too-small.patch

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

This patch includes fix for ESTIMATE_SIZE macro. (see below)
Same fix is included in patch for issue28147.

>>> def estimate_size(n):
... return n * 3 // 2  # Current ESTIMATE_SIZE
...
>>> def usable(n):
... return n * 2 // 3
...
>>> def keysize(minsize):
... size = 8
... while size < minsize:  # Current implementation uses <=
... size *= 2
... return size
...
>>> def check():
... for i in range(1000):
... estimate = estimate_size(i)
... size = keysize(estimate)
... cap = usable(size)
... if cap < i:
... print(i, estimate, size, cap)
...
>>> check()
11 16 16 10
43 64 64 42
171 256 256 170
683 1024 1024 682
>>> # 
>>> estimate_size = lambda n: (n * 3 +1) // 2  # Fixed version
>>> check()
>>>

--

___
Python tracker 

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



[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> '[abc]' and '[cba]' are compiled to the same code. Do we want to handle them 
> as equal?

Comparison must be fast. If the comparison is just memcmp(code1,
code2, codesize), it's ok.

I agree that we must put a similar somewhere to say that some parts
are implementation details. Maybe split the test in two parts, and
mark the second part with @cpython_only.

--

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread srinivasaraoMaddukuri

New submission from srinivasaraoMaddukuri:

in window7  (using python 3.4.3,3.5.2) following script crashes

import os
os.spawnl( os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe' )"

Note: similar issue is already exist https://bugs.python.org/issue8036

--
components: Interpreter Core
messages: 281095
nosy: srinim
priority: normal
severity: normal
status: open
title: spawnl crash on windows7
type: crash
versions: Python 3.4, Python 3.5

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread srinivasaraoMaddukuri

srinivasaraoMaddukuri added the comment:

small correction (removed " )

import os
os.spawnl( os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe' )

--

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Just to make sure: a crash means that the Python process is killed and you get 
a popup or something like that?

Can you please try to run the script on Python 3.6 using:

python.exe -X faulthandler script.py

It should display the Windows error code at least.

--
nosy: +haypo

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

current:
$ ~/work/python36/bin/python3 -m perf timeit -- 'd = {"a":1, "b":2, "c":3, 
"d":4, "e":5, "f":6}'
.
Median +- std dev: 925 ns +- 49 ns

patched:
$ ~/work/python36/bin/python3 -m perf timeit -- 'd = {"a":1, "b":2, "c":3, 
"d":4, "e":5, "f":6}'
.
Median +- std dev: 726 ns +- 30 ns

--

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread STINNER Victor

Changes by STINNER Victor :


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



[issue28730] __reduce__ not being called in dervied extension class from datetime.datetime

2016-11-18 Thread Jeff Reback

Jeff Reback added the comment:

ok thanks for the info. fixed in pandas here: 
https://github.com/pandas-dev/pandas/pull/14689

is this documented in the whatsnew?

--

___
Python tracker 

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



[issue26273] Expose TCP_CONGESTION and TCP_USER_TIMEOUT to the socket module

2016-11-18 Thread Jelte Fennema

Jelte Fennema added the comment:

Is there any issue in merging this? TCP_USER_TIMEOUT is quite useful, for 
automatic failover of connections that suddenly died.

--
nosy: +JelteF

___
Python tracker 

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



[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I see two options:

* Compare flags, isbytes and code. This makes some different patterns be 
compiled to equal objects. For example spaces in verbose mode are ignored. But 
this don't make equal all equivalent patterns. '[aA]' would be equal to 
'(?:a|A)' but still would be not equal to '(i?a)' with current implementation.

* Compare flags, isbytes, code and pattern. This makes literally different 
patterns be compiled to not equal objects even if the difference is not 
significant. '[abc]' would be different from '[cba]' despites the fact that 
matching both always returns the same result.

Since this issue becomes a little ambiguous, I would target the patch to 3.7 
only. Maybe we will find other subtle details or will decide to change the 
meaning of equality of pattern objects before releasing 3.7.

--

___
Python tracker 

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



[issue20572] subprocess.Popen.wait() undocumented "endtime" parameter

2016-11-18 Thread Mariatta Wijaya

Mariatta Wijaya added the comment:

Thanks, Martin :)
Attached is the patch where deprecation warning is emitted if endtime argument 
is passed.
Let me know if this works.

Thanks :)

--
keywords: +patch
Added file: http://bugs.python.org/file45532/issue20572.patch

___
Python tracker 

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



[issue28730] __reduce__ not being called in dervied extension class from datetime.datetime

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It seems to me that this is not documented. I'm even not sure that this change 
is compatible. Additional bit is saved only with protocol 4. The default 
protocol is 3, thus your should explicitly specify it. But protocol 4 is 
supported since 3.4. It seems to me that if you pickle the datetime object with 
the fold bit set with protocol 4, you could get invalid result when unpickle it 
in 3.4 and 3.5. Yet one doubtful detail is that the fold bit is added to the 
hour bit in datetime.time, but to the month field in datetime.datetime.

In any case __reduce_ex__ has the highest priority. After implementing it your 
can be sure that it would be used.

--
nosy: +yselivanov

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

Seems Android/BioniC always uses UTF-8: 
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mbrtoc32.cpp#83

--
nosy: +Chi Hsuan Yen

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

FYI if you rename Python binaries, you can use:

./python-patched perf timeit --compare-to=./python-orig

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> Median +- std dev: 925 ns +- 49 ns
> Median +- std dev: 726 ns +- 30 ns

Nice speedup. Can you please compare Python 3.5? Better if you compile it
yourself with the same options.

I'm curious if 925 ns is slower than py3.5 or if 726 ns is faster than
py3.5.

--

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

If it is not possible to change the locale, it makes sense to hardcode utf8.

Note: to avoid mojibake, it's better if sys.getfilesystemencoding() and
locale.getpreferredencoding(False) are equal. I understand that both must
be utf8.

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The condition in the loop in _PyDict_NewPresized() contains the test newsize > 
0. This is a check for integer overflow. But it doesn't make much sense. First, 
the overflow is undefined behavior, and it is too late to detect it when it 
already is happen. Second, after detecting the negative value just is passed to 
new_keys_object() which either is crashed in debug build or makes other integer 
overflow and creates invalid object.

I would add a runtime check that minused is less than PY_SSIZE_MAX/3 (or more 
strong PY_SSIZE_MAX/3*2/sizeof(Pobject *)). This would guarantee that integer 
overflow is not possible. The test "newsize > 0" could be removed.

There is similar code in dictresize().

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

inada-n@test1:~/work/py36$ ~/local/py36/bin/patched -m perf timeit --compare-to 
~/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6}'
master: . 910 ns +- 49 ns
patched: . 713 ns +- 26 ns

Median +- std dev: [master] 910 ns +- 49 ns -> [patched] 713 ns +- 26 ns: 1.28x 
faster

inada-n@test1:~/work/py36$ ~/local/py36/bin/patched -m perf timeit --compare-to 
~/local/py35/bin/python3.5 -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6}'
python3.5: . 1.17 us +- 0.06 us
patched: . 720 ns +- 24 ns

Median +- std dev: [python3.5] 1.17 us +- 0.06 us -> [patched] 720 ns +- 24 ns: 
1.62x faster

--

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

There are some locale strings supported in setlocale(): 
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/locale.cpp#104.
 However, seems mbstowcs just ignores such a setting on Android. Here's an 
example:

#include 
#include 
#include 
#include 

#define BUFFER_SIZE 10

void test_mbstowcs()
{
wchar_t dest[BUFFER_SIZE];
memset(dest, 0, sizeof(dest));
printf("mbstowcs: %ld\n", mbstowcs(dest, "中文", BUFFER_SIZE));
printf("dest: %x %x\n", dest[0], dest[1]);
}

int main()
{
printf("setlocale: %d\n",  setlocale(LC_ALL, "en_US.UTF-8") != NULL);
test_mbstowcs();
printf("setlocale: %d\n",  setlocale(LC_ALL, "C") != NULL);
test_mbstowcs();
return 0;
}

On Linux (glibc 2.24) the result is:

$ ./a.out 
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587
setlocale: 1
mbstowcs: -1
dest: 0 0

On Android (6.0 Marshmallow) the result is:
shell@ASUS_Z00E_2:/ $ /data/local/tmp/a.out
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587

A quick search indicates setlocale() affects *scanf functions only, so I guess 
it's safe to force UTF-8 in CPython.

--

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread Eryk Sun

Eryk Sun added the comment:

spawnl is implemented by calling _spawnv [1], which is documented to invoke the 
invalid parameter handler if argv points to a NULL pointer. It wants the 
program name, or whatever, as long as argv[0] isn't NULL or an empty string, 
e.g. `os.spawnl(os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe', 'tclsh')`. 

The invalid parameter handler should be disabled (_Py_BEGIN_SUPPRESS_IPH) when 
calling _spawnv[e], which in this case would lead to an EINVAL OSError instead 
of crashing the process. 

For example:

import os, sys
from ctypes import *

ucrt = CDLL('ucrtbase')

@CFUNCTYPE(None, c_wchar_p, c_wchar_p, c_wchar_p, c_int, c_void_p)
def iph(*args):
pass

ucrt._set_thread_local_invalid_parameter_handler(iph)

>>> os.spawnl(os.P_NOWAIT, sys.executable)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python35\lib\os.py", line 977, in spawnl
return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument

Also, in this case a descriptive ValueError would be friendlier, given an empty 
argv or argv[0] that's an empty string -- at least on Windows.

[1]: https://msdn.microsoft.com/en-us/library/7zt1y878.aspx

--
nosy: +eryksun

___
Python tracker 

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



[issue28730] __reduce__ not being called in dervied extension class from datetime.datetime

2016-11-18 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> On Nov 18, 2016, at 7:04 AM, Serhiy Storchaka  wrote:
> 
> Yet one doubtful detail is that the fold bit is added to the hour bit in 
> datetime.time, but to the month field in datetime.datetime.

The reason behind this choice is documented in PEP 495: "We picked these bytes 
because they are the only bytes that are checked by the current unpickle code. 
Thus loading post-PEP fold=1 pickles in a pre-PEP Python will result in an 
exception rather than an instance with out of range components."

https://www.python.org/dev/peps/pep-0495/#pickles

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

Python 3.5 has similar issue:
$ ~/local/py35/bin/patched -m perf timeit --compare-to ~/local/py35/bin/master 
-- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6}'
master: . 1.15 us +- 0.09 us
patched: . 885 ns +- 37 ns

Median +- std dev: [master] 1.15 us +- 0.09 us -> [patched] 885 ns +- 37 ns: 
1.30x faster


patch:
diff -r 20f62e4a9c2f Objects/dictobject.c
--- a/Objects/dictobject.c  Wed Nov 16 16:32:22 2016 -0800
+++ b/Objects/dictobject.c  Fri Nov 18 12:56:38 2016 +
@@ -1015,8 +1015,9 @@ PyObject *
 {
 Py_ssize_t newsize;
 PyDictKeysObject *new_keys;
+minused = (minused * 3 + 1) / 2;
 for (newsize = PyDict_MINSIZE_COMBINED;
- newsize <= minused && newsize > 0;
+ newsize < minused && newsize > 0;
  newsize <<= 1)
 ;
 new_keys = new_keys_object(newsize);

--

___
Python tracker 

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



[issue28733] Show how to use mock_open in modules other that __main__

2016-11-18 Thread Michał Bultrowicz

New submission from Michał Bultrowicz:

Documentation of mock_open doesn't say how to use it in real-life test 
situations (when you're probably not mocking in __main__). I've spent some time 
scratching my head and googling for the way to mock-out the "open" function, 
want to spare other people the hassle.

The thing is that "open" needs to be mocked out from the magical "builtins" 
module, and not from the place of usage (like when mocking everything that's 
not built-in). So it's not obvious how to do that, especially that the example 
with __main__ makes it look like the normal mocking approach should work.

I still don't fully understand why mocking "__main__.open" can work from 
interpreter, but that's a different thing...

--
assignee: docs@python
components: Documentation
files: mock_open_doc.patch
keywords: patch
messages: 281114
nosy: butla, docs@python
priority: normal
severity: normal
status: open
title: Show how to use mock_open in modules other that __main__
type: enhancement
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45533/mock_open_doc.patch

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Ok, it's an optimization, not a performance regression of Python 3.6. In this 
case, I suggest to first push the change to Python 3.7, and after 3.6.0 
release, backport to 3.6 (if you want to), and maybe even 3.5 if it makes sense 
(and if you want).

I didn't review the patch.

--

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

In Python, the most important functions are Py_DecodeLocale() and
Py_EncodeLocale() which use mbstowcs() and wvstombs().

--

___
Python tracker 

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



[issue28732] spawnl crash on windows7

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

I like the idea of using _Py_BEGIN_SUPPRESS_IPH, but also the idea of
implementing most obvious checks on arguments. Sadly, I don't have
access to Windows yet to write such patch. Eryk, if you write such
patch, I would be happy to review it ;-) Especially if it includes
unit tests :-D

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

On Fri, Nov 18, 2016 at 9:31 PM, Serhiy Storchaka
 wrote:
>
> Serhiy Storchaka added the comment:
>
> The condition in the loop in _PyDict_NewPresized() contains the test newsize 
> > 0. This is a check for integer overflow. But it doesn't make much sense. 
> First, the overflow is undefined behavior, and it is too late to detect it 
> when it already is happen. Second, after detecting the negative value just is 
> passed to new_keys_object() which either is crashed in debug build or makes 
> other integer overflow and creates invalid object.
>
> I would add a runtime check that minused is less than PY_SSIZE_MAX/3 (or more 
> strong PY_SSIZE_MAX/3*2/sizeof(Pobject *)). This would guarantee that integer 
> overflow is not possible. The test "newsize > 0" could be removed.
>
> There is similar code in dictresize().
>

Nice idea.  I'll update patch in issue28147.

In case of _PyDict_NewPresized(minused), it would be called from 3rd
party libraries, and there are no strong
guarantee about PyDict_SetItem() won't resize until minused items.
So how about more small, maximum presize?

#define MAX_INITSIZE (128 * 1024)

if (minused > USABLE_FRACTION(MAX_INITSIZE)) {
newsize = MAX_INITSIZE;
}
else {
newsize = PyDict_MINSIZE;
whilie (newsize < minused)
newsize <<= 1;   // Can't we assume *= 2 is optimized?
};

--

___
Python tracker 

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



[issue28730] __reduce__ not being called in dervied extension class from datetime.datetime

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for your explanation Alexander. It looks reasonable.

But there are two drawbacks.

1. By default the fold bit is ignored. That means that you lost it when use 
multiprocessing or other library that uses default pickle protocol.

2. It is not easy to make a workaround for pickles with fold=1 in pre-PEP 
Python.

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Even if the use case is limited (creation of small dictionaries), it's a nice 
enhancement, good job Naoki! It's nice to see someone looking at this very 
important Python type!

1.28x faster or 1.62x faster is significant for a micro-optimization! (My 
personal threshold is at least 10% faster for a micro-optimization.)

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> So how about more small, maximum presize?

I don't know what is the benefit of this, but this change looks correct. The 
benefit of preresizing is vanishingly small for very large dicts.

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This optimization affects only 6-element (and perhaps to less extend 
11-element) dicts. But in any case this is good enhancement.

Naoki, could you please make microbenchmarks for 5- and 7-element dicts with 
your next patch?

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

Can I assume PY_SSIZE_T_MAX is 2**n-1?
If so, I can define like:

#define PyDict_MAXSIZE (PY_SSIZE_T/8+1)

--

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> Can I assume PY_SSIZE_T_MAX is 2**n-1?

I think so. Add an assertion just to be sure :-)

--

___
Python tracker 

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



[issue28159] Deprecate isdst argument in email.utils.localtime

2016-11-18 Thread R. David Murray

R. David Murray added the comment:

At this point I think the deprecation warning will go into 3.7, but we should 
be able to remove it in 3.8.  I think I'll probably keep the 'localtime' method 
and have it delegate it to astimezone, because frankly I would never be able to 
remember that that was the datetime method I needed to get localtime.

--

___
Python tracker 

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



[issue28730] __reduce__ not being called in dervied extension class from datetime.datetime

2016-11-18 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> On Nov 18, 2016, at 8:49 AM, Serhiy Storchaka  wrote:
> 
> But there are two drawbacks.

It is not too late to make improvements.  If you have specific proposals - 
please bring them up on  the mailing list.

--

___
Python tracker 

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



[issue28159] Deprecate isdst argument in email.utils.localtime

2016-11-18 Thread Mariatta Wijaya

Mariatta Wijaya added the comment:

Thanks David :)
So, I found that isdst was never added as method signature in the docs, but it 
is mentioned in the paragraph.
https://docs.python.org/3.7/library/email.util.html?#email.utils.localtime

The intention is still just to deprecate isdst argument, right? not the 
localtime().

I can add a sentence in the docs indicating that we favor datetime.astimezone() 
instead of email.utils.localtime(), if that works for you. What do you think 
about this?

--

___
Python tracker 

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



[issue28734] argparse: successive parsing wipes out nargs=? values

2016-11-18 Thread Adam Stewart

New submission from Adam Stewart:

I'm writing a wrapper that optionally accepts a file and reads more options 
from that file. The wrapper then needs to pass all of these options and the 
file to another program (qsub). Here is a minimal example to reproduce the 
behavior I'm seeing:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-a')
>>> parser.add_argument('file', nargs='?')
>>> args = parser.parse_args(['-a', '3', 'myFile'])
>>> print(args)
Namespace(file='myFile', a='3')
>>> parser.parse_args(['-a', '4'], namespace=args)
>>> print(args)
Namespace(file=None, a='4')

The behavior I expect is that the file should remain as 'myFile', but it is 
being wiped out. Is there any way to prevent this, or is this actually a bug?

I can recreate this problem in Python 2.7 and 3.5.

--
components: Library (Lib)
messages: 281128
nosy: ajstewart
priority: normal
severity: normal
status: open
title: argparse: successive parsing wipes out nargs=? values
type: behavior
versions: Python 3.5

___
Python tracker 

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



[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

To reduce the memory footprint, it's important that we reuse internal Unicode 
singletons. For the empty string singleton, you have two choices:

* if length is equal to zero, return the singleton
* create a string and then call unicode_result()

unicode_result() should be used when the output length is not easy to compute 
or when the code is complex.

Here is the code is very simple and the output length is obvious.

Serhiy: "In what circumstances _PyUnicode_FromASCII is called with size=0?"

I checked the current code: I'm unable to see any function which can call 
_PyUnicode_FromASCII() with size=0.


Xiang: "IMHO, _PyUnicode_FromASCII is a private API and could be used in other 
places in future. We should not rely on the caller to check and return the 
singleton empty string."

I agree. Xiang's patch is short and makes sense, so I vote +1 on it.

I let Serhiy decides if the patch should be merged or not.

If we decide to reject the patch, I suggest to add the following code at the 
beginning of _PyUnicode_FromASCII:

/* Detect missed optimization */
assert(size != 0);

--

___
Python tracker 

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



[issue26936] android: test_socket fails

2016-11-18 Thread Xavier de Gaye

Xavier de Gaye added the comment:

New patch using support.less_than_android_api(level).

--
stage: patch review -> commit review
Added file: http://bugs.python.org/file45534/test_socket_2.patch

___
Python tracker 

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



[issue28694] tkinter interface to fontchooser

2016-11-18 Thread Lance Ware

Lance Ware added the comment:

Not having any luck creating a patch. I have retrieved source, built python, 
put my fontchooser.py file (attached) in cpython\Lib\tkinter, done hg add and 
hg commit, but when I try to do hg diff it gives me nothing.

--
Added file: http://bugs.python.org/file45536/fontchooser.py

___
Python tracker 

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



[issue28531] Improve utf7 encoder memory usage

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Serhiy Storchaka: "The performance of the UTF-7 codec is not important."

Right.


"Actually I'm going to propose replacing it with Python implementation."

Oh. Sadly, PyUnicode_DecodeUTF7() is part of the stable ABI. Do you want to 
call the Python codec from the C function for backward compatibility?

I dislike UTF-7 because it's complex, but it's not as optimized as the UTF-8 
codec, so the code remains not too big and so not too expensive to matain.


"This encoder was omitted form _PyBytesWriter-using optimizations for purpose."

Ah? I don't recall that. When I wrote _PyBytesWriter, I skipped UTF-7 because I 
don't know well this codec and I preferred to keep the code unchanged to avoid 
bugs :-)


"The patch complicates the implementation."

Hum, I have to disagree. For me, the patched new is no more complex than the 
current code. The main change is that it adds code checking the kind to better 
estimate the output length. It's not hard to understand the link between the 
Unicode kind of the max_char_size.


I vote +1 on this patch because I consider that it makes the code simpler, not 
because it makes the codec faster (I don't really care of UTF-7 codec 
performance).

But again (as in issue #28398), it's up to you Serhiy: I'm also ok to leave the 
code unchanged if you are against the patch.

--

___
Python tracker 

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



[issue26928] _bootlocale imports locale at startup on Android, causing test_site to fail

2016-11-18 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

Submitted a patch to issue28596

--

___
Python tracker 

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



[issue28596] on Android _bootlocale on startup relies on too many library modules

2016-11-18 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

Here's my try: force UTF-8 on Android as explained in msg281110. 
sys.getfilesystemencoding() is already UTF-8 since issue22747.

Testing:
1. Starting up time 0.18~0.19s => 0.11~0.12s, on Android 6.0, ASUS ZE500KL 
(Qualcomm MSM8916 QuadCore 1.2GHz)
2. test_site passes

--
keywords: +patch
nosy: +Chi Hsuan Yen
Added file: http://bugs.python.org/file45535/android-locale-utf8.patch

___
Python tracker 

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



[issue28735] Mock is equal to ANY but MagicMock is not

2016-11-18 Thread Rafael Jacinto Caricio da Fonseca

New submission from Rafael Jacinto Caricio da Fonseca:

On Python 3.5.2 mock.Mock() is equal to mock.ANY, but mock.MagicMock() is not.

Minimal example:

In Python 3.5.2:
>>> from unittest import mock
>>> mock.Mock() == mock.ANY
True
>>> mock.ANY == mock.Mock()
True
>>> mock.MagicMock() == mock.ANY
False
>>> mock.ANY == mock.MagicMock()
True

--
components: Library (Lib)
messages: 281135
nosy: rafael.fonseca
priority: normal
severity: normal
status: open
title: Mock is equal to ANY but MagicMock is not
type: behavior
versions: Python 3.5

___
Python tracker 

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



[issue28731] _PyDict_NewPresized() creates too small dict

2016-11-18 Thread INADA Naoki

INADA Naoki added the comment:

> This optimization affects only 6-element (and perhaps to less extend 
> 11-element) dicts. But in any case this is good enhancement.

This affects when minused = (n*2/3)+1 .. n-1 (n=8, 16, ...)

n=8: 6, 7
n=16: 11, 12, ..15

> Naoki, could you please make microbenchmarks for 5- and 7-element dicts with 
> your next patch?

+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5}'
master: . 568 ns +- 18 ns
patched: . 567 ns +- 23 ns

Median +- std dev: [master] 568 ns +- 18 ns -> [patched] 567 ns +- 23 ns: 1.00x 
faster
Not significant!
+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, 
"f":6}'
master: . 1.01 us +- 0.04 us
patched: . 756 ns +- 20 ns

Median +- std dev: [master] 1.01 us +- 0.04 us -> [patched] 756 ns +- 20 ns: 
1.33x faster
+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, 
"f":6, "g":7}'
master: . 1.12 us +- 0.03 us
patched: . 867 ns +- 31 ns

Median +- std dev: [master] 1.12 us +- 0.03 us -> [patched] 867 ns +- 31 ns: 
1.29x faster
+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, 
"f":6, "g":7, "h":8}'
master: . 1.04 us +- 0.03 us
patched: . 1.03 us +- 0.04 us

Median +- std dev: [master] 1.04 us +- 0.03 us -> [patched] 1.03 us +- 0.04 us: 
1.00x faster
Not significant!
+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, 
"f":6, "g":7, "h":8, "i":9, "j":10}'
master: . 1.16 us +- 0.04 us
patched: . 1.16 us +- 0.04 us

Median +- std dev: [master] 1.16 us +- 0.04 us -> [patched] 1.16 us +- 0.04 us: 
1.00x faster
Not significant!
+ /home/inada-n/local/py36/bin/patched -m perf timeit --compare-to 
/home/inada-n/local/py36/bin/master -- 'd = {"a":1, "b":2, "c":3, "d":4, "e":5, 
"f":6, "g":7, "h":8, "i":9, "j":10, "k":11}'
master: . 1.67 us +- 0.06 us
patched: . 1.39 us +- 0.04 us

Median +- std dev: [master] 1.67 us +- 0.06 us -> [patched] 1.39 us +- 0.04 us: 
1.20x faster

--

___
Python tracker 

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



[issue28734] argparse: successive parsing wipes out nargs=? values

2016-11-18 Thread Wolfgang Maier

Wolfgang Maier added the comment:

try this:
parser.add_argument('file', nargs='?', default = argparse.SUPPRESS)

I don't think this is a bug. The default for the default parameter is None so 
the behavior is consistent with the documentation.

--
nosy: +wolma

___
Python tracker 

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



[issue25731] Assigning and deleting __new__ attr on the class does not allow to create instances of this class

2016-11-18 Thread Carl Dunham

Changes by Carl Dunham :


--
nosy: +Carl Dunham

___
Python tracker 

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



[issue28734] argparse: successive parsing wipes out nargs=? values

2016-11-18 Thread Adam Stewart

Adam Stewart added the comment:

Works for me, thanks Wolfgang!

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

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



[issue28159] Deprecate isdst argument in email.utils.localtime

2016-11-18 Thread R. David Murray

R. David Murray added the comment:

No, localtime does something subtly different, in that it will accept a naive 
datetime add the local timezone to it.  Calling localtime() is also more 
convenient/readable than calling datetime.now().astimezone().

--

___
Python tracker 

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



[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I know that _PyUnicode_FromASCII() is called with size=0. But most callers call 
it only with size!=0. I didn't investigate further. We should know what is the 
benefit of the patch before committing it. Just "for consistency" is a weak 
argument itself.

--

___
Python tracker 

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



[issue28736] multiprocessing.Lock() no longer has .acquire()

2016-11-18 Thread Eric Leadbetter

New submission from Eric Leadbetter:

The documentation on the multiprocessing library in Python 3 uses 
Lock.acquire()/Lock.release() in the example for primitive synchronization 
(https://docs.python.org/3/library/multiprocessing.html#synchronization-between-processes).
 Lock() has been changed in Python 3 to use coroutines and so the documentation 
should replace the call to Lock.acquire() with an appropriate yield statement.

--
assignee: docs@python
components: Documentation
messages: 281141
nosy: Eric Leadbetter, docs@python
priority: normal
severity: normal
status: open
title: multiprocessing.Lock() no longer has .acquire()
versions: Python 3.3, Python 3.4, 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



[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> We should know what is the benefit of the patch before committing it.

The purpose of the patch is to use the empty string singleton to reduce the 
memory footprint, instead of creating multiple empty (Unicode) string objects.

--

___
Python tracker 

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



[issue28531] Improve utf7 encoder memory usage

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I fixed many long living bugs in the UTF-7 codec in the past, and I remember 
that we fixed bugs introduced by using _PyUnicodeWriter or _PyBytesWriter many 
months after changing the code. Since the UTF-7 codec is rarely used, there is 
a risk of introducing new long living bug. You should peruse not just the code 
near the changed lines, but all the codec.

I'm not strongly against this patch, if you Victor takes the responsibility for 
it, I left it on you.

--
assignee:  -> haypo

___
Python tracker 

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



[issue28531] Improve utf7 encoder memory usage

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Oh no, now I'm afraid of breaking something :-D I don't trust anymore our test 
suite for the UTF-7 codec, so I close the issue :-)

Sorry Xiang, but as we said, this rarely used codec is not important enough to 
require optimization.

--
resolution:  -> rejected
status: open -> closed

___
Python tracker 

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



[issue28531] Improve utf7 encoder memory usage

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

> I remember that we fixed bugs introduced by using _PyUnicodeWriter or 
> _PyBytesWriter many months after changing the code.

Yeah, now I recall it (vaguely), that's why I closed the bug :-)

--

___
Python tracker 

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



[issue28737] Document that tp_dealloc handler must call PyObject_GC_UnTrack if Py_TPFLAGS_HAVE_GC is set

2016-11-18 Thread Sam Gross

New submission from Sam Gross:

In general, an a PyTypeObject that has Py_TPFLAGS_HAVE_GC set must call 
PyObject_GC_UnTrack() before it frees any PyObject* references it owns. The 
only reference to this requirement I found is in 
https://docs.python.org/3/c-api/gcsupport.html#c._PyObject_GC_TRACK.

This requirement should be documented in:

1. https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc
2. https://docs.python.org/3/extending/newtypes.html

A call to PyObject_GC_UnTrack() should also be added to he official "noddy4" 
example. Currently, the example is incorrect and can crash if a referred-to 
object triggers a GC from it's destructor. See the following example which 
segfaults:

https://github.com/colesbury/noddy

It may be worthwhile to have _Py_Dealloc call PyObject_GC_UnTrack() if the 
PyTypeObject has Py_TPFLAGS_HAVE_GC set. Considering that the official Python 
extension example is missing the call, it seems likely that extension writers 
often forget to include it.

--
assignee: docs@python
components: Documentation, Extension Modules
messages: 281146
nosy: colesbury, docs@python
priority: normal
severity: normal
status: open
title: Document that tp_dealloc handler must call PyObject_GC_UnTrack if 
Py_TPFLAGS_HAVE_GC is set
versions: Python 3.5

___
Python tracker 

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



[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

My question is simple: in what circumstances the patch has an effect?

--

___
Python tracker 

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



[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Xiang Zhang

Xiang Zhang added the comment:

> My question is simple: in what circumstances the patch has an effect?

My original intention is that there is no need for the caller to check for the 
empty string. Even there is no use case now, it could be in future.

But Serhiy, I am actually very glad to get a determined result, even it's 
rejected. If the issue is still open, I would think you are still open to 
discussion. Such a trivial patch isn't worth it.

--
assignee:  -> serhiy.storchaka

___
Python tracker 

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



[issue28728] test_host_resolution in test_socket fails on duplicate assert

2016-11-18 Thread SilentGhost

Changes by SilentGhost :


Removed file: http://bugs.python.org/file45524/test_socket.diff

___
Python tracker 

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



[issue28728] test_host_resolution in test_socket fails

2016-11-18 Thread SilentGhost

SilentGhost added the comment:

Of course, you're right, that was my mistake. The last three addresses fail to 
raise, namely: '::1q', '::1::2' and '1:1:1:1:1:1:1:1:1'.

--
stage: patch review -> 
title: test_host_resolution in test_socket fails on duplicate assert -> 
test_host_resolution in test_socket fails

___
Python tracker 

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



[issue28694] tkinter interface to fontchooser

2016-11-18 Thread Zachary Ware

Zachary Ware added the comment:

I would recommend backing out your commit (hg rollback if you haven't pulled or 
otherwise changed your checkout since you made your commit), and just do 'hg 
diff' at the point where you would commit.  In this particular case, if there 
are no changes other than the added file it doesn't really matter much that 
it's not in patch form.

It would be nice to have some unit tests.  It may not be possible to test 
anything but your _str_to_font and _font_to_str functions, though.

I notice that your Fontchooser class doesn't inherit from commondialog.Dialog 
like colorchooser.Chooser does; is commondialog.Dialog usable for this?  Or are 
there improvements that can be made to commondialog.Dialog to make it suitable 
for Fontchooser and also improve colorchooser.Chooser?  Can this reuse anything 
from Lib/tkinter/font.py or perhaps be merged into that file to keep all the 
font stuff together?

After we have some of those details ironed out, this is going to make a nice 
addition to tkinter!

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



[issue28673] pyro4 with more than 15 threads often crashes 2.7.12

2016-11-18 Thread Terry J. Reedy

Changes by Terry J. Reedy :


--
stage:  -> test needed
title: When using pyro4 with more than 15 threads, python 2.7.12 cores 
frequently -> pyro4 with more than 15 threads often crashes 2.7.12

___
Python tracker 

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



[issue28677] difficult to parse sentence structure in "When an instance attribute is referenced that isn't a data attribute"

2016-11-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

David's wording looks good.

--
nosy: +terry.reedy

___
Python tracker 

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



[issue28596] on Android _bootlocale on startup relies on too many library modules

2016-11-18 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

Version 2 - use sys.implementation._multiarch to determine whether it's Android 
or not

--
Added file: http://bugs.python.org/file45537/android-locale-utf8.patch

___
Python tracker 

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



[issue28736] multiprocessing.Lock() no longer has .acquire()

2016-11-18 Thread R. David Murray

R. David Murray added the comment:

What gives you the idea that the multiprocessing Lock implementation has been 
changed?  Are you confusing the asyncio Lock with the threading Lock?  Is there 
a documentation crosslink somewhere that is going to the wrong place?

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



[issue28596] on Android _bootlocale on startup relies on too many library modules

2016-11-18 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy:  -pitrou

___
Python tracker 

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



[issue24452] Make webbrowser support Chrome on Mac OS X

2016-11-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 0c8270cbdc62 by Brett Cannon in branch 'default':
Issue #24452: add attribution
https://hg.python.org/cpython/rev/0c8270cbdc62

--

___
Python tracker 

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



[issue28681] About function renaming in the tutorial

2016-11-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

It took me a moment to realize that 'value of the function name' meant 'the 
function object associated with the name'.  I think David's rewrite is a 
substantial improvement.  I would just change the end 'can be used as a 
function' to 'can be used to access the function.'

'Renaming' is wrong to me because it implies invalidation of the previous name. 
'Alternate name' is more accurate.

I agree that 'alias' is better, but also that it is a bit problematical*.  
'Alias' is distinct from 'legal name'. The closest analogy to 'legal name' is 
'definition name' (.__name__ attribute).  But definition names are distinct 
from bound names, only some objects have definition names, and when they do, 
they can be renamed if and only if the object is coded in Python. 

I don't understand the relevance of the middle sentence
   "The interpreter recognizes the object pointed to by that
   name as a user-defined function."
All objects can be given multiple names.  In this context, the difference 
between C and Python coded names is whether the .__name__ attribute can be 
rebound, and that attribute is not part of the discussion here.  The paragraph 
introduces this code example, which has nothing to do with .__name__.

   >>> fib
   
   >>> f = fib
   >>> f(100)
   0 1 1 2 3 5 8 13 21 34 55 89

(* Steven, I would say that both 'x' and 'y' in your example are aliases for 
the int 1.  But I understand the other viewpoint.)

--
nosy: +terry.reedy
stage:  -> needs patch
versions:  -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



[issue28705] Clean up design FAQ question about compiling to C

2016-11-18 Thread Brett Cannon

Changes by Brett Cannon :


--
resolution:  -> fixed
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



[issue28705] Clean up design FAQ question about compiling to C

2016-11-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a0a3dab4ed66 by Brett Cannon in branch '3.6':
Issue #28705: greatly simplify the FAQ entry on transpiling.
https://hg.python.org/cpython/rev/a0a3dab4ed66

New changeset 89e2201142f9 by Brett Cannon in branch 'default':
Merge for issue #28705
https://hg.python.org/cpython/rev/89e2201142f9

--
nosy: +python-dev

___
Python tracker 

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



[issue28736] multiprocessing.Lock() no longer has .acquire()

2016-11-18 Thread Eric Leadbetter

Eric Leadbetter added the comment:

It was a typographical error on my part. My mistake.

--
status: open -> closed

___
Python tracker 

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



[issue28687] Python 2.7.12 windows x64 installer fails after previous bad uninstall

2016-11-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I had something like this happen with early 3.y.z.  I believe I re-downloaded 
and re-installed the old version before either uninstalling or upgrading.  I 
now keep the installer for x.y.z around until it is deleted or replaced.  (I 
don't now if this is still needed for the 3.5+ non-msi installers.)

I don't know how easy it would be to make a change as the author/maintainer of 
the msi installers is not currently active.

--
nosy: +loewis, steve.dower, terry.reedy

___
Python tracker 

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



[issue28693] No HKSCS support in Windows cp950

2016-11-18 Thread Terry J. Reedy

Changes by Terry J. Reedy :


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



[issue28736] multiprocessing.Lock() no longer has .acquire()

2016-11-18 Thread Zachary Ware

Changes by Zachary Ware :


--
resolution:  -> not a bug
stage:  -> resolved

___
Python tracker 

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



[issue28738] Document SIGBREAK as argument for signal() under Windows.

2016-11-18 Thread Wojtek Ruszczewski

New submission from Wojtek Ruszczewski:

SIGBREAK should be listed as acceptable for signal.signal() under Windows.

Some context. Registering a handler for SIGBREAK may be useful as this is the 
signal that generating CTRL_BREAK_EVENT results in (and the latter combined 
with the CREATE_NEW_PROCESS_GROUP flag might be the closest that one can get to 
terminating a process group).

Some pointers:
* The changed documentation fragment: 
https://docs.python.org/3/library/signal.html#signal.signal.
* MSDN doesn't say so much about SIGBREAK: 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682541(v=vs.85).aspx.
* SIGBREAK was added to the signal module with #466877.
* The signal number check looks as follows: 
https://github.com/python/cpython/blob/3.6/Modules/signalmodule.c#L402.

--
assignee: docs@python
components: Documentation, Windows
files: sigbreak.patch
keywords: patch
messages: 281159
nosy: docs@python, paul.moore, steve.dower, tim.golden, wrwrwr, zach.ware
priority: normal
severity: normal
status: open
title: Document SIGBREAK as argument for signal() under Windows.
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file45538/sigbreak.patch

___
Python tracker 

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



[issue28702] Confusing error message when None used in expressions, eg. "'NoneType' object has no attribute 'foo'"

2016-11-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I have doubts also.

The issue is the same for NotImplemented, though the occurrence is much rarer, 
and similar for Ellipsis.

>>> NotImplemented.foo
Traceback (most recent call last):
  File "", line 1, in 
NotImplemented.foo
AttributeError: 'NotImplementedType' object has no attribute 'foo'
>>> Ellipsis.foo
Traceback (most recent call last):
  File "", line 1, in 
Ellipsis.foo
AttributeError: 'ellipsis' object has no attribute 'foo'

Replacing the type name with the object name works for this message, but not 
for the type errors.
  TypeError: unsupported operand type(s) for +: 'None' and 'int'
is wrong.

Replacing 'NoneType' with 'None' in error messages will break code that does 
something like "if 'NoneType' in err.args[0]" in an exception message.  The 
same replacement would have to be make in user code.  Fortunately, it would 
continue to work with older versions.

--
nosy: +terry.reedy
stage:  -> test needed
versions: +Python 3.7 -Python 3.6

___
Python tracker 

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



[issue28159] Deprecate isdst argument in email.utils.localtime

2016-11-18 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Keeping localtime as a convenience function in email.util is fine, but isdst 
argument should be eliminated at some point.  There is a fundamental problem 
with disambiguating fold times with isdst: some folds do not involve the change 
in dst or happen in the regions that do not have a dst regime at all.  PEP 495 
covers this in all the gory details.

--

___
Python tracker 

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



[issue28710] Sphinx incompatible markup in configparser.ConfigParser.

2016-11-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

As far as I looked, the patch changes `xyz' in docstrings and quotes to 
``xyz``.  A rst expert should verify that this is correct.  In printed strings, 
`zyz' is changed to 'xyz', which I consider to be correct.

Before applying this, I would want to review in Rietveld, with side by side 
diff and changes color marked.  However, Rietveld does not like the patch and 
there is no 'review' button.  I thought it might be the git format, but I found 
another git patch that did have a review button.  When I downloaded and tried 
to apply (to default), hg says that there is no diff.  I don't see the problem, 
but we cannot currently use a patch that does not apply in hg.

Patrick, in order to use patches, we require Contributor Agreements.
https://www.python.org/psf/contrib/
There is an electronic form that makes submission easy.
https://www.python.org/psf/contrib/contrib-form/

--
nosy: +terry.reedy
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



[issue28687] Python 2.7.12 windows x64 installer fails after previous bad uninstall

2016-11-18 Thread Steve Dower

Steve Dower added the comment:

So the fix for pre-2.7.13 here is to Repair first and then reinstall. 

But we've actually fixed this for 2.7.13 by making the pip uninstall step 
non-vital (the work was sponsored by Microsoft because it affects the Visual 
Studio installer). See issue27888 for the change.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Hide pip install/uninstall windows in setup

___
Python tracker 

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



[issue28687] Python 2.7.12 windows x64 installer fails after previous bad uninstall

2016-11-18 Thread Steve Dower

Steve Dower added the comment:

> ...is to Repair first and then reinstall

Repair and then *un*install (obviously).

--

___
Python tracker 

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



[issue28710] Sphinx incompatible markup in configparser.ConfigParser.

2016-11-18 Thread R. David Murray

R. David Murray added the comment:

I think that we do not generally use ReST markup in our docstrings.  So 
replacing `x' with 'x' would be more correct, I think.  In many cases the 
quotes could just be omitted entirely.

The patch command says:

  patch unexpectedly ends in middle of line
  patch:  Only garbage was found in the patch input.

--

___
Python tracker 

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



[issue28739] PEP 498: docstrings as f-strings

2016-11-18 Thread Yury Selivanov

New submission from Yury Selivanov:

Can f-strings be used as docstrings?

Right now:

class Foo:
   f'spam'
Foo.__doc__ is None

I couldn't find that f-strings cannot be used as docstrings in neither PEP 498 
not in the 3.6 documentation, so I suppose this is a bug.

--
components: Interpreter Core
messages: 281166
nosy: eric.smith, gvanrossum, martin.panter, yselivanov
priority: normal
severity: normal
status: open
title: PEP 498: docstrings as f-strings
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



[issue28739] PEP 498: docstrings as f-strings

2016-11-18 Thread Eric V. Smith

Eric V. Smith added the comment:

As you've seen, the answer is "no"!

We'd need to add logic to evaluate them at function definition time. That would 
be a slight noticeable change, if the expressions had side effects.

--

___
Python tracker 

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



[issue28735] Mock is equal to ANY but MagicMock is not

2016-11-18 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +michael.foord
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



[issue28739] PEP 498: docstrings as f-strings

2016-11-18 Thread Martin Panter

Martin Panter added the comment:

There was a bit of discussion at the top of 
.

IMO it would be simpler do disallow all f-strings as docstrings. Otherwise, 
what would the result of this be:

name = "module level"
class C:
name = "class level"
def m(self, name="default param"):
f"{name}"

--

___
Python tracker 

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



[issue28740] Add sys.getandroidapilevel()

2016-11-18 Thread STINNER Victor

New submission from STINNER Victor:

Android slowly becomes a first-citizen class platform in CPython thanks to 
Xavier de Gaye and other motivated developers, thanks to all of them :-)

To fix the issue #28596, we need a function to check if we are running Android. 
Chi Hsuan Yen proposed to use sysconfig to get the new ANDROID_API_LEVEL 
configuration option:

+if sysconfig.get_config_var('ANDROID_API_LEVEL'):

But I asked to avoid sysconfig to reduce imports at Python startup (especially 
when the site module is not loaded). I proposed to add a new function to the 
sys module: sys.getandroidapilevel().

sys.getandroidapilevel() would only be available on Android, as  
sys.getwindowsversion() is only available on Windows, and would return 
ANDROID_API_LEVEL as an integer.

I'm not sure about the type: should we use a string? A tuple of integers like 
sys.version_info?

sys.getwindowsversion() returns a named tuple:
https://docs.python.org/dev/library/sys.html#sys.getwindowsversion

I'm sorry, I don't have access to an Android development platform, so I let 
someone else implement it :-)

--
messages: 281169
nosy: Chi Hsuan Yen, haypo, xdegaye
priority: normal
severity: normal
status: open
title: Add sys.getandroidapilevel()
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



[issue28596] on Android _bootlocale on startup relies on too many library modules

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

I created the issue #28740: Add sys.getandroidapilevel().

--

___
Python tracker 

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



[issue28740] Add sys.getandroidapilevel()

2016-11-18 Thread STINNER Victor

STINNER Victor added the comment:

Ah, I wrote a patch to implement the function. I used ANDROID_API_LEVEL from 
pyconfig.h. I chose to simply return an integer. I don't know if it's the most 
future-proof API :-)

--
keywords: +patch
Added file: http://bugs.python.org/file45539/getandroidapilevel.patch

___
Python tracker 

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



[issue28739] PEP 498: docstrings as f-strings

2016-11-18 Thread Yury Selivanov

Yury Selivanov added the comment:

> IMO it would be simpler do disallow all f-strings as docstrings.

How exactly you want to disallow them?  Raise SyntaxError?  If you don't raise 
anything, then the behaviour is just confusing -- the interpreter parses them, 
but __doc__ is None.

I think this needs to be fixed.  Eric, can we still fix this in 3.6?  If not, 
then we need to update the PEP and the docs.

--

___
Python tracker 

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



[issue28741] PEP 498: single '}' is not allowed

2016-11-18 Thread Yury Selivanov

New submission from Yury Selivanov:

The PEP should document the "single '}' is not allowed" error.

--
assignee: docs@python
components: Documentation
messages: 281173
nosy: docs@python, eric.smith, yselivanov
priority: normal
severity: normal
status: open
title: PEP 498: single '}' is not allowed
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



  1   2   >