[issue26707] plistlib fails to parse bplist with 0x80 UID values

2016-04-06 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +ronaldoussoren, serhiy.storchaka
type: crash -> behavior

___
Python tracker 

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



[issue26388] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)

2016-04-06 Thread Nick Coghlan

Nick Coghlan added the comment:

Thanks for the ping.

The actual code changes look OK to me for the initially proposed design, which 
means the main missing piece would be documentation updates (both to the 
docstrings and to runpy module reference).

However, thinking about how those docs might be written, I'm starting to think 
the specific proposed design would be inherently confusing for folks that 
aren't already familiar with runpy's internals, and it might be better to use a 
callback API with a few predefined helper functions.

That is, suppose the new parameter was a callback accepting the following 
parameters:

* "module" - the module about to be executed
* "argv" - sys.argv prior to module execution

And then we have 3 predefined callbacks/callback factories in runpy:

def keep_argv(module, argv):
return argv

def set_argv0(module, argv):
return module.__file__ + argv[1:]

def set_argv(argv, *, implicit_argv0=True):
argv_override = list(argv)
if implicit_argv0:
def _set_argv(module, original_argv):
return [module.__file__] + argv_override
else:
def _set_argv(module, original_argv):
return argv_override
return _set_argv

Then the three scenarios in your original post would look like:

runpy.run_module(mod_name, argv=set_argv0)
runpy.run_module(mod_name, argv=keep_argv)
runpy.run_module(mod_name, argv=set_argv(iterable))

(and similarly for run_path)

"argv=None" would be the default, and equivalent to specifying "argv=set_argv0"

"argv=set_argv(iterable, implicit_argv0=False)" would allow even more precise 
control of the argv settings seen by the running module.

Future and/or custom variations would be straightforward, since we're just 
passing in a callable.

The documentation benefit is that the "argv" parameter docs can just describe 
the callback signature and the use of "set_argv0" as the default, with the 
details of the individual behaviours moving to the definitions of the 
corresponding functions.

--

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread Martin Panter

Martin Panter added the comment:

Yes, I think this is the expected behaviour, and I can’t think of any 
improvements that could be made. If you call fileno(), you have to ensure that 
you don’t close the file descriptor until you have finished using it. It is a 
bit like accessing memory after it has been freed. Python doesn’t make raw 
memory addresses easily accessible, but it does make fileno() accessible 
without much protection.

Perhaps there is some confusion about the term socket. Normally (without using 
the fileno=... parameter), Python’s socket() constructor does two things. 
First, it creates a new OS socket using the socket() system call (or Winsock 
equivalent), which returns a file descriptor or handle (an integer). Then, it 
creates a Python socket object, which wraps the file descriptor.

When you use socket(fileno=...), only the second step is taken. You get a _new_ 
socket object, which wraps the given existing OS socket file descriptor. So 
when it says “the same socket”, I think it means the same OS-level socket. It 
still creates a new Python object.

--

___
Python tracker 

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



[issue26388] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)

2016-04-06 Thread Mike Kaplinskiy

Mike Kaplinskiy added the comment:

ping

--

___
Python tracker 

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



[issue26707] plistlib fails to parse bplist with 0x80 UID values

2016-04-06 Thread John Lehr

New submission from John Lehr:

libplist raises an invalid file exception on loading properly formed binary 
plists containing UID (0x80) values.  The binary files were tested for form 
with plutil.

Comments at line 706 state the value is defined but not in use in plists, and 
the object is not handled.  However, I find them frequently in bplists, e.g., 
iOS Snapchat application files.  I have attached a proposed patch that I have 
tested on these files and can now successfully parse them with the _read_object 
method in the _BinaryPlistParser class.

My proposed patch is pasted below for others consideration while waiting for 
the issue to be resolved.

706,707c706,708
< # tokenH == 0x80 is documented as 'UID' and appears to be used for
< # keyed-archiving, not in plists.
---
> elif tokenH == 0x80: #UID
> s = self._get_size(tokenL)
> return self._fp.read(s).decode('ascii')

Thanks for your consideration.

--
components: Library (Lib)
files: plistlib_uid.diff
keywords: patch
messages: 262974
nosy: slo.sleuth
priority: normal
severity: normal
status: open
title: plistlib fails to parse bplist with 0x80 UID values
type: crash
versions: Python 3.5
Added file: http://bugs.python.org/file42388/plistlib_uid.diff

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread JoshN

JoshN added the comment:

I do understand that the docs are a bit strange on the issue. For example, 
actually testing the line you referenced ("...fileno will return the same 
socket and not a duplicate.") by creating 2 sockets and testing sameness with 
the 'is' operator returns false.

I tried to trim the example code as much as possible - I did test disabling the 
garbage collector, playing with inheritance, etc, but trimmed them out as they 
didn't have any effect on my system.


I think my main issue was, when this occurs, the socket 'breaks' as you 
mentioned instead of closing. Was almost sure it was a bug. Using detach works 
for this UDP example, but I wasn't sure if detaching the socket actually closes 
it (e.g. in a stream oriented connection).

So this is considered normal behavior then?

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

Anthony Sottile added the comment:

Here's an improved patch which:

- passes the tests
- puts the test in the correct place

I'm not entirely happy with the approach -- open to suggestions :)

--
Added file: http://bugs.python.org/file42387/patch2

___
Python tracker 

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



[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart

Steven Basart added the comment:

I reuploaded the file.  The spacing on the if amount < 1 was off.  Hopefully 
its fixed now.

--
Added file: http://bugs.python.org/file42386/weighted_choice_v4.patch

___
Python tracker 

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



[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart

Changes by Steven Basart :


Removed file: http://bugs.python.org/file42385/weighted_choice_v4.patch

___
Python tracker 

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



[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart

Steven Basart added the comment:

Okay so I added a few lines of code.  One to make it return a single number if 
amount == 1 and the other to check that the amount > 1.

The main difference I've noticed between this implementation and previous 
versions compared to say R is that in R they provide a boolean flag to ask if 
sampling with replacement.

Here's there documentation and source code:
https://github.com/wch/r-source/blob/e5b21d0397c607883ff25cca379687b86933d730/src/library/base/man/sample.Rd

https://github.com/wch/r-source/blob/e5b21d0397c607883ff25cca379687b86933d730/src/library/base/R/sample.R

Maybe someone else can comment more on the use cases.  I can only say for 
myself that I've needed this function plenty of times when working with samples 
that have a non uniform distribution.

--
Added file: http://bugs.python.org/file42385/weighted_choice_v3.patch

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread Martin Panter

Martin Panter added the comment:

Also, if you enable warnings (e.g. python -Wall), you should see that the 
socket is being closed:

-c:22: ResourceWarning: unclosed 

--

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread Martin Panter

Martin Panter added the comment:

The documentation already says “Sockets are automatically closed when they are 
garbage-collected”. If for some reason you want to release a socket object but 
keep the file descriptor open, I suggest socket.detach(). Otherwise, pass the 
original socket, not the fileno.

I think this is at best a documentation issue, if you have any suggestions.

--
assignee:  -> docs@python
components: +Documentation -IO
nosy: +docs@python, martin.panter
type: crash -> behavior

___
Python tracker 

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



[issue18844] allow weights in random.choice

2016-04-06 Thread Westley Martínez

Westley Martínez added the comment:

I still like Serhiy's implementation more. A function that returns a list 
instead of the item is unnatural and doesn't fit with the rest of the module.

I think there's need to be some discussion about use cases. What do users 
actually want? Maybe post this on the ideas list.

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

Anthony Sottile added the comment:

The root cause seems to be that autospecced functions return a function object 
(not a Mock instance) which a '.mock' attribute which is a MagicMock ( assigned 
here: 
https://github.com/python/cpython/blob/ae775ab1eb72f42de2d070158bade4bf261ac04f/Lib/unittest/mock.py#L198
 )

I took a first stab at a patch (attached)

--
Added file: http://bugs.python.org/file42384/patch

___
Python tracker 

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



[issue26705] logging.Handler.handleError should be called from logging.Handler.handle

2016-04-06 Thread Vinay Sajip

Vinay Sajip added the comment:

Thanks for the suggestion, but I'm not sure this can be accepted without 
violating backward compatibility. It forces each handler implementation to 
either accept the base implementation of handleError(), or to override it. And 
if there are existing handler implementations out there (i.e. not in the 
stdlib) which don't call handleError in their emit() (i.e. allow exceptions to 
propagate upwards), their behaviour would change, wouldn't it? That's not 
backwards-compatible.

--

___
Python tracker 

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



[issue26706] Update OpenSSL version in readme

2016-04-06 Thread Shaun Walbridge

New submission from Shaun Walbridge:

Sync documentation with the OpenSSL version update (1.0.2g vs 1.0.2f). Mismatch 
present in both head and 3.5 branch.

--
assignee: docs@python
components: Documentation
files: readme-openssl.diff
keywords: patch
messages: 262964
nosy: docs@python, scw
priority: normal
severity: normal
status: open
title: Update OpenSSL version in readme
type: enhancement
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file42383/readme-openssl.diff

___
Python tracker 

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



[issue26027] Support Path objects in the posix module

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is preliminary patch without tests. Writing tests will be tiresome.

--
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file42382/path_converter_path.patch

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

New submission from Anthony Sottile:

Originally from https://github.com/testing-cabal/mock/issues/350

## Example
```python
from unittest import mock

class C(object):
def f(self):
pass

c = C()

with mock.patch.object(c, 'f', autospec=True):
with mock.patch.object(c, 'f', autospec=True):
pass
```

## Python3.3

```
$ test.py
$
```

## Python3.4 / 3.5 / 3.6 (From gitbhub.com/python/cpython@fa3fc6d7)

```
Traceback (most recent call last):
  File "test.py", line 10, in 
with mock.patch.object(c, 'f', autospec=True):
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 1320, in 
__enter__
_name=self.attribute, **kwargs)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 2220, in 
create_autospec
_check_signature(original, new, skipfirst=skipfirst)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 112, in 
_check_signature
_copy_func_details(func, checksig)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 117, in 
_copy_func_details
funcopy.__name__ = func.__name__
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 578, in 
__getattr__
raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute '__name__'
```

--
components: Library (Lib)
messages: 262960
nosy: asottile
priority: normal
severity: normal
status: open
title: unittest.mock.patch: Double patching instance method: AttributeError: 
Mock object has no attribute '__name__'
type: crash
versions: 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



[issue26705] logging.Handler.handleError should be called from logging.Handler.handle

2016-04-06 Thread Aviv Palivoda

New submission from Aviv Palivoda:

Currently all the stdlib logging handlers (except BufferingHandler) emit method 
have the following structure:
def emit(self, record):
try:
// do the emit
except Exception:
self.handleError(record)

I suggest changing this so that the handle method will do the exception 
handling of the emit:

def handle(self, record): 
rv = self.filter(record)
if rv:
self.acquire()
try:
self.emit(record)
except Exception:
self.handleError(record)
finally:
self.release()
return rv

Now the emit() method can be override without the need to handle it's own 
exceptions.

I think this is more clear with the current documentation as well. For example 
in the handleError function it says that "This method should be called from 
handlers when an exception is encountered during an emit() call". In addition 
in the only example that implement the emit() function 
https://docs.python.org/3/howto/logging-cookbook.html#speaking-logging-messages 
there is no error handling at all.

--
components: Library (Lib)
files: logging-handle-error.patch
keywords: patch
messages: 262962
nosy: palaviv, vinay.sajip
priority: normal
severity: normal
status: open
title: logging.Handler.handleError should be called from logging.Handler.handle
type: behavior
versions: Python 3.6
Added file: http://bugs.python.org/file42381/logging-handle-error.patch

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 8dc144e47252 by Serhiy Storchaka in branch 'default':
Issue #26671: Fixed #ifdef indentation.
https://hg.python.org/cpython/rev/8dc144e47252

--

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4acdb324a430 by Serhiy Storchaka in branch 'default':
Issue #26671: Fixed #ifdef indentation.
https://hg.python.org/cpython/rev/4acdb324a430

--

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread Josh Rosenberg

Josh Rosenberg added the comment:

For source reference, the behavior for this case is to just copy out the file 
descriptor and stick it in a new socket object ( 
https://hg.python.org/cpython/file/3.5/Modules/socketmodule.c#l4289 ); no work 
is being done to somehow collaboratively manage the file descriptor to ensure 
it remains alive for the life of the socket object you're creating.

--

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread Josh Rosenberg

Josh Rosenberg added the comment:

You used the `fileno` based initialization in the child, which creates a 
wrapper around the same file descriptor without duplicating it, so when the 
first socket disappears, that file descriptor becomes invalid.

I think this is a doc bug more than a behavior bug; the docs say "Unlike 
socket.fromfd(), fileno will return the same socket and not a duplicate." which 
almost seems like the idea is that the Python level socket object it returns is 
cached in some way that allows it to be looked up by file descriptor (making 
mysock2 = socket.socket(fileno=mysock.fileno()) equivalent to mysock2 = 
mysock), but what it really means is that there are two Python level socket 
objects referencing the same C level file descriptor; the normal cleanup 
behavior still applies though, so the first Python level socket object to be 
destroyed also closes the file descriptor, leaving the other socket object in a 
broken state.

The correct approach to this would be to just pass the socket object to the 
thread directly, or pass along the address family and type and use 
socket.fromfd (which dups the underlying file descriptor).

--
nosy: +josh.r

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for your review Larry.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a866f5727b7f by Serhiy Storchaka in branch 'default':
Issue #26671: Enhanced path_converter.
https://hg.python.org/cpython/rev/a866f5727b7f

--
nosy: +python-dev

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Larry Hastings

Larry Hastings added the comment:

LGTM.

--

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here it is.

--
Added file: http://bugs.python.org/file42380/path_converter_cleanup_3.patch

___
Python tracker 

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



[issue23551] IDLE to provide menu link to PIP gui.

2016-04-06 Thread Terry J. Reedy

Terry J. Reedy added the comment:

It is wrong for Run Module to open a new shell window when there is a shell 
window already.  But I am not seeing this today with IDLE restarted, so for 
now, forget about it.

V4 is improved, but the list of installed packages is repeated and 2/3 repeated 
again, for a total of 2 2/3 appearances  - like 'abcabcab', where a, b, and c 
are packages.

--

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +pitrou

___
Python tracker 

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



[issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

2016-04-06 Thread JoshN

Changes by JoshN :


--
title: Socket state corrupts when original assignment goes out of scope -> 
Socket state corrupts when original socket object goes out of scope in a 
different thread

___
Python tracker 

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



[issue26703] Socket state corrupts when original assignment goes out of scope

2016-04-06 Thread JoshN

New submission from JoshN:

Creating a socket in one thread and sharing it with another will cause the 
socket to corrupt as soon as the thread it was created in exits.

Example code:
import socket, threading, time, os

def start():
a = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
a.bind(("", 8080))
a.set_inheritable(True)

thread = threading.Thread(target=abc, args=(a.fileno(),))
thread.start()

time.sleep(2)
print("Main thread exiting, socket is still valid: " + str(a) + "\n")

def abc(b):
sock = socket.socket(fileno=b)
for _ in range(3):
print("Passed as an argument:" + str(sock) + "\n=")

time.sleep(1.1)

start()

Note that, as soon as the main thread exits, the socket isn't closed, nor is 
the fd=-1, etc. Doing anything with this corrupted object throws WinError 10038 
('operation performed on something that is not a socket').

I should note that the main thread exiting doesn't seem to be the cause, it is 
the original object containing the socket going out of scope that causes the 
socket to become corrupted.

-JoshN

--
components: IO
messages: 262951
nosy: JoshN
priority: normal
severity: normal
status: open
title: Socket state corrupts when original assignment goes out of scope
type: crash
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



[issue23551] IDLE to provide menu link to PIP gui.

2016-04-06 Thread Eric Khoo Jiun Hooi

Changes by Eric Khoo Jiun Hooi :


Added file: http://bugs.python.org/file42379/pip_gui_v4.py

___
Python tracker 

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



[issue26671] Clean up path_converter in posixmodule.c

2016-04-06 Thread Larry Hastings

Larry Hastings added the comment:

Can you post the updated patch please?

--

___
Python tracker 

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



[issue26698] IDLE DPI Awareness

2016-04-06 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +gpolo, kbk, roger.serwy, serhiy.storchaka, terry.reedy

___
Python tracker 

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



[issue26702] A better assert statement

2016-04-06 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

On Apr 06, 2016, at 03:07 PM, Serhiy Storchaka wrote:

>I think in this particular case you are more interesting in the value of k
>than k.replace('.', '').replace('-', '').replace('_', '').

Possibly so.

--

___
Python tracker 

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



[issue26702] A better assert statement

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I think in this particular case you are more interesting in the value of k than 
k.replace('.', '').replace('-', '').replace('_', '').

--
nosy: +rhettinger, serhiy.storchaka

___
Python tracker 

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



[issue23551] IDLE to provide menu link to PIP gui.

2016-04-06 Thread Eric Khoo Jiun Hooi

Eric Khoo Jiun Hooi added the comment:

I try to open the script in editor mode and run the script. It restart shell 
and run the script. I upload the picture of it, is there any wrong with it?

--
Added file: http://bugs.python.org/file42378/tem_v3_idle.png

___
Python tracker 

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



[issue26702] A better assert statement

2016-04-06 Thread Barry A. Warsaw

New submission from Barry A. Warsaw:

Too many times I hit failing assert statements, and have no idea what value is 
causing the assertion to fail.  Sure, you can provide a value to print (instead 
of just the failing code) but it seems to be fairly rarely used.  And it can 
also lead to code duplication.  As an example, I saw this today in some 
installed code:

assert k.replace('.', '').replace('-', '').replace('_', '').isalum()

So now I have to sudo edit the installed system file, duplicate everything up 
to but not including the .isalum() as the second argument to assert, then try 
to reproduce the problem.  IWBNI assert could make this better.

One idea would be to split the value and the conditional being asserted on that 
value, but we can't use two-argument asserts for that.  Crazy syntax thought: 
reuse the 'with' keyword:

assert k.replace('.', '').replace('-', '').replace('_', '') with isalum

where the part before the 'with' is 'value' and the part after the 'with' is 
conditional, and the two parts together imply the expression.

This would be equivalent to:

if __debug__:
if not value.conditional():
raise AssertionError(expression, value, conditional)

I suppose you then want to support arguments:

assert foo with can_bar, 1, 2, x=3

but maybe that's YAGNI and we can just say to use a better 2-value assert in 
those more complicated cases.

--
messages: 262946
nosy: barry
priority: normal
severity: normal
status: open
title: A better assert statement
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



[issue26701] Documentation for int constructor mentions __int__ but not __trunc__

2016-04-06 Thread R. David Murray

R. David Murray added the comment:

It is documented in the relevant PEP (pep 3141), but should indeed be added to 
the appropriate places in the regular documentation.

--
nosy: +r.david.murray
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



[issue26257] Eliminate buffer_tests.py

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Nice.

> I discovered a flaw in the bytearray tests: most of them don’t actually test 
> bytearray objects!

Good catch!

> I adapted the tests from the deleted buffer_tests.py file to override the 
> relevant tests from string_tests.py, so that we continue to test bytearray 
> methods but with str a.k.a. bytes arguments.

The patch LGTM. But may be instead of duplicating tests add fixfillchartype() 
(calling fixtype() by default)? If this don't complicate tests too much.

--

___
Python tracker 

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



[issue26257] Eliminate buffer_tests.py

2016-04-06 Thread Martin Panter

Martin Panter added the comment:

I discovered a flaw in the bytearray tests: most of them don’t actually test 
bytearray objects! This is easy to fix in Python 3, and I added a test case to 
ensure that the arguments are converted to the expected type.

However porting this fix to Python 2 was trickier. A few of the bytearray 
methods do not accept bytearray arguments:

>>> bytearray(b"abc").ljust(10, bytearray(b"*"))
TypeError: ljust() argument 2 must be char, not bytearray
>>> bytearray(b"abc").rjust(10, bytearray(b"*"))
TypeError: rjust() argument 2 must be char, not bytearray
>>> bytearray(b"abc").center(10, bytearray(b"*"))
TypeError: center() argument 2 must be char, not bytearray

I adapted the tests from the deleted buffer_tests.py file to override the 
relevant tests from string_tests.py, so that we continue to test bytearray 
methods but with str a.k.a. bytes arguments.

--
versions: +Python 2.7
Added file: http://bugs.python.org/file42377/buffer_tests.py2.patch

___
Python tracker 

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



[issue26689] Add `has_flag` method to `distutils.CCompiler`

2016-04-06 Thread SilentGhost

Changes by SilentGhost :


--
status: pending -> open

___
Python tracker 

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



[issue26689] Add `has_flag` method to `distutils.CCompiler`

2016-04-06 Thread SilentGhost

SilentGhost added the comment:

I'm largely fine with it, bar the in-function import. It would also be good if 
you could verify that no other temporary files are left after the function is 
run.

As I said earlier, issue 25544 should have priority and it should get a 
refreshed patch soon.

Donald, I'm assigning issue to you since you're maintaining this module.

--
assignee:  -> dstufft
stage: patch review -> commit review
status: open -> pending

___
Python tracker 

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



[issue26701] Documentation for int constructor mentions __int__ but not __trunc__

2016-04-06 Thread Robert Smallshire

New submission from Robert Smallshire:

The documentation for the int(x) constructor explains that if possible, it 
delegates to x.__int__().   The documentation does not explain that there is a 
fallback to x.__trunc__() if x.__int__() is not available.

The only mention of __trunc__ in the Python documentation is in the entry for 
math.trunc; the documentation for the numbers module does not describe the 
underlying special methods.

Given that all Real numbers are required to implement __trunc__ but only 
Integral subclasses are required to implement __int__ this could be important 
to implementers of other Real types, although in practice I imagine that most 
Real types will implement __int__ as float does.

--
assignee: docs@python
components: Documentation
messages: 262941
nosy: Robert Smallshire2, docs@python
priority: normal
severity: normal
status: open
title: Documentation for int constructor mentions __int__ but not __trunc__
type: enhancement
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



[issue26700] Make digest_size a class variable

2016-04-06 Thread Raymond Hettinger

New submission from Raymond Hettinger:

It would be nicer if this worked:

 >>> hashlib.md5.digest_size
 64

--
assignee: gregory.p.smith
components: Extension Modules
messages: 262940
nosy: gregory.p.smith, rhettinger
priority: normal
severity: normal
status: open
title: Make digest_size a class variable
type: enhancement
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



[issue26200] SETREF adds unnecessary work in some cases

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Py_SETREF was renamed to Py_XSETREF in 719c11b6b6ff, d0c8b2c1544e and 
7197809a7428.

Here is a patch that introduces new Py_SETREF and uses it instead Py_XSETREF if 
Py_DECREF was used before.

--
keywords: +patch
Added file: http://bugs.python.org/file42376/py_setref.patch

___
Python tracker 

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



[issue22570] Better stdlib support for Path objects

2016-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Sorry, these changesets were related to issue26200.

--

___
Python tracker 

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



[issue23551] IDLE to provide menu link to PIP gui.

2016-04-06 Thread Terry J. Reedy

Terry J. Reedy added the comment:

F5 from the editor, with a Shell window already present.

--

___
Python tracker 

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



[issue26699] locale.str docstring is incorrect: "Convert float to integer"

2016-04-06 Thread Mark Dickinson

New submission from Mark Dickinson:

[Observed by one of my colleagues]

The locale.str docstring currently looks like this (and apparently has been
this way since the dawn of time):

def str(val):
"""Convert float to integer, taking the locale into account."""

The output of str doesn't *look* like an integer on my machine. :-)

Python 2.7.10 |Master 2.1.0.dev1829 (64-bit)| (default, Oct 21 2015, 
09:09:19) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, 'fr_FR')
'fr_FR'
>>> locale.str(34.56)
'34,56'

--
assignee: docs@python
components: Documentation
keywords: easy
messages: 262936
nosy: docs@python, mark.dickinson
priority: normal
severity: normal
stage: needs patch
status: open
title: locale.str docstring is incorrect: "Convert float to integer"
type: behavior
versions: Python 2.7, 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



[issue22570] Better stdlib support for Path objects

2016-04-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d0c8b2c1544e by Serhiy Storchaka in branch '3.5':
Issue #22570: Renamed Py_SETREF to Py_XSETREF.
https://hg.python.org/cpython/rev/d0c8b2c1544e

New changeset 719c11b6b6ff by Serhiy Storchaka in branch 'default':
Issue #22570: Renamed Py_SETREF to Py_XSETREF.
https://hg.python.org/cpython/rev/719c11b6b6ff

New changeset 7197809a7428 by Serhiy Storchaka in branch '2.7':
Issue #22570: Renamed Py_SETREF to Py_XSETREF.
https://hg.python.org/cpython/rev/7197809a7428

--

___
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-04-06 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Please apply the new macros so that all the original DECREFs are restored 
rather than blindly converted to XDECREFs.

--

___
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-04-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Since several core devs agree that we should have doual macros, I'll rename 
Py_SETREF to Py_XSETREF and add new Py_SETREF.

--

___
Python tracker 

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