[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

2019-04-07 Thread anthony shaw


Change by anthony shaw :


--
type:  -> enhancement

___
Python tracker 

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



[issue26730] SpooledTemporaryFile doesn't correctly preserve data for text (non-binary) SpooledTemporaryFile objects when Unicode characters are written

2019-04-07 Thread Inada Naoki


Inada Naoki  added the comment:

I think this bug is critical, because it may break user's data silently.

If we can not fix this bug soon, how about adding note in document and raise 
warning?

--

___
Python tracker 

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



[issue36552] Replace OverflowError with ValueError when calculating length of range objects > PY_SIZE_MAX

2019-04-07 Thread anthony shaw


Change by anthony shaw :


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

___
Python tracker 

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



[issue36552] Replace OverflowError with ValueError when calculating length of range objects > PY_SIZE_MAX

2019-04-07 Thread anthony shaw


New submission from anthony shaw :

When calculating length of range() objects that have an r->length > 
PY_SIZE_MAX, the underlying PyLong_AsSsize_t() function will raise an 
OverflowError:

>>> a = list(range(2**256))
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C ssize_t
>>> a = range(2**256)
>>> len(a)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C ssize_t

This is expected behaviour, but to the average user, who won't know what 
ssize_t is, or what this has to do with Python int, the user message is 
confusing and OverflowError is the symptom but not the cause. The cause is that 
the length sent to range was in a value too large to calculate. 

This patch changes OverflowError to ValueError to hint to the user that the 
value sent to the range object constructor is too large.

>>> a = list(range(2**256))
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Range object too large to calculate length (Overflow Error)
>>> a = range(2**256)
>>> len(a)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Range object too large to calculate length (Overflow Error)

--
components: Library (Lib)
messages: 339589
nosy: anthony shaw
priority: normal
severity: normal
status: open
title: Replace OverflowError with ValueError when calculating length of range 
objects > PY_SIZE_MAX
versions: Python 3.8

___
Python tracker 

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



[issue9883] minidom: AttributeError: DocumentFragment instance has no attribute 'writexml'

2019-04-07 Thread miss-islington


miss-islington  added the comment:


New changeset a9a065addd175ed37a959118c90377ba60f90036 by Miss Islington (bot) 
in branch '3.7':
bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677)
https://github.com/python/cpython/commit/a9a065addd175ed37a959118c90377ba60f90036


--
nosy: +miss-islington

___
Python tracker 

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



[issue36260] Cpython/Lib vulnerability found and request a patch submission

2019-04-07 Thread Victor Kung


Victor Kung  added the comment:

I see. 

@Christian Heimes Thank you for the response.

--

___
Python tracker 

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



[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

2019-04-07 Thread Aaron Hall


Change by Aaron Hall :


--
nosy: +Aaron Hall

___
Python tracker 

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



[issue31904] Python should support VxWorks RTOS

2019-04-07 Thread LihuaZhao


Change by LihuaZhao :


--
pull_requests: +12645

___
Python tracker 

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



[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

2019-04-07 Thread anthony shaw


Change by anthony shaw :


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

___
Python tracker 

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



[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

2019-04-07 Thread anthony shaw


New submission from anthony shaw :

List comprehensions currently create a series of opcodes inside a code object, 
the first of which is BUILD_LIST with an oparg of 0, effectively creating a 
zero-length list with a preallocated size of 0.

If you're doing a simple list comprehension on an iterator, e.g.

def foo():
  a = iterable
  return [x for x in a]

Disassembly of  at 0x109db2c40, file "", line 3>:
  3   0 BUILD_LIST   0
  2 LOAD_FAST0 (.0)
>>4 FOR_ITER 8 (to 14)
  6 STORE_FAST   1 (x)
  8 LOAD_FAST1 (x)
 10 LIST_APPEND  2
 12 JUMP_ABSOLUTE4
>>   14 RETURN_VALUE

The list comprehension will do a list_resize on the 4, 8, 16, 25, 35, 46, 58, 
72, 88th iterations, etc.

This PR preallocates the list created in a list comprehension to the length of 
the iterator using PyObject_LengthHint().

It uses a new BUILD_LIST_PREALLOC opcode which builds a list with the allocated 
size of PyObject_LengthHint(co_varnames[oparg]).

[x for x in iterable] compiles to:

Disassembly of  at 0x109db2c40, file "", line 3>:
  3   0 BUILD_LIST_PREALLOC  0
  2 LOAD_FAST0 (.0)
>>4 FOR_ITER 8 (to 14)
  6 STORE_FAST   1 (x)
  8 LOAD_FAST1 (x)
 10 LIST_APPEND  2
 12 JUMP_ABSOLUTE4
>>   14 RETURN_VALUE

If the comprehension has ifs, then it will use the existing BUILD_LIST opcode

Testing using a range length of 1

./python.exe -m timeit "x=list(range(1)); [y for y in x]"

Gives 392us on the current 3.8 branch
and 372us with this change (about 8-10% faster)

the longer the iterable, the bigger the impact.

This change also catches the issue that a very large iterator, like a range 
object :
[a for a in range(2**256)]

Would cause the 3.8< interpreter to consume all memory and crash because there 
is no check against PY_SSIZE_MAX currently.

With this change (assuming there is no if inside the comprehension) is now 
caught and thrown as an OverflowError:

>>> [a for a in range(2**256)]
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
OverflowError: Python int too large to convert to C ssize_t

--
components: Interpreter Core
messages: 339586
nosy: anthony shaw, ncoghlan
priority: normal
severity: normal
status: open
title: Optimize list comprehensions with preallocate size and protect against 
overflow
versions: Python 3.8

___
Python tracker 

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



[issue36503] remove references to aix3 and aix4 in \*.py

2019-04-07 Thread Inada Naoki


Change by Inada Naoki :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 3.7, Python 3.9

___
Python tracker 

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



[issue36503] remove references to aix3 and aix4 in \*.py

2019-04-07 Thread Inada Naoki


Inada Naoki  added the comment:


New changeset b7eec94c0e86f8ac318b135ca9146fff32b7203a by Inada Naoki (Michael 
Felt) in branch 'master':
bpo-36503: remove references to 'aix3' and 'aix4' (GH-12658)
https://github.com/python/cpython/commit/b7eec94c0e86f8ac318b135ca9146fff32b7203a


--
nosy: +inada.naoki

___
Python tracker 

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



[issue36546] Add quantiles() to the statistics module

2019-04-07 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

I think adding quantiles (sometimes called fractiles) is a good feature to add. 
I especially have some use-cases for quartiles. I especially like that it 
delegates to the inv_cdf() method when available, and I'm happy with the API 
you suggested.

Forgive me if you're already aware of this, but the calculation of quantiles is 
unfortunately complicated by the fact that there are so many different ways to 
calculate them. (I see you have mentioned a potential future API for 
interp_method.)

See, for example:

http://jse.amstat.org/v14n3/langford.html

for a discussion. My own incomplete survey of statistics software has found 
about 20 distinct methods for calculating quantiles in use. I'm very happy to 
see this function added, but I'm not happy to commit to a specific calculation 
method without discussion.

If you agree that we can change the implementation later (and hence the 
specific cut points returned) then I see no reason why we can't get this in 
before feature freeze, and then do a review to find the "best" default 
implementation later. I already have three candidates:

1. Langford suggests his "CDF method 4", which is equivalent to Hyndman and 
Fan's Definition 2; it is also the default method used by SAS.

2. Hyndman and Fan themselves recommend their Definition 8:

https://robjhyndman.com/publications/quantiles/

3. R's default is H's Definition 7. (I suggest this only to ease comparisons 
with results from R, not because it has any statistical advantage.)

Do we agree that there is to be no backwards-compatibility guarantee made on 
the implementation and the specific cut-points returned? (Or at least not yet.)

--

___
Python tracker 

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



[issue36550] Avoid creating AttributeError exceptions in the debugger

2019-04-07 Thread daniel hahler


New submission from daniel hahler :

pdb should try (hard) to avoid creating unnecessary exceptions, e.g. 
``AttributeError`` when looking up commands, since this will show up in 
exception chains then (as "'Pdb' object has no attribute 'do_foo'").

See https://github.com/python/cpython/pull/4666 for an older PR in this regard.

My use case is to display the traceback for exceptions caused within/via 
Pdb.default(), to see more context when running code from pdb's prompt 
directly, where currently it would only display the exception itself.

--
components: Library (Lib)
messages: 339583
nosy: blueyed
priority: normal
severity: normal
status: open
title: Avoid creating AttributeError exceptions in the debugger
versions: Python 3.9

___
Python tracker 

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



[issue36550] Avoid creating AttributeError exceptions in the debugger

2019-04-07 Thread daniel hahler


Change by daniel hahler :


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

___
Python tracker 

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



[issue36259] exception text is being sourced from the wrong file

2019-04-07 Thread Jesse Farnham

Jesse Farnham  added the comment:

Upon further digging, the filename to search for ultimately comes from the 
PyCodeObject where the error occurred. So a possible solution could be to 
populate the PyCodeObject with the absolute path to the file when it’s first 
created in compilation. Then no searching is needed and the problem doesn’t 
happen. This seems like a potentially very invasive change, though.

--

___
Python tracker 

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



[issue36259] exception text is being sourced from the wrong file

2019-04-07 Thread Jesse Farnham


Jesse Farnham  added the comment:

I did some digging into this, and the problem seems to be that 
_Py_FindSourceFile() in traceback.c searches through every directory in 
sys.path (of which the first entry is the working directory) to find a file 
with the passed filename. So if there's a file in the working directory with 
name matching the filename passed in from the traceback object, 
_Py_FindSourceFile will find that one, resulting in the wrong listing being 
printed.

Does the traceback object contain any other information that would avoid the 
need to search sys.path to find the right file? If it can know the file name, 
maybe there's a way to find the file path as well?

Apologies if this is not useful -- this is my first attempt to contribute to 
Python.

--

___
Python tracker 

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



[issue36259] exception text is being sourced from the wrong file

2019-04-07 Thread Jesse Farnham


Change by Jesse Farnham :


--
nosy: +jesse.farnham

___
Python tracker 

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



[issue27181] Add geometric mean to `statistics` module

2019-04-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Feel free to reopen this if something further needed to be changed or discussed.

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



[issue27181] Add geometric mean to `statistics` module

2019-04-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset 6463ba3061bd311413d2951dc83c565907e10459 by Raymond Hettinger in 
branch 'master':
bpo-27181: Add statistics.geometric_mean() (GH-12638)
https://github.com/python/cpython/commit/6463ba3061bd311413d2951dc83c565907e10459


--

___
Python tracker 

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



[issue36488] os.sendfile() on BSD, macOS don't return bytes sent on EINTR

2019-04-07 Thread Josh Rosenberg


Josh Rosenberg  added the comment:

Right. So this is a hard problem for anyone to solve, and therefore os.sendfile 
should be the one solving it, not the caller of sendfile, right?

--

___
Python tracker 

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



[issue27992] Clarify %(prog)s in argparse help formatter returns basename of sys.argv[0] by default

2019-04-07 Thread py.user


Change by py.user :


--
pull_requests: +12642
stage:  -> patch review

___
Python tracker 

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
pull_requests: +12641

___
Python tracker 

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



[issue36537] except statement block incorrectly assumes end of scope(?).

2019-04-07 Thread Xavier de Gaye


Xavier de Gaye  added the comment:

The *** Tracing *** section [1] of Objects/lnotab_notes.txt in the cpython 
repository provides detailed explanations for when the line trace function is 
called.

[1] 
https://github.com/python/cpython/blob/9d7b2c0909b78800d1376fd696f73824ea680463/Objects/lnotab_notes.txt#L63

--

___
Python tracker 

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



[issue2180] tokenize: mishandles line joining

2019-04-07 Thread Anthony Sottile


Anthony Sottile  added the comment:

Here's an example in the wild which still reproduces with python3.8a3:

https://github.com/SecureAuthCorp/impacket/blob/194b22ed2fc85c4f241375fb7ebe4e0d89626c8c/impacket/examples/remcomsvc.py#L1669

This was reported as a bug on flake8:

https://gitlab.com/pycqa/flake8/issues/532

Here's the reproduction with python3.8:

$ python3.8 --version --version
Python 3.8.0a3 (default, Mar 27 2019, 03:46:44) 
[GCC 7.3.0]
$ python3.8 impacket/examples/remcomsvc.py 
$ python3.8 -mtokenize impacket/examples/remcomsvc.py 
impacket/examples/remcomsvc.py:1670:0: error: EOF in multi-line statement

--
nosy: +Anthony Sottile
versions: +Python 3.8, Python 3.9 -Python 2.7, Python 3.1, Python 3.2

___
Python tracker 

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



[issue14017] Make it easy to create a new TextIOWrapper based on an existing

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Aye, let's close this for now - swapping streams out has enough other problems 
with stale references to the original stream that using reconfigure() to update 
the existing stream in place is usually going to be the better option.

--
resolution:  -> postponed
stage: needs patch -> 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



[issue34589] Py_Initialize() and Py_Main() should not enable C locale coercion

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

I'm inclined to leave 3.7 alone unless/until we get an actual bug report for 
the current behaviour - if an embedder finds that it just straight up doesn't 
work for them, then they can either resort to tinkering with the private APIs 
(since they won't change until Python 3.8, and at that point we expect to have 
a public API available), or else stick with Python 3.6 until later this year 
when Python 3.8 is available.

--

___
Python tracker 

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



[issue36053] pkgutil.walk_packages jumps out from given path if there is package with the same name in sys.path

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Piotr: does it always jump out, or does it only jump out if the relevant module 
has already been imported?

(The tests for walk_packages are relatively weak and never generate conflicting 
names, so it's entirely plausible that there are caching side effects that make 
it do strange things)

--

___
Python tracker 

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



[issue36384] ipaddress Should not reject IPv4 addresses with leading zeroes as ambiguously octal

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

The recommended handling in the article that Serhiy mentions is to strip the 
leading zeroes, which the ipaddress module will still do - it's only being made 
more tolerant on input. That means it will become usable as a prefilter step 
(pass string with potentially leading zeroes to ipaddress, get string with no 
leading zeroes out).

So that means the one part we missed is the docs update (together with a 
versionchanged note in the module docs themselves)

--
assignee:  -> docs@python
components: +Documentation -Library (Lib)
nosy: +docs@python

___
Python tracker 

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



[issue36544] cannot import hashlib when openssl is missing

2019-04-07 Thread Xavier de Gaye


Xavier de Gaye  added the comment:

Check that PR 12708 fixes the bug:

Run the ubuntu:bpo-36544 image and enters bash as user pydev

$ docker run -it ubuntu:bpo-36544

As user pydev, clone python and fetch PR 12708, build python and import 
hashlib:

pydev@e4cfd6f74c2b:~$ git clone -b master --single-branch --depth 1 
https://github.com/python/cpython.git
pydev@e4cfd6f74c2b:~$ cd cpython/ && ./configure && make
pydev@e4cfd6f74c2b:~/cpython$ git fetch --depth 1 origin 
pull/12708/head:pr_12708 && git checkout pr_12708
pydev@e4cfd6f74c2b:~/cpython$ make
pydev@e4cfd6f74c2b:~/cpython$ ./python -c "import hashlib"

--

___
Python tracker 

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



[issue36549] str.capitalize should titlecase the first character not uppercase

2019-04-07 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I think this is a reasonable change.

Also the docs for str.title() should be fixed.

--
components: +Interpreter Core, Unicode
keywords: +easy (C)
nosy: +ezio.melotti, serhiy.storchaka, vstinner
stage:  -> needs patch
type:  -> enhancement
versions: +Python 3.8

___
Python tracker 

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



[issue36544] cannot import hashlib when openssl is missing

2019-04-07 Thread Xavier de Gaye


Xavier de Gaye  added the comment:

Steps to reproduce (requires docker support, about 500 MB and only few minutes):

1. Create the file named 'Dockerfile' whose content is:


FROM ubuntu

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
bash \
build-essential \
git \
sed \
&& rm -rf /var/lib/apt/lists/*

# Run as user 'pydev'.
RUN groupadd pydev && useradd --no-log-init -m -g pydev pydev
USER pydev:pydev
ENV HOME=/home/pydev
WORKDIR $HOME


2. Create the ubuntu:bpo-36544 image

$ docker build --tag=ubuntu:bpo-36544 .

3. Run the image and enters bash as user pydev

$ docker run -it ubuntu:bpo-36544

As user pydev, build python and import hashlib:

pydev@5a8ffc33955d:~$ git clone -b master --single-branch --depth 1 
https://github.com/python/cpython.git
pydev@70e0722a76f2:~$ cd cpython/ && ./configure && make
pydev@70e0722a76f2:~/cpython$ ./python -c "import hashlib"

--

___
Python tracker 

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



[issue36549] str.capitalize should titlecase the first character not uppercase

2019-04-07 Thread Steven D'Aprano

New submission from Steven D'Aprano :

str.capitalize appears to uppercase the first character of the string, which is 
okay for ASCII but not for non-English letters.

For example, the letter NJ in Croatian appears as Nj at the start of words when 
the first character is capitalized:

Njemačka ('Germany'), not NJemačka.

(In ASCII, that's Njemacka not NJemacka.)

https://en.wikipedia.org/wiki/Gaj's_Latin_alphabet#Digraphs

But using any of:

U+01CA LATIN CAPITAL LETTER NJ
U+01CB LATIN CAPITAL LETTER N WITH SMALL LETTER J
U+01CC LATIN SMALL LETTER NJ 

we get the wrong result with capitalize:


py> 'NJemačka'.capitalize()
'NJemačka'
py> 'Njemačka'.capitalize()
'NJemačka'
py> 'njemačka'.capitalize()
'NJemačka'


I believe that the correct behaviour is to titlecase the first code point and 
lowercase the rest, which is what the Apache library here does:

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#capitalize-java.lang.String-

--
messages: 339568
nosy: steven.daprano
priority: normal
severity: normal
status: open
title: str.capitalize should titlecase the first character not uppercase

___
Python tracker 

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



[issue36548] Make the repr of re flags more readable

2019-04-07 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


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

___
Python tracker 

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



[issue36548] Make the repr of re flags more readable

2019-04-07 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

Currently the repr of re flags contains the name of the private class and it is 
not an evaluable expression:

>>> re.I

>>> re.I|re.S|re.X


The repr of inverted flags is even more verbose:


>>> ~(re.I|re.S|re.X)


The result of str() starves from the same issues.

>>> print(re.I)
RegexFlag.IGNORECASE
>>> print(re.I|re.S|re.X)
RegexFlag.VERBOSE|DOTALL|IGNORECASE
>>> print(~re.I)
RegexFlag.ASCII|DEBUG|VERBOSE|UNICODE|DOTALL|MULTILINE|LOCALE|TEMPLATE
>>> print(~(re.I|re.S|re.X))
RegexFlag.ASCII|DEBUG|UNICODE|MULTILINE|LOCALE|TEMPLATE

If the value contains unrecognized flags, it looks even more weird, and this 
information is not shown for invered flags:

>>> re.I|re.S|re.X|(1<<10)

>>> ~(re.I|re.S|re.X|(1<<10))

>>> print(re.I|re.S|re.X|(1<<10))
RegexFlag.1024|VERBOSE|DOTALL|IGNORECASE
>>> print(~(re.I|re.S|re.X|(1<<10)))
RegexFlag.ASCII|DEBUG|UNICODE|MULTILINE|LOCALE|TEMPLATE

This repr is also not consistent with the represenation of flags in the repr of 
the compiled pattern:

>>> re.compile('x', re.I|re.S|re.X)
re.compile('x', re.IGNORECASE|re.DOTALL|re.VERBOSE)

The proposed PR makes the repr be the same as for flags in the repr of the 
compiled pattern and represents inverted flags as the result of inversion:

>>> re.I
re.IGNORECASE
>>> re.I|re.S|re.X
re.IGNORECASE|re.DOTALL|re.VERBOSE
>>> ~re.I
~re.IGNORECASE
>>> ~(re.I|re.S|re.X)
~(re.IGNORECASE|re.DOTALL|re.VERBOSE)
>>> re.I|re.S|re.X|(1<<10)
re.IGNORECASE|re.DOTALL|re.VERBOSE|0x400
>>> ~(re.I|re.S|re.X|(1<<10))
~(re.IGNORECASE|re.DOTALL|re.VERBOSE|0x400)

__str__ is set to object.__str__, so that str() will return the same as repr().

--
components: Library (Lib), Regular Expressions
messages: 339567
nosy: ethan.furman, ezio.melotti, mrabarnett, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Make the repr of re flags more readable
type: enhancement
versions: Python 3.8

___
Python tracker 

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



[issue36537] except statement block incorrectly assumes end of scope(?).

2019-04-07 Thread Xavier de Gaye


Xavier de Gaye  added the comment:

@Saim wrote
> https://docs.python.org/3/reference/compound_stmts.html#the-try-statement says

This is correct, the disassembly of foo.py below demonstrates that point: 
BEGIN_FINALLY at bytecode index 36 starts the implementation of the 'finally' 
clause that deletes 'err'. But pdb is a line debugger, not a debugger at the 
bytecode level, so when 'foo = 1' is replaced by 'import pdb; pdb.set_trace()', 
the first line where pdb may stop is at line 6 and since foo() last line is 
line 5, pdb stops at the 'return' event for this function.

===   foo.py   
def foo():
try:
1/0
except Exception as err:
foo = 1

import dis
dis.dis(foo)
===
  2   0 SETUP_FINALLY   12 (to 14)

  3   2 LOAD_CONST   1 (1)
  4 LOAD_CONST   2 (0)
  6 BINARY_TRUE_DIVIDE
  8 POP_TOP
 10 POP_BLOCK
 12 JUMP_FORWARD38 (to 52)

  4 >>   14 DUP_TOP
 16 LOAD_GLOBAL  0 (Exception)
 18 COMPARE_OP  10 (exception match)
 20 POP_JUMP_IF_FALSE   50
 22 POP_TOP
 24 STORE_FAST   0 (err)
 26 POP_TOP
 28 SETUP_FINALLY8 (to 38)

  5  30 LOAD_CONST   1 (1)
 32 STORE_FAST   1 (foo)
 34 POP_BLOCK
 36 BEGIN_FINALLY
>>   38 LOAD_CONST   0 (None)
 40 STORE_FAST   0 (err)
 42 DELETE_FAST  0 (err)
 44 END_FINALLY
 46 POP_EXCEPT
 48 JUMP_FORWARD 2 (to 52)
>>   50 END_FINALLY
>>   52 LOAD_CONST   0 (None)
 54 RETURN_VALUE
===

--

___
Python tracker 

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



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

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Oops, this covers more than just modulefinder - reopening until the other 
remaining uses of the imp module have been removed.

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

___
Python tracker 

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



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

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Fixed for Python 3.8 via the patch for #35936.

--
nosy: +ncoghlan
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.8 -Python 3.6

___
Python tracker 

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



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

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Fixed for Python 3.8 via the patch for #35936. We won't be backporting that 
patch as it also migrates modulefinder from the deprecated imp API to the 
supported importlib one, and is hence considered overly intrusive for a bug fix 
release.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
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



[issue17396] modulefinder fails if module contains syntax error

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Fixed for Python 3.8 via the patch for #35936. We won't be backporting that 
patch as it also migrates modulefinder from the deprecated imp API to support 
importlib one, and is hence considered overly intrusive for a bug fix release.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.8 -Python 3.4, Python 3.5

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:


New changeset 9d7b2c0909b78800d1376fd696f73824ea680463 by Nick Coghlan (Brandt 
Bucher) in branch 'master':
bpo-35936: Updates to modulefinder (GH-11787)
https://github.com/python/cpython/commit/9d7b2c0909b78800d1376fd696f73824ea680463


--

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-04-07 Thread Nick Coghlan


Nick Coghlan  added the comment:

Thanks Brandt!

I'll also go back and close #17396, #35376, and #25160

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread Vinay Sajip


Vinay Sajip  added the comment:


New changeset 2dad96013ca24abdc5ba5a369ea42d70ff02487a by Vinay Sajip (Xtreak) 
in branch 'master':
bpo-35726: Add test for QueueHandler with multiple handlers (GH-11659)
https://github.com/python/cpython/commit/2dad96013ca24abdc5ba5a369ea42d70ff02487a


--

___
Python tracker 

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +12639

___
Python tracker 

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread Vinay Sajip


Change by Vinay Sajip :


--
pull_requests:  -11458

___
Python tracker 

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread Vinay Sajip


Change by Vinay Sajip :


--
pull_requests:  -11459

___
Python tracker 

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



[issue35726] QueueHandler formatting affects other handlers

2019-04-07 Thread Vinay Sajip


Change by Vinay Sajip :


--
pull_requests:  -11460

___
Python tracker 

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



[issue27992] Clarify %(prog)s in argparse help formatter returns basename of sys.argv[0] by default

2019-04-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

CPython now accepts GitHub PRs. Please see the workflow at 
https://devguide.python.org . You can raise a PR against master branch.

--

___
Python tracker 

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



[issue27992] Clarify %(prog)s in argparse help formatter returns basename of sys.argv[0] by default

2019-04-07 Thread py.user


py.user  added the comment:

@Karthikeyan Singaravelan
Thank you for the point. I added a new patch.

--
Added file: https://bugs.python.org/file48245/argparse_sys-argv-0-basename.diff

___
Python tracker 

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