[issue44603] REPL: exit when the user types exit instead of asking them to explicitly type exit()

2021-09-24 Thread Vedran Čačić

Vedran Čačić  added the comment:

> why it would be beneficial to have custom handling like this for exit is that 
> exit is a site-builtin, not a builtin.

In my view, that's exactly why it _shouldn't_ have a special treatment. After 
all, site can add many more builtins. Do you want all of them to have autocall?

--

___
Python tracker 

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



[issue44687] io.BufferedReader:peek() closes underlying file, breaking peek/read expectations

2021-09-24 Thread Jun De


Jun De  added the comment:

Awesome! To be honest I was very inclined to add test cases for this edge case, 
but while some existing test cases use native objects like io.BytesIO, the one 
that our edge case uses is HTTPResponse from `urllib3.response.py`. Should I 
still go ahead with writing the test cases in this case? I worry about creating 
new dependencies for the python repository.

--

___
Python tracker 

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



[issue43760] The DISPATCH() macro is not as efficient as it could be (move PyThreadState.use_tracing)

2021-09-24 Thread Guido van Rossum


Guido van Rossum  added the comment:

Ah, I think the docs need to be clarified a bit. Here's what I was missing:

The key thing to know here is that there are *three* state variables; 
`c_tracefunc`, `c_profilefunc` (on the thread state), and `use_tracing` (on the 
C frame).

Normally `use_tracing` is initialized to false if both functions are NULL, and 
true otherwise (if at least one of the functions is set).

*Disabling* means setting `use_tracing` to false regardless. *Resetting* means 
setting `use_tracing` to the value computed above.

There's also a fourth variable, `tstate->tracing`, which indicates whether a 
tracing function is active (i.e., it has been called and hasn't exited yet). 
This can be incremented and decremented. But none of the proposed APIs affect 
it.

Would it be reasonable to just put these APIs in pythoncapi_compat, instead of 
in the stdlib? (It would be yet one more selling point for people to start 
using that. :-)

--

___
Python tracker 

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



[issue45279] avoid redundant _commit_removals pending_removals guard

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Antoine, git blame says you added at least many of the lines Thomas proposes to 
remove.

--
nosy: +pitrou, terry.reedy

___
Python tracker 

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



[issue43914] Highlight invalid ranges in SyntaxErrors

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
pull_requests: +26941
pull_request: https://github.com/python/cpython/pull/28558

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


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



[issue45277] typo in codecs documentation

2021-09-24 Thread miss-islington


miss-islington  added the comment:


New changeset 2a7d985bb3a1d85d63f135956750b330408702e6 by Miss Islington (bot) 
in branch '3.9':
bpo-45277: Fix typo in codecs doc (GH-28555)
https://github.com/python/cpython/commit/2a7d985bb3a1d85d63f135956750b330408702e6


--

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread miss-islington


miss-islington  added the comment:


New changeset 371ca3b54d355476cc735cb932e80f5cd16310da by Miss Islington (bot) 
in branch '3.10':
bpo-45277: Fix typo in codecs doc (GH-28555)
https://github.com/python/cpython/commit/371ca3b54d355476cc735cb932e80f5cd16310da


--

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 3.0 -> 4.0
pull_requests: +26939
pull_request: https://github.com/python/cpython/pull/28556

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread miss-islington


Change by miss-islington :


--
pull_requests: +26940
pull_request: https://github.com/python/cpython/pull/28557

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:


New changeset 4c0fc65cd8a6d4c18330505576ccd4b46abeec1c by Terry Jan Reedy in 
branch 'main':
bpo-45277: Fix typo in codecs doc (GH-28555)
https://github.com/python/cpython/commit/4c0fc65cd8a6d4c18330505576ccd4b46abeec1c


--

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
keywords: +patch
pull_requests: +26938
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28555

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Thanks for the report.  I will fix this.

--
nosy: +terry.reedy

___
Python tracker 

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



[issue45275] Make argparse print description of subcommand when invoke help doc on subcommand

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions:  -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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



[issue45267] New install Python 3.9.7 install of Sphinx Document Generator fails

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
status: open -> closed

___
Python tracker 

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



[issue45020] Freeze all modules imported during startup.

2021-09-24 Thread Eric Snow


Change by Eric Snow :


--
pull_requests: +26937
pull_request: https://github.com/python/cpython/pull/28554

___
Python tracker 

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



[issue45274] Race condition in Thread._wait_for_tstate_lock()

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

> I am not sure that it can be solved at Python level.

Right. In pure Python, we cannot write code which works in all cases. My PR 
28532 fix the most common case: application interrupted by a single CTRL+C.

> with suppress_interrupt(): (...)

It's important to be able to interrupt acquire() which can be called in 
blocking mode with no timeout: it's exactly what tox does, and users expect to 
be able to interrupt tox in this case.

> * Add a Lock method (or just a builtin function) which acquires and 
> immediately releases the lock, without possibility to interrupt.

The acquire()+release() sequence can be made atomic in C, but it doesn't solve 
the problem of _stop() which can be interrupted by a second exception.

This bug is likely as old as Python. I don't think that we should attempt to 
design a perfect solution. I only propose to make the race condition (way) less 
likely.

--

___
Python tracker 

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



[issue45252] Missing support for Source Specific Multicast

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions:  -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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



[issue45254] HAS_SHMEM detection logic is duplicated in implementation and tests

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +davin, pitrou
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



[issue45251] signal.SIGCLD alias is not available on OSX

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions:  -Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

I close the issue.

> bpo-41299: Fix EnterNonRecursiveMutex() (GH-28548)

I don't think that it's worth it to backport this change to 3.9 and 3.10. In 
practice, Py_FatalError() will never be called, and _PyTime_GetMonotonicClock() 
result must always be greater than 0.

But I wanted to remove it in the main branch to reduce the number of functions 
calling Py_FatalError().

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 6bc89116cb121c176453b9745e3daa2cc5df43ab by Victor Stinner in 
branch 'main':
bpo-41299: Mark private thread_nt.h functions as static (GH-28553)
https://github.com/python/cpython/commit/6bc89116cb121c176453b9745e3daa2cc5df43ab


--

___
Python tracker 

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



[issue43760] The DISPATCH() macro is not as efficient as it could be (move PyThreadState.use_tracing)

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

Analysis use use_tracing usage in 3rd part code.

I see two main ways to add C API functions covering these use cases:

* Provide high-level functions like "call a trace function" (disable tracing, 
call trace function, reenable tracing, increment/decrement tstate->tracing)
* Provide low-level functions just to control use_tracing: make PyThreadState 
structure opaque, but stil make the assumption that it is possible to disable 
temporarily tracing and profiling (in practice, it's implemented as 
use_tracing=0).



(*) greenlet

greenlet disables temporarily tracing in g_calltrace(), and then restore it, to 
call a "tracing" function:
---
tstate->tracing++;
TSTATE_USE_TRACING(tstate) = 0;
retval = PyObject_CallFunction(tracefunc, "O(OO)", event, origin, target);
tstate->tracing--;
TSTATE_USE_TRACING(tstate) =
(tstate->tracing <= 0 &&
 ((tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL)));
---

It also saves and then restores use_tracing value:
---
ts__g_switchstack_use_tracing = tstate->cframe->use_tracing;
(...)
tstate->cframe->use_tracing = ts__g_switchstack_use_tracing;
---

=> it can use PyThreadState_IsTracing(), PyThreadState_DisableTracing() and 
PyThreadState_ResetTracing().

These functions don't handle "tstate->tracing++;" and "tstate->tracing--;" 
which is also used by greenlet.

greenlet also saves and restores tstate->cframe:
https://github.com/python-greenlet/greenlet/blob/master/src/greenlet/greenlet.c


(*) dipy

Code generated by Cython.


(*) smartcols

Code generated by Cython.


(*) yappi

yappi is Python profiler.

yappi sets use_tracing to 1 when it sets its profile function: 
"ts->c_profilefunc = _yapp_callback;".

It sets use_tracing to 0 when it clears the profile function: 
"ts->c_profilefunc = NULL;". That's wrong, it ignores the trace function.

PyEval_SetProfile() cannot be used because yappi works on a PyThreadState (ts).

Code: https://github.com/sumerc/yappi/blob/master/yappi/_yappi.c

It can use PyThreadState_DisableTracing() and PyThreadState_ResetTracing(). 
Maybe a PyThreadState_SetProfile(tstate, func) function would fit better 
yappi's use case.


(*) Cython

Cython defines 2 compatibility functions:

* __Pyx_IsTracing(tstate, check_tracing, check_funcs): it can check 
c_profilefunc and c_tracefunc
* __Pyx_SetTracing(tstate, enable)

Code: https://github.com/cython/cython/blob/0.29.x/Cython/Utility/Profile.c

The code is quite complicated. In short, it checks if tracing and/or profiling 
is enabled. If it's enabled, it disables temporarily tracing (use_tracing=0) 
while calling trace and profile functions.

=> it requires PyThreadState_IsTracing(), PyThreadState_DisableTracing() and 
PyThreadState_ResetTracing().

--

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset d639e3170506a1a80c4b2f1b3a6250bb95ff190a by Victor Stinner in 
branch 'main':
bpo-41299: Fix EnterNonRecursiveMutex() (GH-28548)
https://github.com/python/cpython/commit/d639e3170506a1a80c4b2f1b3a6250bb95ff190a


--

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset f35ddf24227e834c9b6b39ad23a0ec382b4de48b by Victor Stinner in 
branch 'main':
bpo-41299: QueryPerformanceFrequency() cannot fail (GH-28552)
https://github.com/python/cpython/commit/f35ddf24227e834c9b6b39ad23a0ec382b4de48b


--

___
Python tracker 

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



[issue44687] io.BufferedReader:peek() closes underlying file, breaking peek/read expectations

2021-09-24 Thread Steve Dower


Steve Dower  added the comment:

That change makes me much happier :)

Do you think we need a specific test added for this case? I'd guess we have 
plenty of coverage for the changed macro already, but clearly nothing that 
showed the issue before.

--

___
Python tracker 

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



[issue44603] REPL: exit when the user types exit instead of asking them to explicitly type exit()

2021-09-24 Thread Filipe Laíns

Filipe Laíns  added the comment:

One technical argument on why it would be beneficial to have custom handling 
like this for exit is that exit is a site-builtin, not a builtin.

$ python -S
Python 3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0] on linux
>>> exit()
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'exit' is not defined
>>> import sys
>>> sys.exit()

--

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26936
pull_request: https://github.com/python/cpython/pull/28553

___
Python tracker 

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



[issue45249] Update doctect SyntaxErrors for location range

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

In 3.10+, end_lineno and end_offset fields were added to SyntaxError objects 
and the args tuple.

>>> try: compile('1 1', '', 'single')
... except SyntaxError as e: print(e.args)
... 
('invalid syntax. Perhaps you forgot a comma?', ('', 1, 1, '1 1', 1, 4))

Here, line 1, offset 4 is the first 1-based column not part of the error.

The builtin default sys.excepthook was modified to read and use this new 
information and mark (end_offset - offset) columns with '^'s.  This default 
prints what it does to sys.stderr.

The syntax error formatting in the traceback module was not altered.  However, 
a new method, TracebackException._format_syntax_error, was extracted from 
TracebackException.format_exception_only so that the former could be overridden 
by software that simulates interaction.

The printed traceback does not come from line 1348.  That *executes* the user 
code, but all Exceptions, including SyntaxError, are caught.  If the exception 
is not expected and the run is not quiet, the exception is output by 
report_unexpected_exception(), as seen above as 'OUTPUT' and the lines that 
follows.
https://github.com/python/cpython/blob/5846c9b71ee9277fe866b1bdee4cc6702323fe7e/Lib/doctest.py#L1264

This calls _exception_traceback(exc_info).
https://github.com/python/cpython/blob/5846c9b71ee9277fe866b1bdee4cc6702323fe7e/Lib/doctest.py#L244
This calls traceback.print_exception, which I believe, for syntax errors, 
ultimately calls TracebackException._format_syntax_error.

I believe that the options for a fix are either
1. Call default sys.excepthook while capturing its output into a StringIO 
instance.
2. Assuming I am correct above about _format_syntax_error being called, 
monkeypatch it.  In line 779,
https://github.com/python/cpython/blob/5846c9b71ee9277fe866b1bdee4cc6702323fe7e/Lib/traceback.py#L779
replace '^' with a field with a calculated number of ^s.

I need to do one of these two for IDLE, and may try both.

--
components: +Library (Lib) -Interpreter Core, Tests
nosy: +terry.reedy
stage:  -> needs patch
title: SyntaxError location range indicator does not work in doctests -> Update 
doctect SyntaxErrors for location range

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26935
pull_request: https://github.com/python/cpython/pull/28552

___
Python tracker 

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



[issue35921] Use ccache by default

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:

It seems to me like the consensus is to not alter CPython's build files because 
ccache is supposed to be used through its `cc`/`gcc` compiler wrappers. Those 
can be provided to a ./configure run either by modifying PATH to include the 
directory with the wrappers or by specifying the CC env var directly to point 
to the ccache wrapper (or "ccache gcc").

Therefore, I'm closing the issue. Antoine, this sat for 2.5 years without 
activity but if you feel strongly about reintroducing the idea, feel free to 
reopen.

--
nosy: +lukasz.langa
resolution:  -> rejected
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



[issue45020] Freeze all modules imported during startup.

2021-09-24 Thread Eric Snow


Eric Snow  added the comment:


New changeset 7c801e0fa603b155eab3fd19698aa90854ac5a7b by Eric Snow in branch 
'main':
bpo-45020: Fix some corner cases for frozen module generation. (gh-28538)
https://github.com/python/cpython/commit/7c801e0fa603b155eab3fd19698aa90854ac5a7b


--

___
Python tracker 

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



[issue45244] pip not installed with fresh python3.8.10 installation

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

If you installed 'py' (the default), you should be able to install pip with 'py 
-3.8 -m ensurepip'.  (I had to do this once.  I wrote the failure off as a 
random glitch and did not think to open an issue.)

--
nosy: +terry.reedy

___
Python tracker 

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



[issue45285] c_char incorrectly treated as bytes in Structure

2021-09-24 Thread Eryk Sun


Eryk Sun  added the comment:

A simple ctypes type implements a get function that's called when its value is 
returned as an attribute of struct/union, index of an array/pointer, or result 
of a function pointer. For example:

>>> a = (ctypes.c_char * 1)(97)
>>> a[0]
b'a'

>>> p = ctypes.POINTER(ctypes.c_char)(a)
>>> p[0]
b'a'

This behavior can't be changed. However, using a subclass of c_char works 
around it. For example:

>>> class my_char(ctypes.c_char): pass
... 

>>> a = (my_char * 1)(97)
>>> a[0]

>>> a[0].value
b'a'

>>> p = ctypes.POINTER(my_char)(a)
>>> p[0]

>>> p[0].value
b'a'

--
nosy: +eryksun

___
Python tracker 

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



[issue41914] test_pdb fails

2021-09-24 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

Léon's message from #45242, which I closed as a duplicate of this.

Leon: please try with 3.11 (best, repository main), 3.10, or at least 3.9.  3.8 
and before only get security fixes.
---

Building Python 3.7, I ran into the same issue reported [here] (only line 
numbers differ):

==
FAIL: test_errors_in_command (__main__.PdbTestCase)
--
Traceback (most recent call last):
  File "Lib/test/test_pdb.py", line 1535, in test_errors_in_command
'(Pdb) ',
AssertionError: Lists differ: ['(Pd[283 chars]efined", 'LEAVING RECURSIVE 
DEBUGGER', '(Pdb) ', '\x1b[?1034h'] != ['(Pd[283 chars]efined", 'LEAVING 
RECURSIVE DEBUGGER', '(Pdb) ']

First list contains 1 additional elements.
First extra element 9:
'\x1b[?1034h'

  ['(Pdb) *** SyntaxError: unexpected EOF while parsing',
   '(Pdb) ENTERING RECURSIVE DEBUGGER',
   '*** SyntaxError: unexpected EOF while parsing',
   'LEAVING RECURSIVE DEBUGGER',
   '(Pdb) ENTERING RECURSIVE DEBUGGER',
   '> (1)()',
   "((Pdb)) *** NameError: name 'doesnotexist' is not defined",
   'LEAVING RECURSIVE DEBUGGER',
-  '(Pdb) ',
?  ^

+  '(Pdb) ']
?  ^

-  '\x1b[?1034h']

--
Ran 39 tests in 1.024s

FAILED (failures=1)


I have also managed to determine the cause.  As can be seen, the output from 
this pdb invocation contains an extraneous ANSI control sequence ("interpret 
"meta" key, set eighth bit"). This happens when running the test inside the GNU 
`screen` environment.  Run the test outside `screen`, and the problem goes away.

(By the way, this was the only test that failed when running `make test` inside 
the `screen` environment.)

--
nosy: +terry.reedy
resolution: works for me -> 

___
Python tracker 

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



[issue45242] test_pdb fails

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> test_pdb fails

___
Python tracker 

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



[issue45240] Add +REPORT_NDIFF option to pdb tests that use doctest

2021-09-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Lukasz, there is no current doctest expert and I think that this is something 
you could either accept or reject fairly quickly.  Since the enhancement is to 
the tests, it could be backported.

--
nosy: +lukasz.langa, terry.reedy

___
Python tracker 

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



[issue45285] c_char incorrectly treated as bytes in Structure

2021-09-24 Thread CireSnave


New submission from CireSnave :

When dealing with a Structure containing c_char variables, the variables are 
incorrectly being typed as bytes.  As a result, a pointer to those c_char 
variables can not be created because bytes is not a ctypes type.

from ctypes import (
Structure,
c_char,
pointer,
)


class MyStruct(Structure):
_fields_ = [("a", c_char), ("b", c_char), ("c", c_char)]


x: MyStruct = MyStruct(98, 99, 100)

print(type(x.a))
# Prints  ???  Both mypy and PyRight agree that x.a is a c_char.

some_variable = pointer(x.a)
# Traceback (most recent call last):
#   File "C:\Users\cires\ctypes_test.py", line 23, in 
# some_variable = pointer(x.a)
# TypeError: _type_ must have storage info

--
components: ctypes
messages: 402582
nosy: ciresnave
priority: normal
severity: normal
status: open
title: c_char incorrectly treated as bytes in Structure
type: behavior
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



[issue44687] io.BufferedReader:peek() closes underlying file, breaking peek/read expectations

2021-09-24 Thread Jun De


Jun De  added the comment:

Yeap Steve, I was thinking the same thing. I've taken the buffered data into 
consideration when checking if the file is closed in my fix, feel free to take 
a look and let me know what you think :)

--

___
Python tracker 

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



[issue44019] operator.call/operator.__call__

2021-09-24 Thread Mark Dickinson


Mark Dickinson  added the comment:


New changeset bfe26bbad787c124f0ce144cff1b513ef9d2dc9c by Terry Jan Reedy in 
branch 'main':
bpo-44019: Add missing comma to operator.call doc (GH-28551)
https://github.com/python/cpython/commit/bfe26bbad787c124f0ce144cff1b513ef9d2dc9c


--

___
Python tracker 

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



[issue35077] Make TypeError message less ambiguous

2021-09-24 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

https://bugs.python.org/issue44110 did some improvements to error message to 
include type.

--

___
Python tracker 

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



[issue45284] Better `TypeError` message when a string is indexed using a non int

2021-09-24 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

See also https://bugs.python.org/issue44110 . This looks like a duplicate. Also 
https://bugs.python.org/issue35077

--
nosy: +xtreak

___
Python tracker 

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



[issue45284] Better `TypeError` message when a string is indexed using a non int

2021-09-24 Thread Rin RIn


Change by Rin RIn :


--
title: Better `TypeError` message when a string is indexed using a string -> 
Better `TypeError` message when a string is indexed using a non int

___
Python tracker 

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



[issue44019] operator.call/operator.__call__

2021-09-24 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +terry.reedy
nosy_count: 6.0 -> 7.0
pull_requests: +26934
pull_request: https://github.com/python/cpython/pull/28551

___
Python tracker 

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



[issue45284] Better `TypeError` message when a string is indexed using a string

2021-09-24 Thread Ganesh Kumar


New submission from Ganesh Kumar :

The `TypeError` message when a string is indexed using a string should be 
similar to the `TypeError` message when a list or tuple is indexed using a 
string.

>>> my_str = 'Rin'
>>> my_str[1:3]  # works
'in'
>>> my_str['no']
Traceback (most recent call last):
  File "", line 1, in 
TypeError: string indices must be integers

>>> my_str[slice(1, 3)]  # works with slices
'in'

Certainly it does work with slice as intended but the error message should 
explain that, as seen in the following

>>> my_list = [1, 2, 3]
>>> my_list['no']
Traceback (most recent call last):
  File "", line 1, in 
TypeError: list indices must be integers or slices, not str

>>> my_tuple = (1, 2, 3)
>>> my_tuple['no']
Traceback (most recent call last):
  File "", line 1, in 
TypeError: tuple indices must be integers or slices, not str

The error message shows `slices` are indeed an option to use when indexing a 
list or tuple.

Would be happy to submit a documentation PR if this minor change would be 
accepted.

--
components: Library (Lib)
messages: 402577
nosy: Rin
priority: normal
severity: normal
status: open
title: Better `TypeError` message when a string is indexed using a string
type: enhancement
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



[issue45211] Useful (expensive) information is discarded in getpath.c.

2021-09-24 Thread Eric Snow


Change by Eric Snow :


--
keywords: +patch
pull_requests: +26933
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/28550

___
Python tracker 

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



[issue40699] Memory leak in threading library with Python 3.6-3.8

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

I fail to reproduce the leak using attached script.

I close the issue.

I get constant memory usage on Linux with the main branch of Python (future 
3.11):

(...)
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
VmRSS: 11344 kB
(...)

--
nosy: +vstinner
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
Added file: https://bugs.python.org/file50304/script.py

___
Python tracker 

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



[issue40657] Resource leaks with threading.Thread

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

You must join thread using thread.join().

If I add .join() calls, threading.active_count() stays around 2, it doesn't 
grow.

It's not a bug in Python.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue45218] cmath.log has an invalid signature

2021-09-24 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +corona10

___
Python tracker 

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



[issue45272] 'os.path' should not be a frozen module

2021-09-24 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +corona10

___
Python tracker 

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



[issue43050] threading timer memory leak

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

I cannot reproduce the issue. IMO it has been fixed.

Moreover, you must join timers using timer.join(): a timer remains a thread.

Code:
---
import os
import threading
os.system(f"grep ^VmRSS /proc/{os.getpid()}/status")
# warmup
for n in range(10):
timer = threading.Timer(5, None)
timer.start()
timer.cancel()
timer.join()
os.system(f"grep ^VmRSS /proc/{os.getpid()}/status")
for n in range(1000):
timer = threading.Timer(5, None)
timer.start()
timer.cancel()
timer.join()
os.system(f"grep ^VmRSS /proc/{os.getpid()}/status")
---

Output on Linux with the main branch of Python (3.11):
---
VmRSS: 10924 kB
VmRSS: 11104 kB
VmRSS: 11104 kB
---

--
nosy: +vstinner
resolution: duplicate -> fixed
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



[issue1596321] KeyError at exit after 'import threading' in other thread

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

I proposed PR 28549 to fix this very old threading issue.

A C extension can spawn threads without using the threading module and then 
then run Python code which imports the threading module. In this case, 
threading._main_thread is the thread which imported first the threading module. 
My PR changes so threading._shutdown() simply ignores _main_thread when it 
happens.

--

___
Python tracker 

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



[issue1596321] KeyError at exit after 'import threading' in other thread

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
keywords: +patch
nosy: +vstinner
nosy_count: 14.0 -> 15.0
pull_requests: +26932
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/28549

___
Python tracker 

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



[issue44019] operator.call/operator.__call__

2021-09-24 Thread Mark Dickinson


Mark Dickinson  added the comment:

Thanks for the contribution!

--
stage: patch review -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

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



[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

2021-09-24 Thread Jeremy Maitin-Shepard


Jeremy Maitin-Shepard  added the comment:

To be clear, the problem I'm trying to address here is not specific to 
embedding Python in a C++ application.  In fact the issue came to my attention 
while using Python directly, but loading an extension module that was written 
in C++ using the popular pybind11 library.

If we continue having Python call `pthread_exit` and `_endthreadex`, we are 
imposing strong constraints on call stacks that call the Python API.  Granted, 
hanging a thread is also not something a well-behaved library should do, but it 
is at least slightly better than killing the thread.  In a sense hanging is 
also logical, since the thread has requested to block until the GIL can be 
acquired, and the GIL cannot be acquired.

I have described a number of problems caused by `pthread_exit`/`_endthreadex` 
that are fixed by hanging.  Can you help me understand what problems caused by 
hanging are fixed by `pthread_exit`/`_endthreadex`, that leads you to think it 
is a better default?

--

___
Python tracker 

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



[issue44019] operator.call/operator.__call__

2021-09-24 Thread Mark Dickinson


Mark Dickinson  added the comment:


New changeset 6587fc60d447603fb8c631d81d9bb379f53c39ab by Antony Lee in branch 
'main':
bpo-44019: Implement operator.call(). (GH-27888)
https://github.com/python/cpython/commit/6587fc60d447603fb8c631d81d9bb379f53c39ab


--

___
Python tracker 

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



[issue20524] format error messages should provide context information

2021-09-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

Thanks for the improvement, @sobolevn!

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



[issue20524] format error messages should provide context information

2021-09-24 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset 8d8729146f21f61af66e70d3ae9501ea6bdccd09 by Nikita Sobolev in 
branch 'main':
bpo-20524: adds better error message for `.format()` (GH-28310)
https://github.com/python/cpython/commit/8d8729146f21f61af66e70d3ae9501ea6bdccd09


--

___
Python tracker 

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



[issue45282] isinstance(x, typing.Protocol-class) unexpectedly evaluates properties

2021-09-24 Thread Alex Waygood


Alex Waygood  added the comment:

Related: https://bugs.python.org/issue44904

--
nosy: +AlexWaygood

___
Python tracker 

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



[issue45267] New install Python 3.9.7 install of Sphinx Document Generator fails

2021-09-24 Thread Paul Broe


Paul Broe  added the comment:

Good Morning:

I was able to resolve the issue based on your assistance.  I created this
topic at github.com

https://github.com/sphinx-doc/sphinx/issues/9669

Someone answered it and it was simple:

Thank you so much. That was it. I thought it was looking for a package but I
completely missed the fact that the package name was package. I can't
connect to the internet from my machines. So, I have to download everything
manually from PyPI.

I added packages pyparsing and packaging ...
And

Building wheels for collected packages: sphinx
Building wheel for sphinx (setup.py) ... done
Created wheel for sphinx: filename=Sphinx-4.2.0-py3-none-any.whl
size=3061858
sha256=c5b28f87749557dc8c06b9820c748d6c5e764e32f2f25620d08b3259993ea90a
Stored in directory:
/usr/opt/oracle/.cache/pip/wheels/31/d2/bc/aa1cbddf1cd38373f4632ab20b0e3400f
037bcf271b50b2397
Successfully built sphinx
Installing collected packages: sphinx
Successfully installed sphinx-4.2.0

You can close the issue.. It was not a python bug

--
status: pending -> open

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

Calling Py_FatalError() must be avoided by any mean. I spent significant time 
to remove Py_FatalError() at Python startup in my PEP 587 implementation: 
https://www.python.org/dev/peps/pep-0587/

I also removed Py_FatalError() calls to report errors to the caller: 
https://bugs.python.org/issue38631

Calling Py_FatalError() is really bad when Python is embedded in an 
application. It kills the whole process, the caller has no way to catch the 
error.

--

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

I created PR #28548 to remove the Py_FatalError() code path.

--

___
Python tracker 

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



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26931
pull_request: https://github.com/python/cpython/pull/28548

___
Python tracker 

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



[issue45283] Top / function argument level ClassVar should not be allowed during `get_type_hints()`

2021-09-24 Thread Nikita Sobolev


New submission from Nikita Sobolev :

This code currently does not raise any issues:

```python
# contents of `ex.py`
from typing import ClassVar

a: ClassVar[int] = 1
def b(c: ClassVar[int]): ...
```

And then: 
1. Module: `python -c 'import ex; from typing import get_type_hints; 
print(get_type_hints(ex))'`
2. Function argument: `python -c 'import ex; from typing import get_type_hints; 
print(get_type_hints(ex.b))'`

It should not be allowed. Currently, the same with `from __future__ import 
annotations` does correctly raise `TypeError: typing.ClassVar[int] is not valid 
as type argument`

Related: https://github.com/python/cpython/pull/28279

I will send a PR with the fix shortly.

--
components: Library (Lib)
messages: 402563
nosy: sobolevn
priority: normal
severity: normal
status: open
title: Top / function argument level ClassVar should not be allowed during 
`get_type_hints()`
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue45282] isinstance(x, typing.Protocol-class) unexpectedly evaluates properties

2021-09-24 Thread Daisuke Takahashi


New submission from Daisuke Takahashi :

Because __instancecheck__ of _ProtocolMeta uses hasattr() and getattr(), both 
of which evaluate property attributes, calling isinstance() with an object and 
a class that inherits typing.Protocol evaluates the input object's properties 
in some cases.

The attached testcases include three cases of checking subtype relationship of 
an instance (having a property "x" that may raise RuntimeError on evaluation) 
and following three protocol classes;
  (1) a protocol class having "x" as a property,
  (2) a protocol class having "x" as a data attribute, and
  (3) a protocol class having "x" as a class property that raises
   RuntimeError on evaluation (>= python 3.9 only).

Expected behavior:
1. The isinstance(obj, Protocol_class) does not evaluate anything but just 
checks existence of attribute names.
2. All cases in the attached testcases run without any error

Thank you very much in advance.

--
files: test_protocol_property.py
messages: 402562
nosy: daitakahashi
priority: normal
severity: normal
status: open
title: isinstance(x, typing.Protocol-class) unexpectedly evaluates properties
type: behavior
versions: Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50303/test_protocol_property.py

___
Python tracker 

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



[issue45281] Make `is_attribute` and `module` arguments to `ForwardRef` kw-only

2021-09-24 Thread Nikita Sobolev


New submission from Nikita Sobolev :

After https://github.com/python/cpython/pull/28279 and 
https://bugs.python.org/issue45166 `ForwardRef` and `_type_check` now have 
`is_class` kw-only argument.

It is now inconsistent with `is_argument` and `module` arguments.
It would be quite nice to make them all kw-only.

Quoting @ambv:

> _type_check we can just change in Python 3.11 without any further ado. 
> ForwardRef() will need a deprecation period when the users is calling 
> is_argument= and module= as non-keyword arguments

--
components: Library (Lib)
messages: 402561
nosy: sobolevn
priority: normal
severity: normal
status: open
title: Make `is_attribute` and `module` arguments to `ForwardRef` kw-only
type: behavior
versions: Python 3.11

___
Python tracker 

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



[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

Jeremy Maitin-Shepard: "In general, I view hanging threads as the least bad 
thing to do when faced with either acquiring the GIL or not returning at all.  
There is a lot of existing usage of Python that currently poses a risk of 
random crashes and memory corruption while Python is exiting, and I would like 
to fix that."

Showing warnings by default or not was discussed many times in Python. It was 
decided to *hide* DeprecationWarning by default. The PEP 565 is a minor 
trade-off to show them in the __main__ module.

For me, more generally, Python default behavior is designed for *users* who 
don't want to be annoyed by warnings or anything which would make sense for 
*developers*. That's why I designed a new "Python Development Mode" (-X dev):
https://docs.python.org/dev/library/devmode.html

Maybe in development mode, the behavior could be changed to call abort(). But 
honestly, I'm not really excited by that. I'm not embedding Python in a C++ 
application. I'm almot only use Python directly: the Unix command "python3". 
For this use case, IMO it's fine to call pthread_exit() by default.

--

___
Python tracker 

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



[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

Another example where a developer asks to call abort() to notice bugs, whereas 
Python previously silently ignored it: bpo-36829. Calling abort() is a legit 
use case, but not really the best default behavior. Again, the problem was 
solved by letting developers setting their own callback: sys.unraisablehook.

If I understood correctly, pytest doesn't override it but "took" into the 
default implementation: it chains its own code with the default implementation. 
It's possible because there is a way to "get" the current hook: just read 
sys.unraisablehook ;-)

Another argument in favor of also adding Py_GetThreadExitCallback() ;-)

--

___
Python tracker 

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



[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

Gregory P. Smith: Python has many API using callbacks:

PEP 445 added PyMem_SetAllocator() to set memory allocator. Adding 
PyMem_GetAllocator() also made possible to chain allocators and to "hook" into 
an existing allocator to execute code before and after it's called (the PEP 
contains an example).

I'm not sure if it's important or useless to chain callbacks with 
Py_SetThreadExitCallback(). I suggest to always override the previously set 
callback.

It would matter if library A sets a callback to emit log and library B sets a 
callback to hang threads. It maybe be nice to first emit a log and then hang 
the thread. But then the order in which callbacks are set starts to matter a 
lot :-)

I'm fine with adding Py_GetThreadExitCallback() if you consider that it matters.


> If someone passes nullptr does that undo it (please no!).

I don't think that we should bother with adding a special case. I prefer to 
consider developers as adults and let them make their own mistakes if they 
consider that they understand the code well enough ;-)

_PyEval_SetTrace() allows to remove the current trace function. It's a legit 
use case.

If library C is annoyed by library A and library B installed annoying 
callbacks, IMO it's also ok to let it "remove" the previously set callback, no?

IMO Py_SetThreadExitCallback(NULL) should simply set the callback to NULL, so 
restore the default behavior: call pthread_exit().

--

___
Python tracker 

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



[issue45280] Empty typing.NamedTuple creation is not tested

2021-09-24 Thread Nikita Sobolev


New submission from Nikita Sobolev :

While working on `mypy` support of `NamedTuple`s 
(https://github.com/python/mypy/issues/11047), I've noticed that currently when 
testing `typing.NamedTuple` cases like:

1. `N = NamedTuple('N')`

and

2.

```python
class N(NamedTuple):
...
```

are ignored. 

However, this is an important corner-cases, we need to be sure that use can 
create empty named tuples if needed.

Related position in code: 
https://github.com/python/cpython/blob/3f8b23f8ddab75d9b77a3997d54e663187e12cc8/Lib/test/test_typing.py#L4102-L4114

I will send a PR add these two cases.

--
components: Tests
messages: 402557
nosy: sobolevn
priority: normal
severity: normal
status: open
title: Empty typing.NamedTuple creation is not tested
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

2021-09-24 Thread STINNER Victor


STINNER Victor  added the comment:

> In this case that unexpected thread simply disappearing can lead to a 
> deadlock in our process.

This problem also remains me the very complex case of bpo-6721: "Locks in the 
standard library should be sanitized on fork". The issue title looks simple, 
but 12 years after the issue was created, it's still open.

This issue is being solved by adding atfork callbacks to modules which must do 
something at fork in the child process (sometimes also in the parent process).

I added threading.Lock._at_fork_reinit() private method to simplify the 
implementation of these callbacks.

Such problem has no silver bullet solution, so it's better to let developers 
design their own solution with their specific requirements.

--

___
Python tracker 

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



[issue45026] More compact range iterator

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:

Serhiy, right: looks like the difference stems from recreating the range 
objects, not from iteration. But Dennis' observation still stands: using `for i 
in range(...):` is a very popular idiom. If that becomes slower than the status 
quo, we will be making existing Python programs slower as well.

--

___
Python tracker 

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



[issue45279] avoid redundant _commit_removals pending_removals guard

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +26930
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28546

___
Python tracker 

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



[issue45279] avoid redundant _commit_removals pending_removals guard

2021-09-24 Thread Thomas Grainger


New submission from Thomas Grainger :

refactor to avoid redundant _commit_removals pending_removals guard

--
components: Library (Lib)
messages: 402554
nosy: graingert
priority: normal
severity: normal
status: open
title: avoid redundant _commit_removals pending_removals guard
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue45278] RuntimeError on race on weakset concurrent iteration

2021-09-24 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
components: +Library (Lib)
nosy: +fdrake, pitrou, serhiy.storchaka
versions: +Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue45278] RuntimeError on race on weakset concurrent iteration

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert

___
Python tracker 

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



[issue45278] RuntimeError on race on weakset concurrent iteration

2021-09-24 Thread Ben


New submission from Ben :

This is a very subtle race

WeakSet uses _weakrefset.py's _IterationGuard structure to protect against the 
case where the elements the WeakSet refers to get cleaned up while a thread is 
iterating over the WeakSet.

It defers the actual removal of any elements which get gc'd during iteration 
until the end of the iteration.

the WeakSet keeps track of all the iterators, and waits until there are no more 
threads iterating over the set before it does the removal: 
https://github.com/python/cpython/blob/main/Lib/_weakrefset.py#L30

However there is a race, if another thread begins iterating after the `if s:` 
check but before the _commit_removals call has ended, that iteration can get a 
RuntimeError.

attached is an example script that can generate such RuntimeError's,
although the race window here is very small and so to observe yourself you may 
have to tweak the magic constants around.

As far as I'm aware nobody has reported seeing this bug happen in production,  
but some libraries (e.g. asyncio) do currently rely on concurrently iterating a 
weakset, so it's not implausible.

--
files: weakset_concurrent_iter_runtimeerror.py
messages: 402553
nosy: bjs
priority: normal
severity: normal
status: open
title: RuntimeError on race on weakset concurrent iteration
type: behavior
Added file: 
https://bugs.python.org/file50302/weakset_concurrent_iter_runtimeerror.py

___
Python tracker 

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



[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26929
pull_request: https://github.com/python/cpython/pull/28545

___
Python tracker 

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



[issue45213] Frozen modules are looked up using a linear search.

2021-09-24 Thread Dong-hee Na


Dong-hee Na  added the comment:

> Then we can at least bail out of the loop early, and one day someone could 
> make it a binary search.

I like this idea if we can guarantee the order :)

--

___
Python tracker 

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



[issue15870] PyType_FromSpec should take metaclass as an argument

2021-09-24 Thread Petr Viktorin


Petr Viktorin  added the comment:

> But at least if it's available as a slot then a module is *able* to use it 
> with limited ABI going backwards. A new function doesn't allow that.

I think you're confusing PyType_Slot with the tp_* members of type structures.  
If a Py_tp_meta is added, it won't appear in past versions. See the end of 
Include/typeslots.h.
(Sadly, they're both called "slots".)

> Bases are available both as a slot (Py_tp_bases) and as an argument 
> (PyType_FromSpecWithBases).  I don't see why this has to be an either/or 
> proposition.  Both can be useful.

I consider Py_tp_bases to be a mistake: it's an extra way of doing things that 
doesn't add any extra functionality, but is sometimes not correct (and it might 
not be obvious when it's not correct).

> Either would satisfy my use case.

So let's go for the one that isn't a trap in the other use cases :)

--

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:

Thanks, Alex! ✨ 🍰 ✨

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type:  -> behavior
versions: +Python 3.10, Python 3.11 -Python 3.8

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 402d5f3d77684c91ad02a2ab5223673bec5f1602 by Miss Islington (bot) 
in branch '3.10':
bpo-30951: Correct co_names docstring in inspect module (GH-2743) (GH-28543)
https://github.com/python/cpython/commit/402d5f3d77684c91ad02a2ab5223673bec5f1602


--

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 91a5ba1bcb24c87a82c1417b1e5df57c89cbd3e0 by Miss Islington (bot) 
in branch '3.9':
bpo-30951: Correct co_names docstring in inspect module (GH-2743) (GH-28544)
https://github.com/python/cpython/commit/91a5ba1bcb24c87a82c1417b1e5df57c89cbd3e0


--

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 8.0 -> 9.0
pull_requests: +26927
pull_request: https://github.com/python/cpython/pull/28543

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread miss-islington


Change by miss-islington :


--
pull_requests: +26928
pull_request: https://github.com/python/cpython/pull/28544

___
Python tracker 

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



[issue30951] Documentation error in inspect module

2021-09-24 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 3f8b23f8ddab75d9b77a3997d54e663187e12cc8 by Alex Vig in branch 
'main':
bpo-30951: Correct co_names docstring in inspect module (GH-2743)
https://github.com/python/cpython/commit/3f8b23f8ddab75d9b77a3997d54e663187e12cc8


--
nosy: +lukasz.langa

___
Python tracker 

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



[issue43760] The DISPATCH() macro is not as efficient as it could be (move PyThreadState.use_tracing)

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26926
pull_request: https://github.com/python/cpython/pull/28542

___
Python tracker 

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



[issue45256] Remove the usage of the C stack in Python to Python calls

2021-09-24 Thread Christian Tismer


Christian Tismer  added the comment:

FYI., in Stackless Python I built a chain of frames by a double linked list. 
This was the replacement for the current frame/stack mix.
Debugging was still quite easy, following this frame chain.

Note that it is a rather easy step to add the capability to squirrel the whole 
current chain away and replace it by another one. Add some header to such a 
chain, and you can call it "Tasklet".

--

___
Python tracker 

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



[issue45277] typo in codecs documentation

2021-09-24 Thread HugoThiolliere

New submission from HugoThiolliere :

There is a typo in 
https://docs.python.org/3/library/codecs.html#encodings-and-unicode

The first sentence in the last paragraph before the table reads : "There’s 
another encoding that is able to encoding the full range of Unicode characters"

When it should read "There’s another encoding that is able to encode the full 
range of Unicode characters"

--
assignee: docs@python
components: Documentation
messages: 402545
nosy: Gronahak, docs@python
priority: normal
severity: normal
status: open
title: typo in codecs documentation
type: enhancement
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



[issue45276] avoid try 1000 in asyncio all_tasks by making weak collection .copy() atomic

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +26925
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28541

___
Python tracker 

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



[issue45274] Race condition in Thread._wait_for_tstate_lock()

2021-09-24 Thread Eryk Sun


Change by Eryk Sun :


--
nosy: +eryksun

___
Python tracker 

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



[issue45276] avoid try 1000 in asyncio all_tasks by making weak collection .copy() atomic

2021-09-24 Thread Thomas Grainger


New submission from Thomas Grainger :

the weak collections should have the same threadsafe/thread unsafe guarantees 
as their strong reference counterparts - eg dict.copy and set.copy are atomic 
and so the weak versions should be atomic also

--
components: Interpreter Core, asyncio
messages: 402544
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: avoid try 1000 in asyncio all_tasks by making weak collection .copy() 
atomic
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue45269] c_make_encoder() has uncovered error: "argument 1 must be dict or None"

2021-09-24 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
keywords: +patch
pull_requests: +26924
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28540

___
Python tracker 

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



[issue45026] More compact range iterator

2021-09-24 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I do not see any difference in iterating small integers:

$ ./python -m pyperf timeit -s 'r = range(1)' 'for i in r: pass'
PR 27986: Mean +- std dev: 174 us +- 9 us
PR 28176: Mean +- std dev: 172 us +- 10 us

--

___
Python tracker 

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