[issue26204] compiler: don't emit LOAD_CONST instructions for constant statements?

2016-01-25 Thread Yury Selivanov

Yury Selivanov added the comment:

The patch looks alright.

Will the following code compile OK?  What will it compile to?

   if 1:
  42

--

___
Python tracker 

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



[issue26194] Undefined behavior for deque.insert() when len(d) == maxlen

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Another take: Do a regular insertion with no special cases, followed by a pop 
from the right:

>>> for i in range(len(d) + 1):
s = list(d)
s.insert(i, None)  
_ = s.pop()
print(i, s)

0 [None, 'a', 'b']
1 ['a', None, 'b']
2 ['a', 'b', None]
3 ['a', 'b', 'c']

Nice parts:
* Doesn't change pop direction depending on the inputs
* Guarantee that entries to the left of i will keep their position.
* Post condition of d[i]==newelem applies whenever i exists.

Not nice part:
* Initially surprising that d.insert(len(d), newelem) does not actually insert 
newelem.
* d.insert(len(d), newelem) not the same as d.append(newelem).

Another alternative is to raise an exception for the one case where 
index==maxlen, with the theory being that d[index] won't be a valid index so 
you can't insert anything there.

--

___
Python tracker 

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



[issue18898] Apply the setobject optimizations to dictionaries

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> Hi, what's the status of this issue? Is anyone working one it?

In the present environment, I feel like advancing this work would be an uphill 
battle and that much of my time investment would be wasted unnecessarily.

That's too bad, because significant r time has already been invested and it 
has had nice payoffs with set objects.

--
status: open -> closed

___
Python tracker 

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



[issue26194] Undefined behavior for deque.insert() when len(d) == maxlen

2016-01-25 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
keywords: +patch
Added file: http://bugs.python.org/file41717/full_deque.diff

___
Python tracker 

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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Eryk Sun

Eryk Sun added the comment:

> An .lnk is launched with ShellExecute which returns control
> immediately upon successful launch

cmd calls ShellExecuteEx, not ShellExecute, and it uses the flags 
SEE_MASK_NO_CONSOLE (0x8000, don't create a new console) and 
SEE_MASK_NOCLOSEPROCESS (0x0040, return a process handle if possible). 

Here's a walk-through with a debugger attached to cmd while executing a LNK 
shortcut to "C:\Program Files\Python27\python.exe": 

C:\Temp>.\python.lnk -c "import sys,time;time.sleep(60);sys.exit(42)"
Breakpoint 0 hit
SHELL32!ShellExecuteExW:
7ff9`a5710e20 48895c2408  mov qword ptr [rsp+8],rbx
ss:00a3`eb3af3a0=00a3eb597ca0
0:000> ; as /x info @rcx
0:000> ; as /x sz @@(*((unsigned long *)${info}))
0:000> bd 2,3,4; pt; be 2,3,4

ShellExecuteEx returns the process handle:

0:000> ?? *((void **)(${info} + ${sz} - 8)); * hProcess
void * 0x`02fc
0:000> !handle 2fc
Handle 2fc
  Type  Process
0:000> g

cmd uses the handle to read the ImageSubsystem type from the process 
environment block (PEB), for which 3 is a console process and 2 is a GUI 
process.

Breakpoint 1 hit
cmd!GetProcessSubsystemType:
7ff7`a133faf4 48895c2410  mov qword ptr [rsp+10h],rbx
ss:00a3`eb3af458=00a3eb585640
0:000> g
Breakpoint 2 hit
KERNELBASE!ReadProcessMemory:
7ff9`a49ac230 4883ec48sub rsp,48h
0:000> as /x buf @r8
0:000> pt
KERNELBASE!ReadProcessMemory+0x2b:
7ff9`a49ac25b c3  ret

0:000> ?? ((ntdll!_PEB *)${buf})->ImageSubsystem
unsigned long 3
0:000> g

Since it's a console process, cmd waits and queries the exit code.

Breakpoint 3 hit
KERNELBASE!WaitForSingleObject:
7ff9`a49840c0 4533c0  xor r8d,r8d
0:000> r rcx
rcx=02fc
0:000> g

Breakpoint 4 hit
KERNELBASE!GetExitCodeProcess:
7ff9`a49c46d0 4053pushrbx
0:000> as /x rc @rdx
0:000> pt
KERNELBASE!GetExitCodeProcess+0x3a:
7ff9`a49c470a c3  ret
0:000> ?? *((unsigned long *)${rc})
unsigned long 0x2a
0:000> ? 0x2a
Evaluate expression: 42 = `002a

It sets the exit code in the 'hidden' environment variable "=ExitCode" as a 
unsigned hexadecimal number.

C:\Temp>echo %=ExitCode%
002A

You can also query the signed value using the pseudo environment variable 
"errorlevel".

C:\Temp>echo %errorlevel%
42

--

___
Python tracker 

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



[issue26194] Undefined behavior for deque.insert() when len(d) == maxlen

2016-01-25 Thread Raymond Hettinger

Changes by Raymond Hettinger :


Added file: http://bugs.python.org/file41718/full_deque_alt.diff

___
Python tracker 

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



[issue26197] arange from numpy function has some limits....I propose a python function that overcome these limitations

2016-01-25 Thread Francesco Pelizza

Changes by Francesco Pelizza :


--
title: arange from numpy function has some limitsI propose a python 
function that overcome -> arange from numpy function has some limitsI 
propose a python function that overcome these limitations

___
Python tracker 

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



[issue26197] arange from numpy function has some limits....I propose a python function that overcome these limitations

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

It looks like an issue for numpy no? 
http://www.scipy.org/scipylib/bug-report.html

I'm not sure that such function fits into Python stdlib.

--
nosy: +haypo

___
Python tracker 

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



[issue26197] arange from numpy function has some limits....I propose a python function that overcome

2016-01-25 Thread Francesco Pelizza

New submission from Francesco Pelizza:

arange from numpy is a function to generate list of floats from a start to an 
end number with a defined float number.

The "arange" function works fine for some cases, but in my case where I have to 
generate numbers that constitute parameters in a Quantum Mechanical 
calculation, numbers can be missing or be more than what I want, since many 
time each number is calculated in a couple of days or more. I need to avoid 
extra numbers or missing numbers to avoid loss of data. And sometimes the 
script will pass to a cycle function wrong numbers for start and stop, or the 
same number as starting and ending point, but I can not avoid this because they 
are numbers coming from Quantum World, and I need a function that sort out 
anything on its own because is inserted in for loops and things like that.

Also arange function does not take the "stop" number as the last number of the 
list, but it will terminate before, so to have the last wanted number in the 
list you have to use the formulae  arange(start,stop+inc,inc) or 
arange(start,stop+n,inc) where n allows is bigger than zero.

Some cases that give me problems are the following:
Defective lists of numbers:
1) arange(1,10+0.001,0.0001) some numbers are missing
2) arange(1,10+0.001,1) generate float without any decimal after the point
3) arange(1,10,0.001) some numbers are missing
4) ...other combination gives problems

Empty lists of numbers:
1) arange(1,10,-1)
2) arange(1,-10,1)
3) arange(1,1,1)
4) arange(1,1,0.5)
5) arange(1,-10,0.005)
6) so on

I made a python function that goes across any of these problems, taking account 
of using the absolute value of the given incremental step number.

Numbers can be float or integers, any exception of number ordering is kept 
under control to generate anyway at least a list of one number, if the stop 
number is bigger than the starting one, they get switched to generate anyway a 
list of numbers. And it can go down until 14 decimal places of incremental 
steps without generating wrong numbers due to the binary conversion of floats!
Some use of this function are eventually weird or really exotic, but in using 
python as a code to deal with computation without crashing for silly numbers 
ordering from the quantum world, is essential.

Do you agree with the improvements I put in this function called "CYCLE" can be 
of help?

I would like to share it with the community.

Here attached the function I made

--
components: Library (Lib)
files: CYCLE.py
messages: 258899
nosy: Francesco Pelizza
priority: normal
severity: normal
status: open
title: arange from numpy function has some limitsI propose a python 
function that overcome
type: enhancement
versions: Python 2.7
Added file: http://bugs.python.org/file41707/CYCLE.py

___
Python tracker 

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



[issue26197] arange from numpy function has some limits....I propose a python function that overcome these limitations

2016-01-25 Thread Emanuel Barry

Emanuel Barry added the comment:

NumPy isn't a part of CPython. As haypo said, please submit that to their 
tracker instead.

--
nosy: +ebarry
resolution:  -> third party
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



[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

Patch version 3: fix a reference leak in validate_constant().

--
Added file: http://bugs.python.org/file41708/constant-3.patch

___
Python tracker 

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



[issue24923] Append system paths in setup.py instead of prepending

2016-01-25 Thread Chris Hogan

Chris Hogan added the comment:

Zach, 

3.x had the desired behavior.  We didn't have to make any changes.

--

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Jeremy Kloth

Jeremy Kloth added the comment:

Added review

--
nosy: +jkloth

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could you please provide any microbencmarks that show the benefit of this 
optimization?

--

___
Python tracker 

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



[issue24923] Append system paths in setup.py instead of prepending

2016-01-25 Thread Zachary Ware

Zachary Ware added the comment:

In that case, does this patch do what you want it to do?

--
stage:  -> patch review
Added file: http://bugs.python.org/file41710/issue24923.diff

___
Python tracker 

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



[issue25783] test_traceback.test_walk_stack() fails when run directly (without regrtest)

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

@Robert: Can you please take a look at the attached patch? Does it look good to 
you?

--

___
Python tracker 

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



[issue26198] PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError

2016-01-25 Thread Barun Parruck

Barun Parruck added the comment:

Added a patch that changes the documentation to reflect TypeError instead of 
ValueError*

--

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Raymond Hettinger

New submission from Raymond Hettinger:

A number of fine-grained methods in Objects/listobject.c use PyList_Check().  
They include PyList_Size, PyList_GetItem, PyList_SetItem, PyList_Insert, and 
PyList_Append.

The PyList_Check() works by making two sequentially dependent memory fetches:

movq8(%rdi), %rax
testb   $2, 171(%rax)
je  L1645

This patch proposes a fast path for the common case of an exact match, using 
PyList_CheckExact() as an early-out before the PyList_Check() test:

leaq_PyList_Type(%rip), %rdx # parallelizable
movq8(%rdi), %rax# only 1 memory access
cmpq%rdx, %rax   # macro-fusion  
je  L1604# early-out
testb   $2, 171(%rax)# fallback to 2nd memory access
je  L1604

This technique won't help outside of Objects/listobject.c because the initial 
LEA instruction becomes a MOV for the global offset table, nullifying the 
advantage.

--
assignee: serhiy.storchaka
components: Interpreter Core
files: list_check_fastpath.diff
keywords: patch
messages: 258918
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Faster type checking in listobject.c
type: performance
versions: Python 3.6
Added file: http://bugs.python.org/file41713/list_check_fastpath.diff

___
Python tracker 

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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Ivan Pozdeev

Ivan Pozdeev added the comment:

@eryksun tried that already, same effect:

C:\>start /b /w python -c "print 'bla-bla-bl
a'; raise SystemExit(42)"

C:\>bla-bla-bla
echo %errorlevel%
0

I'll try to pinpoint the issue to an OS/OS family/update or Python version.

--

___
Python tracker 

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



[issue26199] fix broken link to hamcrest.library.integration.match_equality in unittest.mock "getting started" documentation

2016-01-25 Thread Raphael Das Gupta

Changes by Raphael Das Gupta :


--
keywords: +patch
Added file: http://bugs.python.org/file41709/0d413f60cc23.diff

___
Python tracker 

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



[issue24923] Append system paths in setup.py instead of prepending

2016-01-25 Thread Chris Hogan

Chris Hogan added the comment:

I should be able to try it out today or tomorrow.  I'll let you know.

--

___
Python tracker 

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



[issue26198] PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError

2016-01-25 Thread Hrvoje Nikšić

New submission from Hrvoje Nikšić:

The documentation for the "es#" format (and the "et#" that derives from it) 
documents the possibility of providing an already allocated buffer. Buffer 
overflow is detected and handled as follows: "If the buffer is not large 
enough, a ValueError will be set."

However, the actual behavior is to raise a TypeError. Inspecting the code in 
getargs.c reveals that convertsimple() handles buffer overflow by returning a 
formatted message to its caller, convertitem(). Calls to convertitem() that 
return an error call seterror() to set the error, and seterror() 
unconditionally sets the PyExc_TypeError.

This is not a big issue in practice, and since the behavior is not new, it 
might be best to simply update the documentation to match the existing practice 
instead of changing the behavior and risking breaking working code.

--
assignee: docs@python
components: Documentation, Interpreter Core
messages: 258905
nosy: docs@python, hniksic
priority: normal
severity: normal
status: open
title: PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising 
TypeError instead of ValueError
type: behavior
versions: Python 2.7, Python 3.5

___
Python tracker 

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



[issue26196] Argparse breaks when a switch is given an argument beginning with a dash

2016-01-25 Thread Eric V. Smith

Eric V. Smith added the comment:

I believe this is a duplicate of issue 9334. There's a lot of discussion there.

--
nosy: +eric.smith
stage:  -> resolved
status: open -> closed
superseder:  -> argparse does not accept options taking arguments beginning 
with dash (regression from optparse)

___
Python tracker 

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



[issue26198] PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError

2016-01-25 Thread Hrvoje Nikšić

Hrvoje Nikšić added the comment:

The problem can be encountered and easily reproduced by calling os.path 
functions, such as os.path.abspath, with a sufficiently large string on Windows:

>>> os.path.abspath("a" * 1024)
Traceback (most recent call last):
  File "", line 1, in 
  File "P:\...\lib\ntpath.py", line 471, in abspath
TypeError: must be (buffer overflow), not str

The error message is somewhat confusing, making it look like the "must be" and 
"not" arguments are swapped. Ideally, the message could be along the lines of 
"must be a string of no more than X characters".

--

___
Python tracker 

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



[issue26199] fix broken link to hamcrest.library.integration.match_equality in unittest.mock "getting started" documentation

2016-01-25 Thread Raphael Das Gupta

Raphael Das Gupta added the comment:

0d413f60cc23.diff generated with the 'Create Patch' button of this bug tracker 
is crap. (I guess it's a diff of upstream's tip to my repo's tip, thus 
reverting all changes of upstream that this daggy fix isn't based on.)

Use fix-broken-link-to-pyhamcrest-match_equality.diff instead. (Created with hg 
export.)

--
Added file: 
http://bugs.python.org/file41711/fix-broken-link-to-pyhamcrest-match_equality.diff

___
Python tracker 

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



[issue26199] fix broken link to hamcrest.library.integration.match_equality in unittest.mock "getting started" documentation

2016-01-25 Thread Raphael Das Gupta

New submission from Raphael Das Gupta:

On

* 
https://docs.python.org/3.3/library/unittest.mock-examples.html#more-complex-argument-matching
* 
https://docs.python.org/3.4/library/unittest.mock-examples.html#more-complex-argument-matching
* 
https://docs.python.org/3.5/library/unittest.mock-examples.html#more-complex-argument-matching
* 
https://docs.python.org/3.6/library/unittest.mock-examples.html#more-complex-argument-matching

the link to hamcrest.library.integration.match_equality documentation at the 
very end of the page is broken.

(Earlier versions didn't have this documentation page.)

--
assignee: docs@python
components: Documentation
hgrepos: 332
messages: 258906
nosy: das-g, docs@python
priority: normal
severity: normal
status: open
title: fix broken link to hamcrest.library.integration.match_equality in 
unittest.mock "getting started" documentation
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Ivan Pozdeev

Ivan Pozdeev added the comment:

@eryksun That's it! "python" was actually launching a shortcut in my "shortcuts 
to often-used commands around the system" folder!

Thank goodness (this time, "Goodness" is Brian Curtin with 90617:a9d34685ec47, 
Sat May 10 12:52:59 2014 -0500 (so tell him he can add this to the list of his 
nicknames ;) )), the installer now has an option to add the EXEs to PATH, 
making this hack unneeded.

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



[issue26200] SETREF adds unnecessary work in some cases

2016-01-25 Thread Raymond Hettinger

New submission from Raymond Hettinger:

Application of the SETREF macro was not code neutral in a number of cases.  The 
SETREF macro always uses Py_XDECREF where the original code correctly used a 
faster and lighter Py_DECREF.

There should be an XSETREF variant and more care should be taken when applying 
these macros wholesale to the entire code base.

--
assignee: serhiy.storchaka
components: Interpreter Core
messages: 258913
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: SETREF adds unnecessary work in some cases
type: performance
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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Eryk Sun

Eryk Sun added the comment:

That the wait failed to get the 42 exit code means that the "python" command 
(which may not actually be python.exe) is spawning a child process to run the 
command and not waiting for it to exit. Please try the following using the 
absolute path to python.exe:

C:\>start "title" /b /w "PATH\TO\python.exe" -c "raise SystemExit(42)"
C:\>echo %errorlevel%
42

In this case "title" is required because cmd parses the first quoted string 
prior to the executable as the title. Without "title" it would parse the path 
to python.exe as the title and try to execute "-c".

--

___
Python tracker 

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



[issue26198] PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError

2016-01-25 Thread Barun Parruck

Barun Parruck added the comment:

I just changed the ValueError to TypeError. This is my first attempt at fixing 
anything, so let me know if I've screwed up anywhere.

--
keywords: +patch
nosy: +Barun Parruck
Added file: http://bugs.python.org/file41712/typeerror.patch

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Returning the same range() object from copy.copy() is correct. This is shallow 
copying.

--

___
Python tracker 

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



[issue25833] pyvenv: venvs cannot be moved because activate scripts hard-code paths

2016-01-25 Thread André Caron

Changes by André Caron :


--
nosy: +André Caron

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Jeremy, thanks for the keen eyes.  Attaching a revised patch.

Serhiy, pure python code doesn't directly access any of the C-API functions 
touched by the patch, so timeit-style examples aren't possible.  The 
beneficiaries of the change are external modules.  I suppose we could write a 
small C extension just to time this but that seems like overkill.

It is a general purpose optimization technique to reduce the number of memory 
accesses in fine-grained functions.  That technique has worked well elsewhere 
in the core where measurable progress was made in many small steps that were 
individually hard to measure.

--
assignee: serhiy.storchaka -> rhettinger
Added file: http://bugs.python.org/file41715/list_check_fastpath2.diff

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread Ethan Furman

Ethan Furman added the comment:

I don't have much experience with the copy module, but I don't see any problems 
with the code.

Does copy.copy suffer from the same problem?  If yes, is it fixed with this 
same patch, or is more work needed?

--
nosy: +ethan.furman

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread Ethan Furman

Ethan Furman added the comment:

Victor, patch was already attached.  ;)

--

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

The range() object is immutable, but is not atomic, and copy.deepcopy() 
shouldn't return it unchanged.

>>> class I(int): pass  # mutable index
... 
>>> import copy
>>> r = range(I(10))
>>> r2 = copy.deepcopy(r)
>>> r.stop.attr = 'spam'
>>> r2.stop.attr
'spam'

This is Python 3 only issue because in 2.7 the xrange() object doesn't exposes 
start/stop/step attributes.

Proposed patch fixes the copy module.

--
components: Library (Lib)
files: deepcopy_range.patch
keywords: patch
messages: 258921
nosy: alexandre.vassalotti, fdrake, haypo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: The range() object is deepcopied as atomic
type: behavior
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41714/deepcopy_range.patch

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

Hum ok, it's a bug :-) It should be fixed. Do you want to work on a patch?

--

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

> Could you please provide any microbencmarks that show the benefit of this 
> optimization?

Yeah, analyzing the assembler seems overkill to me. I'm not sure that it really 
make the code faster (but it makes the code more complex).

--
nosy: +haypo

___
Python tracker 

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



[issue26202] The range() object is deepcopied as atomic

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

deepcopy_range.patch looks good to me.

--

___
Python tracker 

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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Eryk Sun

Eryk Sun added the comment:

By shortcut I'm guessing you mean a batch file. A regular .LNK shortcut works 
fine if .LNK is in PATHEXT. I sometimes use a shortcut when I need to set the 
default to "Run as administrator". (I add a "runas" verb to the ProgIds to add 
this option to the menu for .PY, .PYZ, .PYW, and .PYWZ files, but the shell 
doesn't allow setting the default in the advanced properties like with a 
shortcut.)

An alternative to adding Python to PATH is to use the py launcher and virtual 
environments. This is especially useful when you have multiple versions 
installed.

--
stage:  -> resolved

___
Python tracker 

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



[issue26203] nesting venv in virtualenv segfaults

2016-01-25 Thread Florian Bruhin

Changes by Florian Bruhin :


--
nosy: +The Compiler, dstufft, vinay.sajip

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Writing your own static optimizer from scratch is overkill.  Following basic 
techniques from the Agner Fog manuals and Intel optimization manuals is quite 
reasonable in comparison.

Unless you see an actual defect in the patch, I'm applying it.

--

___
Python tracker 

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



[issue26183] 2.7.11 won't clean install on Windows 10 x64

2016-01-25 Thread Roger Cook

Roger Cook added the comment:

Installing a VM and running it there, it installs.

Is there a manual removal procedure to follow when the automated uninstall 
fails?

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



[issue26189] Interpreter returns control to cmd.exe early

2016-01-25 Thread Ivan Pozdeev

Ivan Pozdeev added the comment:

@eryksun That is (was) an .lnk indeed, and adding ".lnk" to PATHEXT is exactly 
what I did to make it work. This is much more maintainable than registry hacks.

An .lnk is launched with ShellExecute which returns control immediately upon 
successful launch (see 
http://stackoverflow.com/questions/31855240/execute-exe-as-jpg/31861241#31861241
 for how this happens from `cmd' prompt).

--

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

> As noted above, it not reasonable for a C-API that isn't used internally 
> because there is no reasonable way to measure the effect without writing a C 
> extension.

Come on, there is a lot of C functions in Python using the C PyList_xxx() API. 
It's easy to write a benchmark on it in pure Python. Example.


Without the patch (best of 10 runs):

$ for i in $(seq 1 10); do ./python -m timeit -s 's="a " * 10**5' 's.split()'; 
done
1000 loops, best of 3: 1.40 msec per loop

With the patch (best of 10 runs):

$ for i in $(seq 1 10); do ./python -m timeit -s 's="a " * 10**5' 's.split()'; 
done
1000 loops, best of 3: 1.49 msec per loop

It looks like list_check_fastpath2.diff makes PyList_Append() *slower* (6%) in 
practice. I expected it to be *faster*.


Please try to reproduce my microbenchmark, timeit is not really reliable, and I 
hate microbenchmarks, it's easy to make mistakes :-/

Note: It looks like s.split() creates a list of 'a' strings where all 'a' 
strings are the same singleton. So I don't think that creating substrings has 
an important cost.


> If you're going to be in the optimization business, I really wish you would 
> read some of the basics in the field so that each and every technique doesn't 
> have to be re-proved to you each time it used.

It's easy to convince me: show me a benchmark where your patch makes the code 
faster :-) I don't think that there is a strict rule for a miniumum speedup in 
CPython. I'm open for discussion :-)

--

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +pitrou, yselivanov

___
Python tracker 

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



[issue26203] nesting venv in virtualenv segfaults

2016-01-25 Thread Vinay Sajip

Vinay Sajip added the comment:

By design, the stdlib venv functionality expects to work from an installed 
Python. However, the Python in a virtualenv venv is not an installed Python - 
it copies some files from the Python it was installed from and does various 
other hacks in order to work (I'm not using 'hack' as a pejorative here - it's 
just what virtualenv has to do).

Thus, you cannot use venv to create an environment from a virtualenv venv's 
Python. For this to work seamlessly, there would probably need to be coupling 
between  venv and virtualenv - virtualenv has potentially to be updated with 
additional hacks every time there is a new Python release, in order to keep 
working.

It doesn't make sense to couple the stdlib closely with a third-party package. 
Does it work the other way around? I realise this doesn't help you with tox, 
and of course tox has to use virtualenv because of supporting older versions of 
Python ...

--
nosy: +carljm
resolution:  -> not a bug

___
Python tracker 

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



[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-25 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 27e5437f442c by Victor Stinner in branch 'default':
Add ast.Constant
https://hg.python.org/cpython/rev/27e5437f442c

--

___
Python tracker 

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



[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

I pushed an enhanced version of constant-3.patch:

* fix the compiler: don't emit LOAD_CONST for ast.Constant if the value is a 
string (str) or a number (int, float, complex), as done previously for ast.Str 
and ast.Num

* add unit tests on: the compiler (ensure that LOAD_CONST is emitted for 
constants), ast.get_docstring() and ast.literal_eval()

--
components: +Interpreter Core
resolution:  -> fixed
status: open -> closed

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> Well, Serhiy Storchaka asked for a microbenchmark. 
> For an optimization, it's a reasonable request no?

As noted above, it not reasonable for a C-API that isn't used internally 
because there is no reasonable way to measure the effect without writing a C 
extension.

FWIW, I look at assembly to see direct evidence for the effect of a change.  It 
makes it easy to see how many memory accesses happen on a given path.

If you're going to be in the optimization business, I really wish you would 
read some of the basics in the field so that each and every technique doesn't 
have to be re-proved to you each time it used.  Here's a short-list I put 
together for those who were interested : 
https://dl.dropboxusercontent.com/u/3967849/sftalk/_build/html/misc.html#optimization-resources

--

___
Python tracker 

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



[issue26204] compiler: don't emit LOAD_CONST instructions for constant expressions?

2016-01-25 Thread STINNER Victor

New submission from STINNER Victor:

The bytecode compilers ignores ast.Str and ast.Num nodes:


>>> def func():
... 123
... "test"
... 
>>> import dis; dis.dis(func)
  3   0 LOAD_CONST   0 (None)
  3 RETURN_VALUE


But other ast nodes which are constant are not ignored:


>>> def func2():
... b'bytes'
... (1, 2)
... 
>>> import dis; dis.dis(func2)
  2   0 LOAD_CONST   1 (b'bytes')
  3 POP_TOP

  3   4 LOAD_CONST   4 ((1, 2))
  7 POP_TOP
  8 LOAD_CONST   0 (None)
 11 RETURN_VALUE


I don't understand the point of loading a constant and then unload it (POP_TOP).


Attached patch changes the compiler to not emit LOAD_CONST+POP_TOP anymore.


My patch only affects constants. Example with the patch:

>>> def f():
...  x
... 
>>> import dis
>>> dis.dis(f)
  2   0 LOAD_GLOBAL  0 (x)
  3 POP_TOP
  4 LOAD_CONST   0 (None)
  7 RETURN_VALUE


The compiler still emits "LOAD_GLOBAL x" for the instruction "x".

Ignoring the Python instruction "x" would change the Python semantics, because 
the function would not raise a NameError anymore if x is not defined.

Note: I noticed this inefficient bytecode while working on the issue #26146 
(add ast.Constant).

--
components: Interpreter Core
files: compiler.patch
keywords: patch
messages: 258939
nosy: haypo, yselivanov
priority: normal
severity: normal
status: open
title: compiler: don't emit LOAD_CONST instructions for constant expressions?
versions: Python 3.6
Added file: http://bugs.python.org/file41716/compiler.patch

___
Python tracker 

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



[issue26204] compiler: don't emit LOAD_CONST instructions for constant statements?

2016-01-25 Thread STINNER Victor

Changes by STINNER Victor :


--
title: compiler: don't emit LOAD_CONST instructions for constant expressions? 
-> compiler: don't emit LOAD_CONST instructions for constant statements?

___
Python tracker 

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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread STINNER Victor

STINNER Victor added the comment:

> Unless you see an actual defect in the patch, I'm applying it.

Well, Serhiy Storchaka asked for a microbenchmark. For an optimization, it's a 
reasonable request no?


> Writing your own static optimizer from scratch is overkill.

My goal is to get speedup on macro benchmarks.

It's hard to get a real speedup on macro benchmark using micro-optimizations, 
even if we combine a lot of them. I'm not saying that micro optimization is a 
waste of time, I like micro-optimizing Python, but we should not abuse of it.

--

___
Python tracker 

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



[issue26140] inspect.iscoroutinefunction raises TypeError when checks Mock of function or coroutinefunction

2016-01-25 Thread Michael Foord

Changes by Michael Foord :


--
nosy:  -gvanrossum

___
Python tracker 

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



[issue26196] Argparse breaks when a switch is given an argument beginning with a dash

2016-01-25 Thread Charles Daffern

New submission from Charles Daffern:

Example code demonstrating the problem:

# {{{
import argparse

def try_args(*args):
parser = argparse.ArgumentParser()
parser.add_argument("-a")
print("Trying:", args)
try:
print(parser.parse_args(args))
except SystemExit:
print("FAILED!")

try_args("-a", "-")  # Works fine
try_args("-a", "-a")  # Breaks
try_args("-a", "--")  # Breaks
try_args("-a", "--things--")  # Breaks
# }}}

This behaviour is contrary to optparse:

# {{{
import optparse

def try_args(*args):
parser = optparse.OptionParser()
parser.add_option("-a")
print("Trying:", args)
try:
print(parser.parse_args(list(args)))
except SystemExit:
print("FAILED!")

try_args("-a", "-")  # Works
try_args("-a", "-a")  # Works
try_args("-a", "--")  # Works
try_args("-a", "--things--")  # Works
# }}}

It is also contrary to many other utilities, including python itself:

# {{{
$ python -c -c
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'c' is not defined
$ printf 'hello\nworld\n-- pick me\netc\n' | grep -e --
-- pick me
$ gawk -f --
gawk: fatal: can't open source file `--' for reading (No such file or directory)
$ vim -u --
E282: Cannot read from "--"
Press ENTER or type command to continue
$ man -M --asdf man
No manual entry for man
$ less -b --sdfkds
Number is required after -b (--buffers)
Missing filename ("less --help" for help)
$ perl -e --fasd
Can't modify constant item in predecrement (--) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
# }}}

I first encountered this problem when using a text scrolling utility someone 
had written in python, and tried to pass "--" as the text separator. The 
program just bailed out, and it turned out that it wasn't the author's fault 
but a problem in argparse itself.

--
components: Library (Lib)
messages: 258897
nosy: Charles Daffern
priority: normal
severity: normal
status: open
title: Argparse breaks when a switch is given an argument beginning with a dash
type: behavior
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



[issue26196] Argparse breaks when a switch is given an argument beginning with a dash

2016-01-25 Thread SilentGhost

SilentGhost added the comment:

If you're to drop the space between the argument and its value, e.g. 
try_args('-a-a'), it seems to work as intended. The third example (
try_args("-a", "--")) still wouldn't work, but it looks like a reasonable 
workaround to me.

--
nosy: +SilentGhost, bethard

___
Python tracker 

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



[issue26205] Inconsistency concerning nested scopes

2016-01-25 Thread Roscoe R.Higgins

New submission from Roscoe R.Higgins:

In chapter 9. Classes of the Python3.5 documentation it says: 

"At any time during execution, there are at least three nested scopes whose 
namespaces are directly accessible:",

followed by a list containing 4 items.
Further down a middle scope is mentioned (although mentioned by name). This was 
confusing for a while.

--
assignee: docs@python
components: Documentation
messages: 258941
nosy: Roscoe R. Higgins, docs@python
priority: normal
severity: normal
status: open
title: Inconsistency concerning nested scopes
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



[issue26201] Faster type checking in listobject.c

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I've lost interest in talking with you.  AFAICT you aren't doing anything to 
help advance or study the patch.  You're just being a PITA and are now 
enlisting people to gang-up on a trivial patch.  This is disgusting.

--
status: open -> closed

___
Python tracker 

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



[issue26194] Undefined behavior for deque.insert() when len(d) == maxlen

2016-01-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Mark, Serhiy and Timmy, do you have any thoughts on what is the right behavior?

One option is to always pop the rightmost element to make room, but that 
results in a weird asymmetry between d.insert(len(d), item) and what 
d.append(item) would do.  I can't seem to come with a coherent set of 
invariants that doesn't have a surprising discontinuity.

Another option is to "refuse the temptation to guess" at what the user intends 
for the popped-off element to be and to raise an exception.  But that isn't 
very user friendly either.

--
nosy: +mark.dickinson, serhiy.storchaka, tim.peters

___
Python tracker 

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



[issue23794] http package should support HTTP/2

2016-01-25 Thread Fantix King

Changes by Fantix King :


--
nosy: +Fantix King

___
Python tracker 

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