[issue31282] C APIs called without GIL in PyOS_Readline

2017-08-25 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +haypo, serhiy.storchaka

___
Python tracker 

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



[issue31282] C APIs called without GIL in PyOS_Readline

2017-08-25 Thread Xiang Zhang

New submission from Xiang Zhang:

When debugging our project I find something interesting. In PyOS_Readline it 
releases the GIL and delegate its job to PyOS_ReadlineFunctionPointer, which 
could be call_readline or PyOS_StdioReadline(I don't find where 
vms__StdioReadline is defined). But in the two functions, they use some C APIs 
like PyMem_Malloc/MALLOC, PyErr_SetString which need guarded by GIL. I don't 
understand why not doing find-grained lock control in call_readline or 
PyOS_StdioReadline since the code is ancient. :-(

I find this because our project makes test_cmd_line fail with `echo "Timer\n" | 
python -i -m timeit -n 1`.

--
components: Interpreter Core
messages: 300862
nosy: xiang.zhang
priority: normal
severity: normal
status: open
title: C APIs called without GIL in PyOS_Readline
type: behavior
versions: Python 2.7

___
Python tracker 

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



[issue30987] Support for ISO-TP protocol in SocketCAN

2017-08-25 Thread Terry J. Reedy

Terry J. Reedy added the comment:

There is no specific maintainer for socket modules, so this may or may not get 
attention anytime soon -- https://docs.python.org/devguide/experts.html.

New features are not backported.

--
nosy: +terry.reedy

___
Python tracker 

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



[issue30987] Support for ISO-TP protocol in SocketCAN

2017-08-25 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
stage:  -> patch review

___
Python tracker 

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



[issue31281] fileinput inplace does not work with pathlib.Path

2017-08-25 Thread Zhiming Wang

Changes by Zhiming Wang :


--
pull_requests: +3245

___
Python tracker 

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



[issue31281] fileinput inplace does not work with pathlib.Path

2017-08-25 Thread Zhiming Wang

New submission from Zhiming Wang:

Consider

import fileinput
import pathlib
with fileinput.input(files=(pathlib.Path('in.txt'),), inplace=True) as fp:
for line in fp:
print(line, end='')

which results in

Traceback (most recent call last):
  File "./pathlib-fileinput.py", line 6, in 
for line in fp:
  File "/Users/zmwang/.pyenv/versions/3.6.1/lib/python3.6/fileinput.py", 
line 250, in __next__
line = self._readline()
  File "/Users/zmwang/.pyenv/versions/3.6.1/lib/python3.6/fileinput.py", 
line 331, in _readline
self._filename + (self._backup or ".bak"))
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

A trivial fix is converting the specified filename to str when assigning to 
self._filename:

-self._filename = self._files[0]
+self._filename = str(self._files[0])

--
components: Library (Lib)
messages: 300860
nosy: zmwangx
priority: normal
severity: normal
status: open
title: fileinput inplace does not work with pathlib.Path
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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



[issue31280] Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages

2017-08-25 Thread Eric V. Smith

Eric V. Smith added the comment:

I think this is a function of the .pth file causing 'zc' to be in sys.modules. 
If I delete the .pth file, the first import of zc.m succeeds.

Note that if the .pth file is in place, then:

% bin/python3
Python 3.6.1 (default, Mar 24 2017, 12:50:34)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> 'zc' in sys.modules
True
>>>

--

___
Python tracker 

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



[issue31280] Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages

2017-08-25 Thread Jim Fulton

Jim Fulton added the comment:

No, but I managed to unattach it, because "Choose File" always feels like a 
submit button to me.

Sorry.

Attached.

--
Added file: http://bugs.python.org/file47101/z.py

___
Python tracker 

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



[issue31280] Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages

2017-08-25 Thread Eric V. Smith

Eric V. Smith added the comment:

Jim: did you forget to attach the z.py script?

--
nosy: +eric.smith

___
Python tracker 

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



[issue31280] Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages

2017-08-25 Thread Barry A. Warsaw

Changes by Barry A. Warsaw :


--
nosy: +barry

___
Python tracker 

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



[issue31280] Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages

2017-08-25 Thread Jim Fulton

New submission from Jim Fulton:

I'm having an issue importing from namespaces packages whose directories are 
added to sys.path and have other packages from the same namespace in 
site-packages.

To reproduce:

- Create a virtualenv and install zc.buildout in it (``envdir/bin/pip install 
zc.buildout``).

- Run the attached script with the virtual environment (``envdir/bin/python 
z.py``).

Note that scenarios like https://www.python.org/dev/peps/pep-0420/#id3 work 
fine.  This seems to related to having namespace packages in site-packages, or, 
presumably anywhere on the default path.

I've verified this with Python 3.4, 3.5, and 3.6.

If y'all agree that this is a bug, then I'll attempt debug it and come up with 
a PR.

--
messages: 300856
nosy: j1m
priority: normal
severity: normal
status: open
title: Namespace packages in directories added to path aren't importable if 
packages from the same namespace are in site-packages
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



[issue27099] IDLE: turn builting extensions into regular modules

2017-08-25 Thread Ned Deily

Changes by Ned Deily :


--
nosy:  -ned.deily

___
Python tracker 

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



[issue31244] IDLE: work around shortcuts bug in Windows' IMEs and tk

2017-08-25 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I obtained more info on the Japanese IME.  It has 2 modes of operation: 
'romanji' and 'kana'.  In romanji mode, one types the ascii transliteration of 
the syllabic chars.  When one types type the syllable vowel , the program 
replaces the sequence of 1 to 3 ascii chars with a Japanese char.  So while 
typing 'akitsu', the 'a', 'ki', and 'tsu' would become 3 chars, with the 'k' 
and 'ts' momentarily visible.  Modifier combinations naturally work since the 
keyboard is being interpreted as outputting ascii chars.  In kana mode, 
japanese chars appear directly, but Ctrl must, in effect, temporarily revert 
the keys to their ascii interpretations.

A Chinese keyboard with a pinyan (romanization) input mode might do the same.  
But non-English keyboards having an ascii mode is likely exceptional.  Given 
this and the two answers above, I conclude that delivering IDLE with a 
'complete' set of IME-compatible keysets is an impossible problem.

I definitely want to document the problem.

I will stay open to the possibility of a 'customizer' that would prompt a user 
to hit all the character keys in a defined order and then augment an existing 
keyset using the method described in msg300716.  The table at 
https://www.tcl.tk/man/tcl/TkCmd/keysyms.htm suggests that this could 
potentially cover accented latin, cyrillic, greek, hebrew, arabic, and japanese 
keyboards.

--

___
Python tracker 

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



[issue31279] Squash new gcc warning (-Wstringop-overflow)

2017-08-25 Thread Stefan Krah

Changes by Stefan Krah :


--
components: +Build
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type:  -> compile error
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



[issue31272] typing module conflicts with __slots__-classes

2017-08-25 Thread Ivan Levkivskyi

Ivan Levkivskyi added the comment:

I think this is fixed in latest version. I thought it was also backported to 
Python 3.5.3. What is the version you are using? Could you please try updating 
to the latest bugfix release? (currently these are 3.5.4 and 3.6.2).

--
nosy: +levkivskyi

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
stage: needs patch -> backport needed

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset a5b4ea15b61e3f3985f4f0748a18f8b888a63532 by Serhiy Storchaka 
(Oren Milman) in branch 'master':
bpo-31271: Fix an assertion failure in io.TextIOWrapper.write. (#3201)
https://github.com/python/cpython/commit/a5b4ea15b61e3f3985f4f0748a18f8b888a63532


--

___
Python tracker 

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



[issue31279] Squash new gcc warning (-Wstringop-overflow)

2017-08-25 Thread Stefan Krah

Stefan Krah added the comment:


New changeset dce6502059f46a04f90938b9d832394c8215397b by Stefan Krah in branch 
'master':
bpo-31279: Silence -Wstringop-overflow warning. (#3207)
https://github.com/python/cpython/commit/dce6502059f46a04f90938b9d832394c8215397b


--

___
Python tracker 

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



[issue31279] Squash new gcc warning (-Wstringop-overflow)

2017-08-25 Thread Stefan Krah

Changes by Stefan Krah :


--
pull_requests: +3244

___
Python tracker 

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



[issue31279] Squash new gcc warning (-Wstringop-overflow)

2017-08-25 Thread Stefan Krah

New submission from Stefan Krah:

gcc-7.2 emits the following not-so-useful warning:


Objects/bytearrayobject.c:226:9: warning: ‘memcpy’: specified size between 
9223372036854775808 and 18446744073709551615 exceeds maximum object size 
9223372036854775807

--
messages: 300851
nosy: skrah
priority: normal
severity: normal
status: open
title: Squash new gcc warning (-Wstringop-overflow)

___
Python tracker 

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



[issue31254] WeakKeyDictionary/Mapping doesn't call __missing__

2017-08-25 Thread Antony Lee

Antony Lee added the comment:

Thanks for the clarification!

"at least if the original key is not `obj` but some other object equal to 
`obj`" does not apply in my case so I'm fine, but the example shows that this 
is tricky to get right...

--

___
Python tracker 

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



[issue31237] test_gdb disables 25% of tests in optimized builds

2017-08-25 Thread Łukasz Langa

Changes by Łukasz Langa :


--
resolution:  -> wont fix
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



[issue31237] test_gdb disables 25% of tests in optimized builds

2017-08-25 Thread Łukasz Langa

Łukasz Langa added the comment:

I guess it's wontfix then. Sad, since that leaves us partially blind to 
regressions like bpo-30983.

--

___
Python tracker 

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



[issue31275] Check fall-through in _codecs_iso2022.c

2017-08-25 Thread Stefan Krah

Stefan Krah added the comment:

Thanks, Serhiy!

--
components: +Build
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type:  -> compile error
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



[issue31205] IDLE, configdialog: Factor out KeysPage class from ConfigDialog

2017-08-25 Thread Łukasz Langa

Łukasz Langa added the comment:

Oh, forgot about this exception, sorry! Thanks for the clarification.

--

___
Python tracker 

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



[issue31275] Check fall-through in _codecs_iso2022.c

2017-08-25 Thread Stefan Krah

Stefan Krah added the comment:


New changeset 138753c1b96b5e06a5c5d409fa4cae5e2fe1108b by Stefan Krah in branch 
'master':
bpo-31275: Small refactoring to silence a fall-through warning. (#3206)
https://github.com/python/cpython/commit/138753c1b96b5e06a5c5d409fa4cae5e2fe1108b


--

___
Python tracker 

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



[issue31275] Check fall-through in _codecs_iso2022.c

2017-08-25 Thread Stefan Krah

Changes by Stefan Krah :


--
pull_requests: +3243

___
Python tracker 

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



[issue28261] wrong error messages when using PyArg_ParseTuple to parse normal tuples

2017-08-25 Thread Oren Milman

Oren Milman added the comment:

sure

--

___
Python tracker 

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



[issue31276] PyObject_CallFinalizerFromDealloc is undocumented

2017-08-25 Thread Pauli Virtanen

New submission from Pauli Virtanen:

It's unclear if PyObject_CallFinalizerFromDealloc is a public function
or not. It is not documented, but it seems there's no other way to
ensure that tp_finalize runs, at least for objects without 
Py_TPFLAGS_HAVE_GC.

In the documentation of tp_finalize 
(https://docs.python.org/3/c-api/typeobj.html?highlight=tp_finalize#c.PyTypeObject.tp_finalize)
 
there is the sentence:

"""It is called either from the garbage collector (if the instance is
part of an isolated reference cycle) or just before the object is 
deallocated."""

However, it appears it is necessary to call it explicitly from any
user-provided tp_dealloc. Indeed, there are several calls to 
PyObject_CallFinalizerFromDealloc in cpython/Modules/* e.g. in
posixmodule.c:ScandirIterator_dealloc

--
assignee: docs@python
components: Documentation
messages: 300842
nosy: docs@python, pv
priority: normal
severity: normal
status: open
title: PyObject_CallFinalizerFromDealloc is undocumented
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



[issue28261] wrong error messages when using PyArg_ParseTuple to parse normal tuples

2017-08-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Oren, do you mind to backport the part of your changes that adds explicit 
checks for tuples to 3.6 and 2.7? Raising SystemError looks like a bug to me.

--

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

May be make an error message more symmetric to the one in the decoder case?

--

___
Python tracker 

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



[issue28287] Refactor subprocess.Popen to let a subclass handle IO asynchronously

2017-08-25 Thread Martin Richard

Martin Richard added the comment:

Yes, the goal is to isolate the blocking IO in __init__ into other methods so 
Popen can be subclassed in asyncio.

The end goal is to ensure that when asyncio calls Popen(), it doesn't block the 
process. In the context of asyncio, there's no need to make Popen() IOs 
non-blocking as they will be performed with the asyncio API (rather than the IO 
methods provided by the Popen object).

--

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Nick Coghlan

Nick Coghlan added the comment:

The proposed fix looks good to me, but it did make me wonder if we might have a 
missing check in the other direction as well. However, it looks like that case 
is already fine:


```
>>> hex_codec = codecs.lookup("hex")
>>> hex_codec._is_text_encoding = True
>>> t = io.TextIOWrapper(io.BytesIO(b'foo'), encoding="hex")
>>> t.buffer.write(b'abcd')
4
>>> t.read()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: decoder should return a string result, not 'bytes'
```

--

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Nick Coghlan

Changes by Nick Coghlan :


--
versions: +Python 2.7, Python 3.6

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Nick can be interested in this.

--
nosy: +ncoghlan

___
Python tracker 

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



[issue31275] Check fall-through in _codecs_iso2022.c

2017-08-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This looks equivalent to me.

--

___
Python tracker 

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



[issue30923] Add -Wimplicit-fallthrough=0 to Makefile ?

2017-08-25 Thread Stefan Krah

Stefan Krah added the comment:

All warnings except for #31275 are dealt with.

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type:  -> compile error

___
Python tracker 

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



[issue31275] Check fall-through in _codecs_iso2022.c

2017-08-25 Thread Stefan Krah

New submission from Stefan Krah:

The last fall-through warning is in _codecs_iso2022.c. IMO the
current code is equivalent to this, but I'm no codecs expert at
all:


diff --git a/Modules/cjkcodecs/_codecs_iso2022.c 
b/Modules/cjkcodecs/_codecs_iso2022.c
index 1ce4218f30..abf214880f 100644
--- a/Modules/cjkcodecs/_codecs_iso2022.c
+++ b/Modules/cjkcodecs/_codecs_iso2022.c
@@ -807,15 +807,9 @@ jisx0213_encoder(const Py_UCS4 *data, Py_ssize_t *length, 
void *config)
 case 2: /* second character of unicode pair */
 coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
 jisx0213_pair_encmap, JISX0213_ENCPAIRS);
-if (coded == DBCINV) {
-*length = 1;
-coded = find_pairencmap((ucs2_t)data[0], 0,
-  jisx0213_pair_encmap, JISX0213_ENCPAIRS);
-if (coded == DBCINV)
-return MAP_UNMAPPABLE;
-}
-else
+if (coded != DBCINV) {
 return coded;
+/* fall through */
 
 case -1: /* flush unterminated */
 *length = 1;

--
messages: 300834
nosy: haypo, serhiy.storchaka, skrah
priority: normal
severity: normal
status: open
title: Check fall-through in _codecs_iso2022.c

___
Python tracker 

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



[issue30923] Add -Wimplicit-fallthrough=0 to Makefile ?

2017-08-25 Thread Stefan Krah

Stefan Krah added the comment:


New changeset 9e1e6f528f3fec16b9bd99f5ee38048ffec04a81 by Stefan Krah in branch 
'master':
bpo-30923: Silence fall-through warnings in libexpat build. (#3205)
https://github.com/python/cpython/commit/9e1e6f528f3fec16b9bd99f5ee38048ffec04a81


--

___
Python tracker 

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



[issue30923] Add -Wimplicit-fallthrough=0 to Makefile ?

2017-08-25 Thread Stefan Krah

Changes by Stefan Krah :


--
pull_requests: +3242

___
Python tracker 

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



[issue30874] unittest execute tests twice in some conditions

2017-08-25 Thread ale5000

ale5000 added the comment:

hi,
is there any news?

--

___
Python tracker 

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



[issue31254] WeakKeyDictionary/Mapping doesn't call __missing__

2017-08-25 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Antony, if you write (line numbers added for clarity):

1. try:
2.d[obj]
3. except KeyError:
4.d[obj] = some new value...
5. # expect d[obj] to exist at this point

it is possible that d[obj] still exists at line 2 but not anymore at line 5 
(because there would have been a garbage collection run in-between), at least 
if the original key is not `obj` but some other object equal to `obj`.  Using 
setdefault() would ensure that doesn't happen.

--

___
Python tracker 

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



[issue31270] Simplify documentation of itertools.zip_longest

2017-08-25 Thread Raphael Michel

Raphael Michel added the comment:

Well, I could think of a way to still use repeat() here that also is pretty 
clean except for the fact that it fails if all inputs to zip_longest are 
repeat() iterators themselves (which would here lead to an empty iterator while 
it would otherwise lead to an infinite one):

def zip_longest(*args, **kwds):
# zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
fillvalue = kwds.get('fillvalue')
iterators = [iter(it) for it in args]

while True:
values = []

for i, it in enumerate(iterators):
try:
values.append(next(it))
except StopIteration:
values.append(fillvalue)
iterators[i] = repeat(fillvalue)

if all(isinstance(it, repeat) for it in iterators):
break
else:
yield tuple(values)

Keeping chain() in use here just for the sake of using it is not worth it, I 
believe.

--

___
Python tracker 

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



[issue31271] an assertion failure in io.TextIOWrapper.write

2017-08-25 Thread Oren Milman

Oren Milman added the comment:

As Serhiy pointed out on github, the assertion failure can be easily reproduced
by the following:

import codecs
import io

rot13 = codecs.lookup("rot13")
rot13._is_text_encoding = True
t = io.TextIOWrapper(io.BytesIO(b'foo'), encoding="rot13")
t.write('bar')

--

___
Python tracker 

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