[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset bfc7dff63b9b30371e3423a5c35ccda2f3b52218 by Serhiy Storchaka in 
branch '2.7':
[2.7] bpo-15718: Document the upper bound constrain on the __len__ return 
value. (GH-1256). (#1261)
https://github.com/python/cpython/commit/bfc7dff63b9b30371e3423a5c35ccda2f3b52218


--

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset c358536fd5e40e8f29ee4f086588a82fccb25a09 by Serhiy Storchaka in 
branch '3.5':
[3.5] bpo-15718: Document the upper bound constrain on the __len__ return 
value. (GH-1256) (#1260)
https://github.com/python/cpython/commit/c358536fd5e40e8f29ee4f086588a82fccb25a09


--

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset f2ed2858eea7569c8915b3611ca5ec92ae10b17f by Serhiy Storchaka in 
branch '3.6':
[3.6] bpo-15718: Document the upper bound constrain on the __len__ return 
value. (GH-1256) (#1259)
https://github.com/python/cpython/commit/f2ed2858eea7569c8915b3611ca5ec92ae10b17f


--

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1374

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1373

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1372

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset 85157cd89a6edac347a5b6871fcf20c500c6fbbf by Serhiy Storchaka in 
branch 'master':
bpo-15718: Document the upper bound constrain on the __len__ return value. 
(#1256)
https://github.com/python/cpython/commit/85157cd89a6edac347a5b6871fcf20c500c6fbbf


--

___
Python tracker 

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



[issue9285] Add a profile decorator to profile and cProfile

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

Giampaolo, the assertion is still worked good, and no need to remove them. The 
assertion is to prevent dispatch return too more, to return upper then when the 
profiler was created.

The problem why profile __enter__ can't work, is because it misses the 
simulate_call between __enter__ and upper frame.

The original scenes:

pr = profile.Profile()  # It will call simulate_call at the end of init
sys.setprofile(pr.dispatcher)
# profile
sys.setprofile(None)

The break scenes:

def profile_helper(pr):
sys.setprofile(pr.dispatcher)
# Function will return None, dead here

pr = profile.Profile()  # Create simulate_call
# We go into profile_helper, but didn't simulate a call!! (didn't setprofile 
yet)
profile_helper(pr)  
sys.setprofile(None)

The #30113 issue fix this:

def profile_helper(pr):
pr._adjust_frame()  # call simuate_call here
sys.setprofile(pr.dispatcher)

pr = profile.Profile()  # Create simulate_call
profile_helper(pr)  
sys.setprofile(None)

Creating this simuate_call, then profiler can go back to the upper frame 
without error.

--

___
Python tracker 

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



[issue30140] Binary arithmetic does not always call subclasses first

2017-04-22 Thread Stephan Hoyer

New submission from Stephan Hoyer:

We are writing a system for overloading NumPy operations (see PR [1] and design 
doc [2]) that is designed to copy and extend Python's system for overloading 
binary operators.

The reference documentation on binary arithmetic [3] states:

> Note: If the right operand's type is a subclass of the left operand’s type 
> and that subclass provides the reflected method for the operation, this 
> method will be called before the left operand’s non-reflected method. This 
> behavior allows subclasses to override their ancestors’ operations.

However, this isn't actually done if the right operand merely inherits from the 
left operand's type. In practice, CPython requires that the right operand 
defines a different method before it defers to it. Note that the behavior is 
different for comparisons, which defer to subclasses regardless of whether they 
implement a new method [4].

I think this behavior is a mistake and should be corrected. It is just as 
useful to write generic binary arithmetic methods that are well defined on 
subclasses as generic comparison operations. In fact, this is exactly the 
design pattern we propose for objects implementing special operators like NumPy 
arrays (see NDArrayOperatorsMixin in [1] and [2]).

Here is a simple example, of a well-behaved that implements addition by 
wrapping its value and returns NotImplemented when the other operand has the 
wrong type:

class A:
   def __init__(self, value):
   self.value = value
   def __add__(self, other):
   if not isinstance(other, A):
   return NotImplemented
   return type(self)(self.value + other.value)
   __radd__ = __add__
   def __repr__(self):
   return f'{type(self).__name__}({self.value!r})'

class B(A):
pass

class C(A):
   def __add__(self, other):
   if not isinstance(other, A):
   return NotImplemented
   return type(self)(self.value + other.value)
   __radd__ = __add__

A does not defer to B:

>>> A(1) + B(1)
A(2)

But it does defer to C, which defines new methods (literally copied/pasted) for 
__add__/__radd__:

>>> A(1) + C(1)
C(2)

With the current behavior, special operator implementations need to explicitly 
account for the possibility that they are being called from a subclass by 
returning NotImplemented. My guess is that this is rarely done, which means 
that most of these methods are broken when used with subclasses, or subclasses 
needlessly reimplement these methods.

Can we fix this logic for Python 3.7?

[1] https://github.com/numpy/numpy/pull/8247
[2] 
https://github.com/charris/numpy/blob/406bbc652424fff332f49b0d2f2e5aedd8191d33/doc/neps/ufunc-overrides.rst
[3] https://docs.python.org/3/reference/datamodel.html#object.__ror__
[4] http://bugs.python.org/issue22052

--
messages: 292149
nosy: Stephan Hoyer
priority: normal
severity: normal
status: open
title: Binary arithmetic does not always call subclasses first
type: behavior

___
Python tracker 

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



[issue9285] Add a profile decorator to profile and cProfile

2017-04-22 Thread Giampaolo Rodola'

Giampaolo Rodola' added the comment:

Original patch still applies. Not sure if we should continue with that one or 
with your new PR. The original assertion error is still there. I CCed Tim 
Peters as it appears he's the one who originally added it in 2001 - maybe he 
has some clue.

--
versions: +Python 3.7 -Python 3.4

___
Python tracker 

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



[issue23420] python -m cProfile -s fails with non informative message

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

If we can solve #30118 for argument unittest, and apply #18971 for optparse to 
argparse, this issue will then can be solve, too.

--
nosy: +louielu

___
Python tracker 

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



[issue29237] Create enum for pstats sorting options

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

Mariatta, is there any movement on this issue?

Thanks!

--
nosy: +louielu

___
Python tracker 

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



[issue30134] BytesWarning is missing from the documents

2017-04-22 Thread Martin Panter

Martin Panter added the comment:

.
Issue 11681 is already open for the -b option, with a patch in progress.

If updating the doc string, also change “buffer” to “bytearray”. This is what 
“bytearray” was originally called in Python 3, and “buffer” is something 
different in Python 2.

--
nosy: +martin.panter

___
Python tracker 

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



[issue23404] 'make touch' does not work with git clones of the source repository

2017-04-22 Thread Martin Panter

Martin Panter added the comment:

Do you mean a separate makefile rule to rebuild the generated files, rather 
than rebuilding them in a normal “make all” build? I would support this; this 
is what I meant with my “make regenerate” proposal in response to Nick linked 
above.

--

___
Python tracker 

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



[issue29619] st_ino (unsigned long long) is casted to long long in posixmodule.c:_pystat_fromstructstat

2017-04-22 Thread STINNER Victor

STINNER Victor added the comment:

Would it work with unsigned long long?

What is the value of HAVE_LARGEFILE_SUPPORT?

Maybe the code should be simplified to always use unsigned long long.

--

___
Python tracker 

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



[issue29619] st_ino (unsigned long long) is casted to long long in posixmodule.c:_pystat_fromstructstat

2017-04-22 Thread Xavier de Gaye

Xavier de Gaye added the comment:

The compilation of Modules/posixmodule.c fails now on Android architecture 
'x86' at api level 21, after the above change 
0f6d73343d342c106cda2219ebb8a6f0c4bd9b3c:

/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
--sysroot=/opt/android-ndk/platforms/android-21/arch-x86 -target 
i686-none-linux-androideabi -gcc-toolchain 
/opt/android-ndk/toolchains/x86-4.9/prebuilt/linux-x86_64 -Wno-unused-result 
-Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall 
-Wstrict-prototypes -fno-strict-aliasing -Wno-unused-value -Wno-empty-body 
-Qunused-arguments -Wno-parentheses-equality   -std=c99 -Wextra 
-Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers 
-Werror=implicit-function-declaration  -IObjects -IInclude -IPython -I. 
-I./Include -I/opt/android-ndk/platforms/android-21/arch-x86/usr/include   
-DPy_BUILD_CORE  -c ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c:1935:5: error: array size is negative
Py_BUILD_ASSERT(sizeof(unsigned long) >= sizeof(st->st_ino));
^~~~
./Include/pymacro.h:43:15: note: expanded from macro 'Py_BUILD_ASSERT'
(void)Py_BUILD_ASSERT_EXPR(cond);   \
  ^~
./Include/pymacro.h:40:19: note: expanded from macro 'Py_BUILD_ASSERT_EXPR'
(sizeof(char [1 - 2*!(cond)]) - 1)
  ^
1 error generated.
make: *** [Makefile:1720: Modules/posixmodule.o] Error 1

The following code:
  #include 
  #include 

  int main()
  {
  struct stat *st;

  printf("sizeof(unsigned long): %d - sizeof(st->st_ino): %d\n",
 sizeof(unsigned long), sizeof(st->st_ino));
  return 0;
  }
prints the following result on this same system:
  sizeof(unsigned long): 4 - sizeof(st->st_ino): 8

--
nosy: +xdegaye

___
Python tracker 

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



[issue29840] Avoid raising OverflowError in bool()

2017-04-22 Thread STINNER Victor

STINNER Victor added the comment:

If someone wants to return a value larger than maxsize and support bool():
it is already possible right now by defining a __bool__ method no? If yes,
I suggest to only document this CPython implementation detail (consequence
of slots, for efficiency) and suggest to use __bool__ for such corner case.

I also dislike retrying to call "__len__" method instead of the slot. It
can have annoying side effects.

--

___
Python tracker 

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



[issue29782] Use __builtin_clzl for bits_in_digit if available

2017-04-22 Thread STINNER Victor

STINNER Victor added the comment:

I'm in favor of documenting in comments decisions to not micro-optimize
such code. I did something similar in ceval.c for 1+1.

--

___
Python tracker 

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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread Ned Deily

Ned Deily added the comment:

> But there is no neither an entry #8743, nor neighbour entries #14710 and 
> #13355 in Misc/NEWS. Seems Misc/NEWS is broken.

Hmm. They seem to have been properly preserved in the current 3.6 and master 
branch versions of Misc/HISTORY.  Perhaps the 3.5 Misc/NEWS was corrupted in a 
merge along the way?  In any case, this is not relevant to the OP's problem.  
Once the auto-generation of Misc/NEWS is implemented, we're going to have to go 
back and redo Misc/NEWS and Misc/HISTORY in active branches.  I don't think 
there is a need for a separate issue to track that but, if you want to open 
one, Serhiy, feel free to do so.

--

___
Python tracker 

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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> works for me
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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

But there is no neither an entry #8743, nor neighbour entries #14710 and #13355 
in Misc/NEWS. Seems Misc/NEWS is broken.

--
nosy: +serhiy.storchaka
resolution: works for me -> 
stage: resolved -> 
status: closed -> open

___
Python tracker 

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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread Ned Deily

Ned Deily added the comment:

>> Then you have a broken copy of 3.5.1.

Yes. You don't say from where you installed Python 3.5.1 but I just took a 
quick look at _collections_abc.py in both the versions installed by the 
python.org 3.5.1 macOS installer and by the current 3.5.3 version (which you 
should update to, or, better, 3.6.1) and the Issue8743 changes appear to be 
there.  If you still believe there is a problem with Python here, please reopen 
and provide a complete test case.

--
resolution:  -> works for me
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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread R. David Murray

R. David Murray added the comment:

Then you have a broken copy of 3.5.1.  There is nothing OS-specific about that 
file.

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



[issue30139] Fix for issue 8743 not available in python MacOS 3.5.1

2017-04-22 Thread Horacio Hoyos

New submission from Horacio Hoyos:

Hi all,

I was having issues while testing a custom Set implementation using the 
_collections_abc base MutableSet and found that my issue was apparently 
resolved with issue 8743. My test is simple:

ms = MySetImpl()
ms & 'testword'

which should fail with TypeError, given that in the 8743 fix the __and__ 
incorporated a test for isinstance(other, Set).

Looking at the _collections_abc.py in my installation 
(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_collections_abc.py)
 I can not see the changes in the patches submitted for issue 8743.

--
components: Library (Lib), macOS
messages: 292134
nosy: Horacio Hoyos, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: Fix for issue 8743 not available in python MacOS 3.5.1
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



[issue29816] Get rid of C limitation for shift count in right shift

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset 997a4adea606069e01beac6269920709db3994d1 by Serhiy Storchaka in 
branch 'master':
Remove outdated note about constraining of the bit shift right operand. (#1258)
https://github.com/python/cpython/commit/997a4adea606069e01beac6269920709db3994d1


--

___
Python tracker 

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



[issue30137] Equivalent syntax regarding List returns List objects with non-similar list elements.

2017-04-22 Thread Steven D'Aprano

Steven D'Aprano added the comment:

The behaviour is as documented and is not a bug. When you have a three-argument 
extended slice, the starting and stopping values depend on whether the stride 
(step) is positive or negative. Although that's buried in a footnote to the 
table.

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

The current behaviour is necessary so that the common case of both start and 
stop being blank is supported correctly for negative stride:

py> "abcde"[::-1]
'edcba'


So with a positive stride, your first example lst[0:3:-1] starts at index 0, 
ends at index 3, with step -1. That is an empty slice.

But your second example lst[:3:-1] starts at the end of the list, index 
len(lst), ends at 3, with step -1. That is equivalent to lst[5:3:-1] which is 
not the same as your first example.

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue29352] provide the authorative source for s[i:j] negative slice indices (<-len(s)) behavior for standard sequences

2017-04-22 Thread Stephen J. Turnbull

Stephen J. Turnbull added the comment:

I prefer Josh's wording.  The important point to me is that

>>> [1, 2][2:0] = "AB"
[1, 2, "A", "B"]

not an error or ["B", "A"] == [1, 2][2:0:-1].  I think too much talk about the 
endpoints obscures this important fact.  (I think I'd like it to be an error, 
since the interpretation of s[2:0] = t could reasonably be any of s[0:0] = t, 
s[1:1] = t, or s[2:2] = t, but I haven't thought carefully enough yet, and 
"backward compatibility".)

Note: Josh's wording is already used in 3.7 
(https://docs.python.org/dev/library/stdtypes.html#common-sequence-operations, 
as of the timestamp of this message).  I didn't check if it's been backported.

--
nosy: +sjt

___
Python tracker 

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



[issue26143] Ensure that IDLE's stdlib imports are from the stdlib

2017-04-22 Thread Matthew Cowles

Matthew Cowles added the comment:

This bug should be fixed urgently. Over at python-help we just got another 
Python beginner who was using IDLE and then started to get the "IDLE's 
subprocess didn't make connection" error. The problem was that the user had 
named one of their programs random.py. That's a bad introduction to Python and 
programming.

--
nosy: +mdcowles

___
Python tracker 

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



[issue29816] Get rid of C limitation for shift count in right shift

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1371

___
Python tracker 

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



[issue30135] default value of argument seems to be overwritten

2017-04-22 Thread Steven D'Aprano

Steven D'Aprano added the comment:

In the future please don't post binary files containing source code, especially 
something as non-standard as 7z. That just makes it difficult for people to 
review the code. Either paste your code snippet directly into the bug report, 
or attach it as a .py file.

If the file is so huge it needs compression, you shouldn't be posting it at 
all. You should post the *minimum* code to demonstrate the problem, not an 
entire application: we don't a 200 line simulation of a Forth interpreter just 
to see something that can be shown in ten lines. Even though this is written 
for Java programmers, the same applies here: http://sscce.org/


Thank you.

--
nosy: +steven.daprano

___
Python tracker 

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



[issue30138] Incorrect documentation of replacement of slice of length 0

2017-04-22 Thread Stephen J. Turnbull

Stephen J. Turnbull added the comment:

Sorry, I just realized this note only applies to slices with a stride (k in 
i:j:k).  Closing.

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



[issue30138] Incorrect documentation of replacement of slice of length 0

2017-04-22 Thread Stephen J. Turnbull

New submission from Stephen J. Turnbull:

In section 4.6.3. "Mutable Sequence Types" of current documentation, Note 1 to 
the table says "[iterable] t must have the same length as the slice it is 
replacing." This is incorrect in the case of extension: s[len(s):] = t 
according to the rest of the documentation, as well as experiment.

--
assignee: docs@python
components: Documentation
keywords: easy
messages: 292127
nosy: docs@python, sjt
priority: normal
severity: normal
status: open
title: Incorrect documentation of replacement of slice of length 0
type: behavior
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



[issue23404] 'make touch' does not work with git clones of the source repository

2017-04-22 Thread Brett Cannon

Brett Cannon added the comment:

Would it make sense to have a `make rebuild` or something which explicitly 
ignores prebuilt files? That could then also serve as non-obvious documentation 
on how to build those files in the first place.

--
nosy: +ncoghlan

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Yes, and the range object already is fixed by issue28876.

--

___
Python tracker 

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



[issue27613] Empty iterator with fake __len__ is rendered as a single bracket ] when using json's iterencode

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1370

___
Python tracker 

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



[issue27613] Empty iterator with fake __len__ is rendered as a single bracket ] when using json's iterencode

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> I am surprised that dumping to a string and to a file give different answers.

This is a difference between Python and C implementations.

An iterable with fake __len__ looks breaking the invariants, but if a 
collection with overridden __bool__() is considered as more legitimate, the 
proposed patch fixes Python implementation of json for that case.

--
components: +Library (Lib)
nosy: +bob.ippolito, ezio.melotti, rhettinger, serhiy.storchaka
stage:  -> patch review
versions: +Python 2.7, 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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Has or will builtin classes be modified to follow advice to include a separate 
__bool__?  In 3.6.1,

>>> r = range(19**100)
>>> bool(r)
Traceback (most recent call last):
  File "", line 1, in 
bool(r)
OverflowError: Python int too large to convert to C ssize_t

--
nosy: +serhiy.storchaka
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



[issue26423] Integer overflow in wrap_lenfunc() on 64-bit build of Windows with len > 2**31-1

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could you create a PR for your patch Victor?

--

___
Python tracker 

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



[issue29840] Avoid raising OverflowError in bool()

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I had similar doubts about this patch and needed opinions of other core 
developers.

> Maybe, if __len__() raises an OverflowError: call again the len(), but using 
> the "__len__" method instead of the slot?

Following patch implements this idea. I don't like it because it is too 
complicated.

I think that we should either document that raising an OverflowError by 
__len__() is normal and interpreted as true in Boolean context, or document 
that __len__() should return a value not larger than sys.maxsize, otherwise 
len() and bool() can raise an OverflowError (see issue15718).

--
Added file: http://bugs.python.org/file46826/bool-no-overflow-double-call.patch

___
Python tracker 

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



[issue15718] Possible OverflowError in __len__ method undocumented (when called via len() function)

2017-04-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +1369

___
Python tracker 

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



[issue30137] Equivalent syntax regarding List returns List objects with non-similar list elements.

2017-04-22 Thread Akshay Deogaonkar

New submission from Akshay Deogaonkar:

lst = [0,1,2,3,4]
print(lst[0:3]) #returns [0,1,2]
print(lst[:3]) #returns [0,1,2]

#Above two syntax returns same lists.

print(lst[0:3:-1]) #returns []
print(lst[:3:-1]) #returns [4]

#Here is a bug; what expected was that the both syntax would have
returned the similar lists; however, they didn't!

--
messages: 292120
nosy: Akshay Deogaonkar
priority: normal
severity: normal
status: open
title: Equivalent syntax regarding List returns List objects with non-similar 
list elements.
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



[issue30024] Treat `import a.b.c as m` as `m = sys.modules['a.b.c']`

2017-04-22 Thread Victor Varvariuc

Victor Varvariuc added the comment:

How can I facilitate/contribute to get the changes suggested by Serhiy into 
Python?

--

___
Python tracker 

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



[issue30135] default value of argument seems to be overwritten

2017-04-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This is correct behavior. You just made a common mistake made by newcomers. 
Read Python FAQ and other resources, this can help you to avoid other pitfalls.

--

___
Python tracker 

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



[issue29442] Replace optparse with argparse in setup.py

2017-04-22 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

I guess you were asking whether the newly compiled Python binary is able to 
build extension modules or not? I rebased PR 139 against the latest git master 
and seems it's fine. Running `make distclean`, `./configure` and then `make` 
builds all modules as expected. The result is the same on Travis CI and 
Appveyor.

About "elegant": I guess the only issue regarding elegancy in my patch is the 
local import in  GNUTranslations._parse(). For me moving setup.py away from 
deprecated modules is a good reason for introducing local imports. Does it 
sound OK?

--

___
Python tracker 

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



[issue18576] Document test.support.script_helper

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

The PR on GitHub is based on bobcatfist's patch, addressed on Martin request 
and some minor change.

--
nosy: +louielu

___
Python tracker 

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



[issue29782] Use __builtin_clzl for bits_in_digit if available

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

If this issue is closed by "not a big performance improvement", maybe the XXX 
in mathmoudle.c should be take off?

"""
/* XXX: This routine does more or less the same thing as
 * bits_in_digit() in Objects/longobject.c.  Someday it would be nice to
 * consolidate them.  On BSD, there's a library function called fls()
 * that we could use, and GCC provides __builtin_clz().
 */
"""

--
nosy: +louielu

___
Python tracker 

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



[issue29782] Use __builtin_clzl for bits_in_digit if available

2017-04-22 Thread Mark Dickinson

Mark Dickinson added the comment:

Closing.

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

___
Python tracker 

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



[issue30135] default value of argument seems to be overwritten

2017-04-22 Thread Klaus Wolf

Klaus Wolf added the comment:

A documented misbheavior is still a misbehavior.

--

___
Python tracker 

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



[issue30113] Allow helper functions to wrap sys.setprofile

2017-04-22 Thread Louie Lu

Changes by Louie Lu :


--
pull_requests: +1368

___
Python tracker 

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



[issue30113] Allow helper functions to wrap sys.setprofile

2017-04-22 Thread Louie Lu

Louie Lu added the comment:

Thanks, Nick. Your analysis is very helpful.


After some testing, I found the problem here is because when we using 
`sys.setprofile` in the helper function, we didn't simulate the call (from 
where profiler create to helper function), that cause profile's frame link 
breakup, so if we want to return to outside of helper function, it will report 
a bad return.

A straightforward method is the latter method you propose, to make a 
profiler-aware function manually insert the frame into profiler's frame stack:

def _adjust_frame(self):
frame = sys._getframe(1)  # Get helper function frame
self.dispatch['call'](self, frame, 0)

And adjust *before* install profiler:

def profile_helper(pr):
pr._adjust_frame()
sys.setprofile(pr.dispatcher)


Then we can get the correct thing we need.

--

___
Python tracker 

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



[issue30024] Treat `import a.b.c as m` as `m = sys.modules['a.b.c']`

2017-04-22 Thread Nick Coghlan

Nick Coghlan added the comment:

Expanding on Serhiy's answer: the ModuleNotFoundError for "import sys.path" 
comes from IMPORT_NAME, not from any of the subsequent attribute lookups.

That difference is visible in the bytecode:

>>> dis("import sys.path as path")
  1   0 LOAD_CONST   0 (0)
  3 LOAD_CONST   1 (None)
  6 IMPORT_NAME  0 (sys.path)
  9 LOAD_ATTR1 (path)
 12 STORE_NAME   1 (path)
 15 LOAD_CONST   1 (None)
 18 RETURN_VALUE

For "import sys.path as path", the given module name is "sys.path", and the 
"from list" entry on the stack is None. This fails before it even reaches the 
`LOAD_ATTR` line, since "sys.path" isn't an importable module. Changing 
LOAD_ATTR to IMPORT_FROM would thus have no effect on its behaviour.

>>> dis("from sys import path")
  1   0 LOAD_CONST   0 (0)
  3 LOAD_CONST   1 (('path',))
  6 IMPORT_NAME  0 (sys)
  9 IMPORT_FROM  1 (path)
 12 STORE_NAME   1 (path)
 15 POP_TOP
 16 LOAD_CONST   2 (None)
 19 RETURN_VALUE

For "from sys import path", the given module name is "sys", and the "from list" 
entry on the stack is a tuple containing the string "path". This works, since 
"sys" is importable *and* it has a "path" attribute.

Hence why Serhiy's suggestion is such an elegant fix, since the only cases 
where the LOAD_ATTR vs IMPORT_FROM distinction matters will be those where:

1. The submodule exists, so both "import a.b" and "from a import b" will work 
for the IMPORT_NAME step
2. It's a circular import, so even though "a.b" exists in sys.modules, it won't 
be accessible as an attribute of "a" yet

Getting the tests and any related documentation updates right will actually be 
harder than the code change.

--

___
Python tracker 

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