[issue37812] Make implicit returns explicit in longobject.c (in CHECK_SMALL_INT)

2019-09-19 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I'm unassigning this.  It has been blown profoundly out of proportion.  The 
recommendation of the senior most developer is being ignored, and now two 
developers are speaking in terms of strong belief systems and labeling 
long-stable code as "evil".  This doesn't bode well and it makes it difficult 
to conduct reasoned discourse.  

(Meanwhile, we have another have another long-term active developer who 
routinely adds new macros to existing code because he thinks that is an 
improvement. That portends a pointless tug-of-war predicated almost solely in 
not liking how other people code).

--
assignee: rhettinger -> 

___
Python tracker 

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



[issue37224] test__xxsubinterpreters failed on AMD64 Windows8.1 Refleaks 3.8

2019-09-19 Thread Kyle Stanley

Kyle Stanley  added the comment:

Is there a currently reliable way of accessing the GIL functions within the 
sub-interpreters, without causing deadlock issues? I was trying to follow the 
advice in the documentation 
(https://docs.python.org/3/c-api/init.html?highlight=global%20interpreter%20lock#bugs-and-caveats).

"It is highly recommended that you don’t switch sub-interpreters between a pair 
of matching PyGILState_Ensure() and PyGILState_Release() calls."

But it seemed that any attempt to use any of the PyGIL* calls within 
``interp_destroy()`` in a meaningful way resulted in a deadlock, even if it was 
done away from the sub-interpreter switching.

My next idea would be to add a conditional check to see if the current thread 
has ownership of the GIL, and using ``PyEval_RestoreThread()`` to acquire it if 
it doesn't. This would be followed by releasing the GIL with 
``PyThreadState_Get()`` at the end of the function. I'll try experimenting with 
that idea next.

--

___
Python tracker 

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



[issue37812] Make implicit returns explicit in longobject.c (in CHECK_SMALL_INT)

2019-09-19 Thread Greg Price


Greg Price  added the comment:

I hesitate to come back to this thread, because as Raymond says it's consumed a 
lot of time already.  But I think this point is of broader interest than the 
specific few lines we've been discussing:

> When small integer are disabled at compilation time (NSMALLPOSINTS=0 and  a 
> NSMALLNEGINTS=0), I suggest to remove code related to small integers. IMHO 
> CHECK_SMALL_INT() macro is a good practical solution for that.

Victor, can you be more specific about the problem this is solving? I think the 
existing code in master really doesn't leave any problems in place that 
CHECK_SMALL_INT solves.

In master (as of 2702638ea), here's the code that CHECK_SMALL_INT would replace:

if (IS_SMALL_INT(ival)) {
return get_small_int((sdigit)ival);
}

When NSMALLPOSINTS=0 and NSMALLNEGINTS=0 , this expands in the preprocessor to 
the equivalent of:

if (0) {
return (Py_UNREACHABLE(), NULL);
}

(Specifically, it expands to whatever that expands to, since Py_UNREACHABLE and 
possibly NULL are also macros.)

A compiler that's attempting to do any significant optimization at all has to 
be able to discard code that's inside `if (0)`; dead-code elimination is a 
necessary primitive for lots of other optimizations.

(And at a quick empirical sanity-check: gcc, clang, and msvc all do so at any 
optimization setting other than "disabled".  In fact gcc and clang do so even 
with optimizations disabled.)


You made the case very nicely above that macros are evil.  The IS_SMALL_INT 
macro is fairly mild, and it has a performance benefit on some platforms to 
justify it.  But CHECK_SMALL_INT causes a return from the enclosing function, 
which seems quite high on the "evil macro" scale.

--

___
Python tracker 

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



[issue37812] Make implicit returns explicit in longobject.c (in CHECK_SMALL_INT)

2019-09-19 Thread Kyle Stanley


Kyle Stanley  added the comment:

> I'm one of the first to advocate to replace ugly macros with clean static 
> inline functions. Macros are evil and can be too easily misused.

As someone who has only more recently started learning the C-API (and C in 
general), I'm certainly in favor of replacing macros with functions when 
possible. I might be a bit biased, but it definitely makes the code a lot 
easier to understand (especially the macros with implicit returns). As long as 
there's not a significant performance loss and it doesn't introduce new 
complications, I don't see an issue with it.

>From my understanding, readability isn't as high of a priority in the C code, 
>but certainly there's some benefit to improving areas that are more difficult 
>to understand. The easier the code is to understand, the lower the overall 
>maintenance cost becomes.

Of course, this should certainly be done in moderation to reduce the 
introduction of unnecessary new bugs and the cost in reviewer time for more 
pressing concerns.

--

___
Python tracker 

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



[issue38216] Fix for issue30458 prevents crafting invalid requests

2019-09-19 Thread Ammar Askar


Ammar Askar  added the comment:

> What bothers me here is that we apparently changed de facto behavior between 
> maintenance releases, in the middle of 3.7's lifecycle, without warning, no 
> doubt because we didn't realize it would break third-party packages.

Arguably, I think the programs that are affected by this vulnerability far 
outnumber the amount of third-party packages that will be broken. The trade-off 
here seems to be between the promise of compatibility and the promise of 
security, choosing compatibility strikes me as odd.

--
nosy: +ammar2

___
Python tracker 

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



[issue38225] iscoroutinefunction broken with cython - allow tagging of functions as async?

2019-09-19 Thread Stefan Behnel

Stefan Behnel  added the comment:

My usual first reaction is: "if you need to find out whether the return value 
of a callable will be an Awaitable or not, without calling it, then you're 
probably doing something wrong in your design".

However,
a) there is code that tries this already (and it falls short in various ways 
while trying)
b) asyncio has a function `iscoroutinefunction` which *seems* to fulfil this 
need but does not achieve it (because not everything that returns an Awaitable 
is a "coroutine function")
c) asyncio has an internal protocol for marking things as "is a coroutine", 
which comes close to but isn't "returns an Awaitable when called"

So – should there be an official protocol for marking callables as returning an 
Awaitable? Should we look at annotations for that? Anything else? Or do we 
consider this intention inherently flawed?

--

___
Python tracker 

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



[issue38216] Fix for issue30458 prevents crafting invalid requests

2019-09-19 Thread Ned Deily

Ned Deily  added the comment:

Thanks for your comments, Greg.  Here's my take as release manager for 3.7 (and 
for 3.6).  What bothers me here is that we apparently changed de facto behavior 
between maintenance releases, in the middle of 3.7's lifecycle, without 
warning, no doubt because we didn't realize it would break third-party 
packages.  But it has and that's a big no-no.  A very important part of our 
maintenance strategy is that we implicitly promise our users that they can 
easily upgrade from any older release in a release family to the most current 
release without fear of incompatibilities (e.g. 3.7.0 to 3.7.4).  In return for 
that, we will only provide fixes for the most recent maintenance release in a 
family (e.g. once 3.7.5 is released, 3.7.4 is dead and 2.7.3 through 3.7.0 were 
already dead).  So it seems here we have violated that compatibility promise 
for 3.7 and 3.6 and are about to do so for 3.5 and 2.7.  Since at least one 
project is known to have been impacted, it's not unreasonable to expect that 
more will be.  So I think we should avoid such breakage and undo the change in 
behavior for 3.7 (and the older releases as well).

Now, as for 3.8, as it hasn't released yet, we have more latitude and, although 
we're close to producing an RC, it may still be OK to document the changed 
behavior there.  That should be Łukasz's call.

Does that make sense?

--

___
Python tracker 

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



Re: numpy results in segmentation fault

2019-09-19 Thread Aldwin Pollefeyt
use:

num_arr1 = numpy.array(tgt_arr1, dtype=int)
num_arr2 = numpy.array(tgt_arr2, dtype=int)


On Mon, Sep 16, 2019 at 5:36 PM Pradeep Patra 
wrote:

> Yes it is crashing in the hackerrank site and the testcases fails with
> segmentation fault. I tried to install numpy with 3.7.3 and it is for some
> reason not working and after import when I run import numpy at python
> console and press enter I get >>? i,e its not working properly.
>
> Can you please help letting me know the python and numpy compatibility
> matrix or I am missing anything?
>
> I tried some of the numpy code from the other github and it also fails with
> the segmentation fault :-(. I am guessing some numpy version compatility
> issue or some environment issue.
>
> On Thu, Sep 12, 2019 at 8:00 PM Thomas Jollans  wrote:
>
> > On 12/09/2019 15.53, Pradeep Patra wrote:
> > > Hi ,
> > >
> > > I was trying to solve the hackerrank and was using python 3.7.x.
> > > https://www.hackerrank.com/challenges/np-concatenate/problem
> > >
> > > While running the code sometimes I get success result and sometimes it
> > > fails with "Segmentation Fault" at Hacker rank UI. I dont have any clue
> > why
> > > the code is crashing ? Does anyone have any idea?
> >
> >
> > Are you sure it's your code that's crashing, and not something beyond
> > your control? (Such as the software that is starting Python for you)
> > Does it depend on the input? Can you reproduce the issue in a controlled
> > environment (i.e. on your own PC)?
> >
> >
> > >
> > > Regards
> > > Pradeep
> > >
> > > import numpy
> > >
> > > n,m,p = map(int,input().split())
> > > tgt_arr1 = []
> > > for i in range(n):
> > > row = list(map(int,input().split()))
> > > tgt_arr1.append(row)
> > > tgt_arr2 = []
> > > for j in range(m):
> > > row = list(map(int,input().split()))
> > > tgt_arr2.append(row)
> > >
> > > num_arr1 = numpy.array(tgt_arr1,int)
> > > num_arr2 = numpy.array(tgt_arr2,int)
> > >
> > > print(numpy.concatenate((num_arr1,num_arr2),axis=0))
> >
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38093] Update MagicMock __aenter__ and __aexit__ to return AsyncMock's

2019-09-19 Thread Lisa Roach


Lisa Roach  added the comment:


New changeset 8b03f943c37e07fb2394acdcfacd066647f9b1fd by Lisa Roach in branch 
'master':
bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947)
https://github.com/python/cpython/commit/8b03f943c37e07fb2394acdcfacd066647f9b1fd


--

___
Python tracker 

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



[issue38161] AsyncMock add `.awaited` like `.called`

2019-09-19 Thread Lisa Roach


Lisa Roach  added the comment:

Yeah I think the current `awaited` ought to at least be a private variable, 
since people will assume it works like a boolean to match `.called`. Then we 
could add a new, proper, `awaited` that would function like:

>>> mock = AsyncMock()
>>> cr_mock = mock()
>>> mock.called
True
>>> mock.awaited
False
>>> await cr_mock
>>> mock.awaited
True

--

___
Python tracker 

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



[issue38216] Fix for issue30458 prevents crafting invalid requests

2019-09-19 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

What's needed here is a Decision.  (release managers and steering councils make 
those)

IMNSHO, this regression is intentional and does not feel like a bug.

The Python HTTP APIs were never designed with an explicit intent to allow 
violations of the protocol.  That it was "allowed" was an accident because the 
very old original API design didn't go out of its way to check much.  That 
doesn't mean it was intended.  Hyrum's Law applies as the (lack of) behavior 
has been around forever.  So of course someone has written code that depended 
on that.  But it doesn't make said code right.

We either "be strict in what we produce" or we ignore abuse of the APIs and 
effectively close all CVEs filed against them as "not a bug, this library is 
intended to allow abuse when given untrusted input."

If we take the latter route and intended to allow such things, we'd need to 
explicitly document it as such and guarantee their behaviors.  As noted, 
disallowing it has already shipped in two stable releases.

When writing tests of particular out of spec queries such that servers can 
implement good "be lenient in what you accept" behavior, it is better not to 
depend on specific behaviors of a given http client library to allow you to do 
so for such tests.

If the decision requires code changes, do not expect me to spend time creating 
them.  Please feel free to loop me in on PR reviews but I'd rather not review 
anything without release manager approval of the direction they take things in 
the first place.

--
nosy: +gregory.p.smith

___
Python tracker 

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



Re: exec and globals and locals ...

2019-09-19 Thread jfong
>>> x = 3
>>> def foo():
... exec("print(globals(), locals()); x = x + 1; print(globals(), 
locals())")
...
>>> foo()
{'foo': , '__package__': None, '__builtins__': 
, '__loader__': , '__doc__': None, '__name__': '__main__', 
'__spec__': None, 'x': 3} {}
{'foo': , '__package__': None, '__builtins__': 
, '__loader__': , '__doc__': None, '__name__': '__main__', 
'__spec__': None, 'x': 3} {'x': 4}
>>> def goo():
... print(globals(), locals())
... x = x + 1
... print(globals(), locals())
...
>>> goo()
{'foo': , '__package__': None, '__builtins__': 
, '__loader__': , '__doc__': None, '__name__': '__main__', 
'__spec__': None, 'goo': , 'x': 3} {}
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in goo
UnboundLocalError: local variable 'x' referenced before assignment
>>>

Can't figure out what makes it different:-(

--Jach

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue34002] minor efficiency and clarity improvements in email package

2019-09-19 Thread Abhilash Raj


Abhilash Raj  added the comment:

PR is now merged.

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



[issue34002] minor efficiency and clarity improvements in email package

2019-09-19 Thread Abhilash Raj


Abhilash Raj  added the comment:


New changeset 2702638eabe5f7b25f36d295f0ad78cb8d4eda05 by Abhilash Raj (Michael 
Selik) in branch 'master':
bpo-34002: Minor efficiency and clarity improvements in email package. (GH-7999)
https://github.com/python/cpython/commit/2702638eabe5f7b25f36d295f0ad78cb8d4eda05


--
nosy: +maxking

___
Python tracker 

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



[issue38228] Missing documentation on strftime modifier O

2019-09-19 Thread Eryk Sun


Eryk Sun  added the comment:

> Have you tried this on Windows or macOS?

3.5+ in Windows uses ucrt, which quietly ignores 'E' and 'O' strftime 
modifiers. From ucrt\time\wcsftime.cpp:

// Skip ISO E and O alternative representation format modifiers.  We
// do not support alternative formats in any locale.
if (*format_it == L'E' || *format_it == L'O')
{
++format_it;
}

Example:

>>> locale.setlocale(locale.LC_ALL, 'ca_ES.utf8')
'ca_ES.utf8'
>>> time.strftime('%b|%Ob')
'set.|set.'

2.7 uses the old MSVC runtime, in which the 'E' and 'O' modifiers are invalid.

Example:

>>> locale.setlocale(locale.LC_ALL, 'cat_esp')
'Catalan_Spain.1252'
>>> time.strftime('%b')
'set.'
>>> time.strftime('%Ob')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Invalid format string

--
nosy: +eryksun

___
Python tracker 

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



[issue38229] ClientConnectionError exception doesn't serialize property

2019-09-19 Thread David Parks


David Parks  added the comment:

Oh yes, this belongs to aiohttp. I thought that was handled here. I'll move 
this to a git issue on that page, and I'm closing this.

https://github.com/aio-libs/aiohttp/issues/4077

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
title: ClientConnectionError exception doesn't serialize propertly -> 
ClientConnectionError exception doesn't serialize property

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread Kyle Stanley


Kyle Stanley  added the comment:

> Thanks, Kyle!

No problem, and thanks for all of the help from Andrew, Yury, and Victor!

> IMHO it will make asyncio more reliable, especially for tests on the CI.

Awesome, that was my primary intention. (:

> If it becomes an issue in Python 3.9 (executor hangs forever),

Feel free to add me to the nosy list if you have to open an issue for it, I'd 
be glad to help out with this if it becomes an issue.

--

___
Python tracker 

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



[issue38229] ClientConnectionError exception doesn't serialize propertly

2019-09-19 Thread ppperry


ppperry  added the comment:

This seems more likely to be a bug in aiohttp than in python.

--
nosy: +ppperry
type: crash -> behavior

___
Python tracker 

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



[issue38228] Missing documentation on strftime modifier O

2019-09-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

Have you tried this on Windows or macOS?

--
nosy: +eric.smith

___
Python tracker 

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



[issue38229] ClientConnectionError exception doesn't serialize propertly

2019-09-19 Thread David Parks


David Parks  added the comment:

Minor correction to the minimal reproducible test case:

```
import multiprocessing
import aiohttp


connection_key = aiohttp.client_reqrep.ConnectionKey
ose = OSError('test')

e = aiohttp.client_exceptions.ClientConnectorError(connection_key, ose)
q = multiprocessing.Queue()

q.put(e)
q.get()
```

--

___
Python tracker 

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



[issue38229] ClientConnectionError exception doesn't serialize propertly

2019-09-19 Thread David Parks


New submission from David Parks :

Original question posted here:

https://stackoverflow.com/questions/58019939/attributeerror-str-object-has-no-attribute-errno?noredirect=1#comment102443264_58019939

The following exception is encountered when placing an 
`aiohttp.client_exceptions.ClientConnectionError` on a `multiprocessing.Queue`. 
The problem appears to occur during deserialization.

```
Traceback (most recent call last):
  File "model_neural_simplified.py", line 318, in 
main(**arg_parser())
  File "model_neural_simplified.py", line 314, in main
globals()[command](**kwargs)
  File "model_neural_simplified.py", line 304, in predict
next_neural_data, next_sample = reader.get_next_result()
  File "/project_neural_mouse/src/asyncs3/s3reader.py", line 174, in 
get_next_result
result = future.result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in 
__get_result
raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
  File "model_neural_simplified.py", line 245, in read_sample
f_bytes = s3f.read(read_size)
  File "/project_neural_mouse/src/asyncs3/s3reader.py", line 374, in read
size, b = self._issue_request(S3Reader.READ, (self.url, size, 
self.position))
  File "/project_neural_mouse/src/asyncs3/s3reader.py", line 389, in 
_issue_request
response = self.communication_channels[uuid].get()
  File "/usr/lib/python3.6/multiprocessing/queues.py", line 113, in get
return _ForkingPickler.loads(res)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/client_exceptions.py", 
line 133, in __init__
super().__init__(os_error.errno, os_error.strerror)
AttributeError: 'str' object has no attribute 'errno'
```

A similar issue is reproducible using the following code snippet:

```
import multiprocessing
import aiohttp


connection_key = aiohttp.client_reqrep.ConnectionKey
ose = OSError('test')

e = aiohttp.client_exceptions.ClientConnectorError(connection_key, ose)
q = multiprocessing.Queue()

q.put(e)
q.get(e)
```

--
components: asyncio
messages: 352818
nosy: asvetlov, davidparks21, yselivanov
priority: normal
severity: normal
status: open
title: ClientConnectionError exception doesn't serialize propertly
type: crash
versions: Python 3.6

___
Python tracker 

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



[issue38225] iscoroutinefunction broken with cython - allow tagging of functions as async?

2019-09-19 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

I think we need better name than just `_is_coroutine`.
All async function properties as dunder named, the new *official* name should 
follow this convention as well

--

___
Python tracker 

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



[issue38228] Missing documentation on strftime modifier O

2019-09-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +belopolsky, p-ganssle

___
Python tracker 

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



[issue38228] Missing documentation on strftime modifier O

2019-09-19 Thread Joan


New submission from Joan :

In the documentation at 
https://docs.python.org/3.9/library/datetime.html#strftime-strptime-behavior 
there's an omission of one of the modifiers that can be add to the strftime 
parameters (O and E)


Quoting from  http://man7.org/linux/man-pages/man3/strftime.3.html


Some conversion specifications can be modified by preceding the
conversion specifier character by the E or O modifier to indicate
that an alternative format should be used.  If the alternative format
or specification does not exist for the current locale, the behavior
will be as if the unmodified conversion specification were used. (SU)
The Single UNIX Specification mentions %Ec, %EC, %Ex, %EX, %Ey, %EY,
%Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy,
where the effect of the O modifier is to use alternative numeric
symbols (say, roman numerals), and that of the E modifier is to use a
locale-dependent alternative representation.


The modifier works as expected for the O modifier returning the values defined 
in ab_alt_mon and alt_mon from the locale (instead of the ones defined in abmon 
and mon.
I haven't been able to get any results with the E modifier (might not be yet 
defined in any locale)

A small snippet of code to see the difference:
import locale
from datetime import datetime
locale.setlocale(locale.LC_ALL, 'ca_AD.utf8')
locale.setlocale(locale.LC_ALL, 'ca_ES.utf8')
now = datetime.now() # current date and time
date_time = now.strftime("|%Ob|%b|||%OB|%B|")
print("date and time:",date_time)

--
assignee: docs@python
components: Documentation
messages: 352816
nosy: aseques, docs@python
priority: normal
severity: normal
status: open
title: Missing documentation on strftime modifier O
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



[issue38227] Setting a signal handler gets multiprocessing.Pool stuck

2019-09-19 Thread Ionel Cristian Mărieș

New submission from Ionel Cristian Mărieș :

Running `python3.8 mp-bug-python2.8.py` usually gets stuck after a dozen 
iterations or so.

It appears that if I stop setting that signal handler it doesn't get stuck. 
Unfortunately I need it to perform critical cleanup.

This is what I got from gdb:

(gdb) py-bt
Traceback (most recent call first):
  File "/usr/lib/python3.8/multiprocessing/synchronize.py", line 95, in 
__enter__
return self._semlock.__enter__()
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 355, in get
with self._rlock:
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 370, in worker
`func` and (a, b) becomes func(a, b).
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/multiprocessing/process.py", line 569, in _bootstrap
  File "/usr/lib/python3.8/multiprocessing/popen_fork.py", line 75, in _launch
code = process_obj._bootstrap(parent_sentinel=child_r)
  File "/usr/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
  File "/usr/lib/python3.8/multiprocessing/context.py", line 276, in _Popen
return Popen(process_obj)
  File "/usr/lib/python3.8/multiprocessing/process.py", line 633, in start
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 838, in 
_repopulate_pool_static
self._length = None
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 559, in 
_repopulate_pool
outqueue.put(None)
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 212, in __init__
self._repopulate_pool()
  File "/usr/lib/python3.8/multiprocessing/context.py", line 375, in Pool
  File "mp-bug-python2.8.py", line 21, in 



And without the macros:



#0  0x7f51c79fb6d6 in futex_abstimed_wait_cancelable (private=128, 
abstime=0x0, expected=0, futex_word=0x7f51c7e29000) at 
../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem@entry=0x7f51c7e29000, abstime=0x0) at 
sem_waitcommon.c:111
#2  0x7f51c79fb7c8 in __new_sem_wait_slow (sem=0x7f51c7e29000, abstime=0x0) 
at sem_waitcommon.c:181
#3  0x7f51c79fb839 in __new_sem_wait (sem=) at sem_wait.c:42
#4  0x7f51c58d51f7 in semlock_acquire (self=0x7f51c58a60b0, args=, kwds=) at ./Modules/_multiprocessing/semaphore.c:319
#5  0x0067d929 in method_vectorcall_VARARGS_KEYWORDS 
(func=, args=0x7f51c58a4eb8, 
nargsf=, kwnames=)
at ../Objects/descrobject.c:332
#6  0x0042c5dc in _PyObject_Vectorcall (kwnames=, 
nargsf=, args=, callable=) at 
../Include/cpython/abstract.h:127
#7  call_function (kwnames=0x0, oparg=, pp_stack=, tstate=0x22bd160) at ../Python/ceval.c:4987
#8  _PyEval_EvalFrameDefault (f=, throwflag=) at 
../Python/ceval.c:3486
#9  0x00425ed7 in function_code_fastcall (co=, 
args=, nargs=1, globals=) at ../Objects/call.c:283
#10 0x006761e4 in _PyObject_Vectorcall (kwnames=0x0, nargsf=1, 
args=0x7ffe20bcc908, callable=) at 
../Include/cpython/abstract.h:127
#11 method_vectorcall (method=, args=, 
nargsf=, kwnames=0x0) at ../Objects/classobject.c:67
#12 0x0042857e in _PyObject_Vectorcall (kwnames=0x0, nargsf=0, 
args=0x0, callable=) at 
../Include/cpython/abstract.h:127
#13 _PyObject_CallNoArg (func=) at 
../Include/cpython/abstract.h:153
#14 _PyEval_EvalFrameDefault (f=, throwflag=) at 
../Python/ceval.c:3287
#15 0x00425ed7 in function_code_fastcall (co=, 
args=, nargs=1, globals=) at ../Objects/call.c:283
#16 0x00676245 in _PyObject_Vectorcall (kwnames=0x0, nargsf=1, 
args=0x23cea18, callable=) at 
../Include/cpython/abstract.h:127
#17 method_vectorcall (method=, args=0x23cea20, 
nargsf=, kwnames=0x0) at ../Objects/classobject.c:60
#18 0x0042cf2f in _PyObject_Vectorcall (kwnames=, 
nargsf=, args=, callable=) at 
../Include/cpython/abstract.h:127
#19 call_function (kwnames=0x0, oparg=, pp_stack=, tstate=0x22bd160) at ../Python/ceval.c:4987
#20 _PyEval_EvalFrameDefault (f=, throwflag=) at 
../Python/ceval.c:3500
#21 0x004f9f44 in PyEval_EvalFrameEx (throwflag=0,
f=Frame 0x23ce820, for file /usr/lib/python3.8/multiprocessing/pool.py, 
line 370, in worker (inqueue=, 
_writer=, _rlock=, acquire=, release=) at remote 
0x7f51c589d0d0>, _poll=, 
_wlock=, 
acquire=, release=) at remote 0x7f51c589deb0>) at remote 
0x7f51c589d3a0>, outqueue=, globals=, 
locals=locals@entry=0x0, args=, argcount=6, kwnames=0x0, 
kwargs=0x7f51c636e628, kwcount=0, kwstep=1,
defs=0x7f51c65a4828, defcount=4, kwdefs=0x0, closure=0x0, name='worker', 
qualname='worker') at ../Python/ceval.c:4298
#23 0x0043e7a2 in _PyFunction_Vectorcall (func=func@entry=, stack=, nargsf=nargsf@entry=6, 
kwnames=) at ../Objects/call.c:435
#24 0x0044143c in PyVectorcall_Call (callable=, tuple=, kwargs=) at 
../Objects/call.c:199
#25 0x00428aec in do_call_core (kwdict={},
callargs=(, _writer=, 
_rlock=, 
acquire=, release=) at remote 0x7f51c589d0d0>, _poll=, _wlock=, acquire=, 

Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.

Am 18.09.2019 um 22:24 schrieb Alexandre Brault:


On 2019-09-18 4:01 p.m., Ralf M. wrote:


I don't know the exact rules of Windows wildcards, so there may be
even more cases of unexpected behavior.
If anyone knows where to find the complete rules (or a python module
that implements them), I would be interested.



fnmatch in the standard library has a translate function that transforms
a glob pattern to a regex

https://docs.python.org/3.7/library/fnmatch.html#fnmatch.translate

Alex


Thank you for the pointer.
However, from the documentation of module fnmatch:
"This module provides support for Unix shell-style wildcards"

And Unix shell-style wildcards differ from Windows cmd wildcards.
For one, [ ] are special in Unix shells, but not in Windows cmd.
For another, cmd wildcards have several quirks, e.g. *.* matching 
filenames that don't contain a dot, or "a???" matching "ab".


Several years ago, when I needed DOS-style globbing, I copied fnmatch.py 
and glob.py from the standard library and modified them to treat [ ] as 
not special. However, that didn't help with the cmd quirks, and I don't 
even know all the rules about cmd wildcards.


Ralf
--
https://mail.python.org/mailman/listinfo/python-list


[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Brett Cannon


Brett Cannon  added the comment:

I'm -1 as PEP 519 created __fspath__ specifically so that pathlib.Path wouldn't 
be confused as a string by accident. You can also use os.fspath() to get a 
string representation of the path itself.

I also don't know if Antoine wants to make this sort of call for pathlib 
anymore as he isn't listed in https://devguide.python.org/experts/ or 
https://github.com/python/cpython/blob/master/.github/CODEOWNERS for pathlib 
anymore (and that was an explicit choice based on code history for the experts 
index).

--
nosy: +brett.cannon
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



Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.

Am 18.09.2019 um 22:22 schrieb Chris Angelico:

On Thu, Sep 19, 2019 at 6:20 AM Ralf M.  wrote:


Am 17.09.2019 um 20:59 schrieb Manfred Lotz:

I have a function like follows

def regex_from_filepat(fpat):
  rfpat = fpat.replace('.', '\\.') \
.replace('%', '.')  \
.replace('*', '.*')

  return '^' + rfpat + '$'


As I don't want to have the replace() functions in one line my
question is if it is ok to spread the statement over various lines as
shown above, or if there is a better way?

Thanks.



Not related to your question, but:
You seem to try to convert a Windows wildcard pattern to a regex
pattern. However, wildcards sometimes behave a bit different than what
you assume. I know for instance that *.* matches any filename, even if
the filename doesn't contain a dot.


Hmm, why do you assume it's a Windows wildcard pattern specifically?

ChrisA

I think I jumped to that conclusion because the example didn't treat [ ] 
as special characters. [ ] are special in a unix shell, but not at a cmd 
prompt. Thinking it over, [ ] would need a much differnt treatment and 
might be left out of the example for that reason, though.


Also I may be biased: I mostly use Windows, Linux only occasionally.

Ralf M.

--
https://mail.python.org/mailman/listinfo/python-list


[issue38226] pickle.dump and load error message when file isn't opened in binary mode are not useful

2019-09-19 Thread Борис Верховский

New submission from Борис Верховский :

pickle.load() and pickle.dump() take a file object as an argument. That file 
object must be opened in binary mode ("rb" or "wb"). If it's not, pickle raises 
a confusing error message.

When pickle.dump()'ing to a file opened in "w" mode instead of "wb" mode it'll 
raise a TypeError:


TypeError: write() argument must be str, not bytes


I thought it might be getting this because I was pickling bytes objects. 

For pickle.load()'ing from a file opened in "r" mode instead of "rb" mode, 
it'll raise a UnicodeDecodeError


UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid 
start byte


There are a couple pages on the internet (just search "pickle" followed by 
either error message) with people being confused about this. 

pickle should catch these errors and report something more useful.

--
components: Library (Lib)
messages: 352813
nosy: boris
priority: normal
severity: normal
status: open
title: pickle.dump and load error message when file isn't opened in binary mode 
are not useful
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



[issue38225] iscoroutinefunction broken with cython - allow tagging of functions as async?

2019-09-19 Thread Zachary Ware


Change by Zachary Ware :


--
nosy: +scoder
versions:  -Python 2.7, Python 3.5, Python 3.6

___
Python tracker 

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



Re: What about idea of making a "Pythonic Lisp"...i.e. a Lisp that more closely resembles the syntax of Python?

2019-09-19 Thread Chris Angelico
On Fri, Sep 20, 2019 at 5:16 AM Cecil Westerhof  wrote:
>
> Paul Rubin  writes:
>
> > Python 3.7.3 (default, Apr  3 2019, 05:39:12)
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> a = range(10)
> > >>> b = reversed(a)
> > >>> sum(a) == sum(b)
> > True
> > >>> sum(b) == sum(a)
> > False
>
> Why does this happen?
>
> By the way, when you change the last statement to:
> sum(a) == sum(b)
>
> you also get False.

>>> sum(range(10)) == sum(reversed(range(10)))
True

If you actually want a reversed range, use slice notation instead of
the reversed() function, which is more parallel to iter().

>>> a = range(10)
>>> b = a[::-1]
>>> sum(a) == sum(b)
True
>>> sum(b) == sum(a)
True

Now you actually have a range that runs the other direction, instead
of an iterator that runs through the range backwards.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What about idea of making a "Pythonic Lisp"...i.e. a Lisp that more closely resembles the syntax of Python?

2019-09-19 Thread Cecil Westerhof
Paul Rubin  writes:

> Python 3.7.3 (default, Apr  3 2019, 05:39:12)
> Type "help", "copyright", "credits" or "license" for more information.
> >>> a = range(10)
> >>> b = reversed(a)
> >>> sum(a) == sum(b)
> True
> >>> sum(b) == sum(a)
> False

Why does this happen?

By the way, when you change the last statement to:
sum(a) == sum(b)

you also get False.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 20:24:49 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
> 
> > Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
> >> Eko palypse wrote:
> >> 
> >> > No, I have to correct myself
> >> > 
> >> > x = 5
> >> > def f1():
> >> > exec("x = x + 1; print('f1 in:', x)")
> >> > return x
> >> > print('f1 out', f1())
> >> > 
> >> > results in the same, for me confusing, results.
> >> > 
> >> > f1 in: 6
> >> > f1 out 5
> >> 
> >> Inside a function exec assignments go to a *copy* of the local namespace.
> >> Also LOAD_NAME is used to look up names. Therefore you can read and then
> >> shade a global name with its local namesake.
> >> 
> >> Inside a function the namespace is determined statically. As f1() has no
> >> assignment to x (code inside exec(...) is not considered) x is looked up
> >> in directly the global namespace using LOAD_GLOBAL.
> >> 
> >> If you want to access the local namespace used by exec() you have to
> >> provide one explicitly:
> >> 
> >> >>> x = 5
> >> >>> def f():
> >> ... ns = {}
> >> ... exec("x += 1", globals(), ns)
> >> ... return ns["x"]
> >> ...
> >> >>> f()
> >> 6
> >> >>> x
> >> 5
> >> 
> >> By the way, in Python 2 where exec was a statement the local namespace is
> >> shared:
> >> 
> >> >>> x = 5
> >> >>> def f():
> >> ... exec "x += 1"
> >> ... return x
> >> ...
> >> >>> f()
> >> 6
> >> >>> x
> >> 5
> > 
> > Sorry, missed that.
> > Thank you, may I ask you how I could have come myself
> > to that explanation? What do I have to read to get that understanding?
> > Hopefully you don't say read the C code, because that is something
> > I tried but failed miserably.
> 
> https://docs.python.org/3/library/functions.html#exec
> https://docs.python.org/3/reference/executionmodel.html#naming-and-binding
> 
> (I had to google for the second link.)
> 
> I usually experiment with code and the disassembler. I find its output quite 
> readable, 
> 
> >>> def f(): x += 1
> ... 
> >>> import dis
> >>> dis.dis(f)
>   1   0 LOAD_FAST0 (x)
>   3 LOAD_CONST   1 (1)
>   6 INPLACE_ADD
>   7 STORE_FAST   0 (x)
>  10 LOAD_CONST   0 (None)
>  13 RETURN_VALUE
> >>> dis.dis(compile("x += 1", "", "exec"))
>   1   0 LOAD_NAME0 (x)
>   3 LOAD_CONST   0 (1)
>   6 INPLACE_ADD
>   7 STORE_NAME   0 (x)
>  10 LOAD_CONST   1 (None)
>  13 RETURN_VALUE
> 
> and you can limit yourself to small snippets.

Thank you very much, really, very much appreciated.
Normally I do use docs.python.org as my first resource to look 
for an answer to my questions but I'm not always convinced that
my understanding/interpretation is correct.
Then I research on the web to see if there are similar questions and
try to understand these explanations but ...
and in this particular case I wasn't even able to find an answer. 

The dis module is nice to see differences but I assume more useful
to software developers than to hobby programmers like me.
At least not in the current state of knowledge I have.
I was under the impression that I have a good understanding of the 
python language before I started my current project but now ...
Enough whining :-)

Once again,
Thank you very much
Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue15363] Idle/tkinter ~x.py 'save as' fails. closes idle

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -Python 2.7, 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



[issue21937] IDLE interactive window doesn't display unsaved-indicator

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -Python 2.7, 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



[issue23544] IDLE hangs when selecting Stack View with debug active

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy:  -kbk, roger.serwy
versions: +Python 3.9 -Python 2.7, 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



[issue21674] Idle: Add 'find all' in current file

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -Python 2.7, 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



[issue24812] All standard keystrokes not recognized in IDLE dialogs on Mac

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy:  -kbk, roger.serwy
versions: +Python 3.9 -Python 2.7, Python 3.5, Python 3.6

___
Python tracker 

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



[issue29926] IDLE: in shell, time.sleep ignores _thread.interrupt_main()

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -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



[issue11820] idle3 shell os.system swallows shell command output

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -Python 2.7, 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



[issue38225] iscoroutinefunction broken with cython - allow tagging of functions as async?

2019-09-19 Thread David Hilton


Change by David Hilton :


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

___
Python tracker 

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



[issue38225] iscoroutinefunction broken with cython - allow tagging of functions as async?

2019-09-19 Thread David Hilton


New submission from David Hilton :

If a python piece of code imports cython code with async defs, 
`asyncio.iscoroutinefunction` cannot determine that the code is async.

https://github.com/cython/cython/issues/2273#issuecomment-531537624

scoder is open to marking async defs so that they can be identified, just like 
`asyncio.coroutine`:

https://github.com/python/cpython/blob/ae239f6b0626e926613a4a1dbafa323bd41fec32/Lib/asyncio/coroutines.py#L156

However, that is an internal interface and `@coroutine` is deprecated.

--

Can we have some official way of marking functions as async that will not be 
deprecated?

The easiest would be for `asyncio.iscoroutinefunction` to look for 
`_is_coroutine = True`, and promise to keep looking for that value.

This would also allow for functools.partial to easily mark that it's returning 
an async function, which some people seem to care about.

--
components: asyncio
messages: 352812
nosy: asvetlov, dhiltonp, yselivanov
priority: normal
severity: normal
status: open
title: iscoroutinefunction broken with cython - allow tagging of functions as 
async?
type: enhancement
versions: Python 2.7, Python 3.5, 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



Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote:

> Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
>> Eko palypse wrote:
>> 
>> > No, I have to correct myself
>> > 
>> > x = 5
>> > def f1():
>> > exec("x = x + 1; print('f1 in:', x)")
>> > return x
>> > print('f1 out', f1())
>> > 
>> > results in the same, for me confusing, results.
>> > 
>> > f1 in: 6
>> > f1 out 5
>> 
>> Inside a function exec assignments go to a *copy* of the local namespace.
>> Also LOAD_NAME is used to look up names. Therefore you can read and then
>> shade a global name with its local namesake.
>> 
>> Inside a function the namespace is determined statically. As f1() has no
>> assignment to x (code inside exec(...) is not considered) x is looked up
>> in directly the global namespace using LOAD_GLOBAL.
>> 
>> If you want to access the local namespace used by exec() you have to
>> provide one explicitly:
>> 
>> >>> x = 5
>> >>> def f():
>> ... ns = {}
>> ... exec("x += 1", globals(), ns)
>> ... return ns["x"]
>> ...
>> >>> f()
>> 6
>> >>> x
>> 5
>> 
>> By the way, in Python 2 where exec was a statement the local namespace is
>> shared:
>> 
>> >>> x = 5
>> >>> def f():
>> ... exec "x += 1"
>> ... return x
>> ...
>> >>> f()
>> 6
>> >>> x
>> 5
> 
> Sorry, missed that.
> Thank you, may I ask you how I could have come myself
> to that explanation? What do I have to read to get that understanding?
> Hopefully you don't say read the C code, because that is something
> I tried but failed miserably.

https://docs.python.org/3/library/functions.html#exec
https://docs.python.org/3/reference/executionmodel.html#naming-and-binding

(I had to google for the second link.)

I usually experiment with code and the disassembler. I find its output quite 
readable, 

>>> def f(): x += 1
... 
>>> import dis
>>> dis.dis(f)
  1   0 LOAD_FAST0 (x)
  3 LOAD_CONST   1 (1)
  6 INPLACE_ADD
  7 STORE_FAST   0 (x)
 10 LOAD_CONST   0 (None)
 13 RETURN_VALUE
>>> dis.dis(compile("x += 1", "", "exec"))
  1   0 LOAD_NAME0 (x)
  3 LOAD_CONST   0 (1)
  6 INPLACE_ADD
  7 STORE_NAME   0 (x)
 10 LOAD_CONST   1 (None)
 13 RETURN_VALUE

and you can limit yourself to small snippets.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regular expressions help

2019-09-19 Thread Chris Angelico
On Fri, Sep 20, 2019 at 1:07 AM Pradeep Patra  wrote:
>
> Thanks  David /Anthony for your help. I figured out the issue myself. I
> dont need any ^, $ etc to the regex pattern and the plain string (for exp
> my-dog) works fine. I am looking at creating a generic method so that
> instead of passing my-dog i can pass my-cat or blah blah. I am thinking of
> creating a list of probable combinations to search from the list. Anybody
> have better ideas?
>

If you just want to find a string in another string, don't use regular
expressions at all! Just ask Python directly:

>>> print("my-cat" in "This is where you can find my-cat, look, see!")
True

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue22083] IDLE: Refactor breakpoint related methods

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
title: Refactor PyShell's breakpoint related methods -> IDLE: Refactor 
breakpoint related methods
versions: +Python 3.9 -Python 2.7, 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



[issue31930] IDLE: Pressing "Home" on Windows places cursor before ">>>"

2019-09-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.9 -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



[issue21359] IDLE macOS: Some Command shortcuts do not work correctly

2019-09-19 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Still an issue.  Several shortcuts do not work right, so I am generalizing the 
issue. 

1. Redo command accelerator acts as Undo.
2. Cmd-M minimizes instead of open module (#35104 has long discussion). 

I at least one other issue mentions a similar problem.  The default mac 
keybinding should all be tested to determine the scope of the problem.  Then a 
new keyset designed (#32761)

3. #18444 and #32761 both discuss ^A and beginning of line.

--
title: IDLE Redo command accelerator acts as Undo with current OS X Cocoa Tk 
8.5.15 -> IDLE macOS: Some Command shortcuts do not work correctly
versions: +Python 3.9 -Python 2.7

___
Python tracker 

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



[issue35104] IDLE: On macOS, Command-M minimizes & opens "Open Module..."

2019-09-19 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I am closing this as a duplicate of #21359 as I believe there is at least one 
more non-working shortcut and because I believe the solution is to test all and 
patch the default mac keyset all at once.

--
resolution:  -> duplicate
stage: needs patch -> resolved
status: open -> closed
superseder:  -> IDLE Redo command accelerator acts as Undo with current OS X 
Cocoa Tk 8.5.15

___
Python tracker 

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



[issue38140] Py_tp_dictoffset / Py_tp_finalize are unsettable in stable API

2019-09-19 Thread Dino Viehland


Change by Dino Viehland :


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



[issue38045] enum.Flag instance creation is slow

2019-09-19 Thread Roundup Robot


Change by Roundup Robot :


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

___
Python tracker 

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



Re: Unicode UCS2, UCS4 and ... UCS1

2019-09-19 Thread MRAB

On 2019-09-19 09:55, Gregory Ewing wrote:

Eli the Bearded wrote:

There isn't anything called UCS1.


Apparently there is, but it's not a character set, it's a loudspeaker.

https://www.bhphotovideo.com/c/product/1205978-REG/yorkville_sound_ucs1_1200w_15_horn_loaded.html

The OP might mean Py_UCS1, which is an implementation detail of the 
Flexible String Representation.

--
https://mail.python.org/mailman/listinfo/python-list


[issue15348] IDLE - shell becomes unresponsive if debugger windows is closed while active.

2019-09-19 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

The input glitch mentioned above no longer exists, so closing.

--
resolution:  -> fixed
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



[issue15347] IDLE - remove debugger 'interacting'

2019-09-19 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

fix-nested-mainloop.patch was superceded by fix-nested2.patch for #24455.
I verified that the initial test now passes.  When I click 'yes' in that box 
popped up by step 4, both Shell and debugger windows disappear and IDLE exists.

The only question left is whether to apply remove-interacting-debugger.patch, 
which was aimed at the deprecated but not removed -n mode.

--
nosy:  -Saimadhav.Heblikar, roger.serwy
title: IDLE - does not close if the debugger was active -> IDLE - remove 
debugger 'interacting'
versions: +Python 3.9 -Python 2.7, 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



[issue38224] Windows embeddable distribution doesn't ship headers

2019-09-19 Thread Steve Dower


Steve Dower  added the comment:

The embeddable distro is meant to be a "redistributable" for end-user machines, 
rather than a development kit. "Build" and "distribution" are two clearly 
separated tasks (at least on Windows), and so they have different dependencies. 
We won't be adding headers to the embeddable distro.

To get the headers, you'll either want the regular installer or the package 
from https://www.nuget.org/packages/python (or pythonx86). Or you can grab the 
Include folder from git, provided you use PC/pyconfig.h and the correct tag, as 
none of the files are "cooked" on Windows.

To directly address your two examples:
- the linked SCons script is a build script, which should be run on a build 
machine against a development kit. But when you copy the built result to 
another machine, they'll only require the embeddable distro at runtime
- the "frozen" distribution will need the new .exe binary to be built against a 
development kit. But when you copy the built result to another machine, they'll 
only require the embeddable distro at runtime.

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

___
Python tracker 

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



[issue38208] Simplify string.Template by using __init_subclass__()

2019-09-19 Thread Barry A. Warsaw


Change 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



Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
> 
> > No, I have to correct myself
> > 
> > x = 5
> > def f1():
> > exec("x = x + 1; print('f1 in:', x)")
> > return x
> > print('f1 out', f1())
> > 
> > results in the same, for me confusing, results.
> > 
> > f1 in: 6
> > f1 out 5
> 
> Inside a function exec assignments go to a *copy* of the local namespace.
> Also LOAD_NAME is used to look up names. Therefore you can read and then 
> shade a global name with its local namesake.
> 
> Inside a function the namespace is determined statically. As f1() has no 
> assignment to x (code inside exec(...) is not considered) x is looked up in 
> directly the global namespace using LOAD_GLOBAL.
> 
> If you want to access the local namespace used by exec() you have to provide 
> one explicitly:
> 
> >>> x = 5
> >>> def f():
> ... ns = {}
> ... exec("x += 1", globals(), ns)
> ... return ns["x"]
> ... 
> >>> f()
> 6
> >>> x
> 5
> 
> By the way, in Python 2 where exec was a statement the local namespace is 
> shared:
> 
> >>> x = 5
> >>> def f():
> ... exec "x += 1"
> ... return x
> ... 
> >>> f()
> 6
> >>> x
> 5

Sorry, missed that. 
Thank you, may I ask you how I could have come myself
to that explanation? What do I have to read to get that understanding?
Hopefully you don't say read the C code, because that is something
I tried but failed miserably.

Thank you
Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue37531] Fix regrtest timeout for subprocesses: regrtest -jN --timeout=SECONDS

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 5e1400a6bcbb3350a6665176980a2b8343075c63 by Victor Stinner in 
branch '3.7':
bpo-37531: sync regrtest with master branch (GH-16285) (GH-16289)
https://github.com/python/cpython/commit/5e1400a6bcbb3350a6665176980a2b8343075c63


--

___
Python tracker 

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



Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
First thank you for all the answers, very much appreciated.
I assume the root cause might be explained by the zen of python as well.

If the implementation is hard to explain, it's a bad idea.

Maybe I need to rethink my implementation :-)

Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote:

> No, I have to correct myself
> 
> x = 5
> def f1():
> exec("x = x + 1; print('f1 in:', x)")
> return x
> print('f1 out', f1())
> 
> results in the same, for me confusing, results.
> 
> f1 in: 6
> f1 out 5

Inside a function exec assignments go to a *copy* of the local namespace.
Also LOAD_NAME is used to look up names. Therefore you can read and then 
shade a global name with its local namesake.

Inside a function the namespace is determined statically. As f1() has no 
assignment to x (code inside exec(...) is not considered) x is looked up in 
directly the global namespace using LOAD_GLOBAL.

If you want to access the local namespace used by exec() you have to provide 
one explicitly:

>>> x = 5
>>> def f():
... ns = {}
... exec("x += 1", globals(), ns)
... return ns["x"]
... 
>>> f()
6
>>> x
5

By the way, in Python 2 where exec was a statement the local namespace is 
shared:

>>> x = 5
>>> def f():
... exec "x += 1"
... return x
... 
>>> f()
6
>>> x
5


-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38140] Py_tp_dictoffset / Py_tp_finalize are unsettable in stable API

2019-09-19 Thread Dino Viehland


Dino Viehland  added the comment:


New changeset 3368f3c6ae4140a0883e19350e672fd09c9db616 by Dino Viehland (Eddie 
Elizondo) in branch 'master':
bpo-38140: Make dict and weakref offsets opaque for C heap types (#16076)
https://github.com/python/cpython/commit/3368f3c6ae4140a0883e19350e672fd09c9db616


--

___
Python tracker 

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



[issue38205] Py_UNREACHABLE() no longer behaves as a function call

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +15875
pull_request: https://github.com/python/cpython/pull/16290

___
Python tracker 

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



[issue37531] Fix regrtest timeout for subprocesses: regrtest -jN --timeout=SECONDS

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +15874
pull_request: https://github.com/python/cpython/pull/16289

___
Python tracker 

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



Re: Unable to start Python with Windows 7

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 17:52:48 UTC+2 schrieb cdoa...@orange.com:
> Hi,
> I am no more able to start Python from Windows 7 environment.
> I have the following message :
> "The Application was unable to start correctly, (0xC142). Click OK to 
> close the application"
> 
> Do you have any idea where the problem is ?
> 
> Bests regards,
> 

A shot in the dark, you do have Win7 32bit and tried to start python 64bit
Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue33694] test_asyncio: test_start_tls_server_1() fails on Python on x86 Windows7 3.7 and 3.x

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +15873
pull_request: https://github.com/python/cpython/pull/16288

___
Python tracker 

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



[issue37531] Fix regrtest timeout for subprocesses: regrtest -jN --timeout=SECONDS

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset fb7746d5d10ec4a34198da672018ba15f5667079 by Victor Stinner in 
branch '3.8':
bpo-37531: sync regrtest with master branch (GH-16285)
https://github.com/python/cpython/commit/fb7746d5d10ec4a34198da672018ba15f5667079


--

___
Python tracker 

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



Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
No, I have to correct myself

x = 5
def f1():
exec("x = x + 1; print('f1 in:', x)")
return x
print('f1 out', f1())

results in the same, for me confusing, results.

f1 in: 6
f1 out 5

Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Unable to start Python with Windows 7

2019-09-19 Thread cdoare.ext
Hi,
I am no more able to start Python from Windows 7 environment.
I have the following message :
"The Application was unable to start correctly, (0xC142). Click OK to close 
the application"

Do you have any idea where the problem is ?

Bests regards,


___
Christian Doaré (Groupe Open)
Tél :  +33 2 96 07 02 63
Mobile :  +33 6 33 51 41 15
cdoare@orange.com


_

Ce message et ses pieces jointes peuvent contenir des informations 
confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce 
message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages 
electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou 
falsifie. Merci.

This message and its attachments may contain confidential or privileged 
information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete 
this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been 
modified, changed or falsified.
Thank you.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode UCS2, UCS4 and ... UCS1

2019-09-19 Thread Gregory Ewing

Eli the Bearded wrote:

There isn't anything called UCS1.


Apparently there is, but it's not a character set, it's a loudspeaker.

https://www.bhphotovideo.com/c/product/1205978-REG/yorkville_sound_ucs1_1200w_15_horn_loaded.html

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Roundup Robot


Change by Roundup Robot :


--
pull_requests: +15872
pull_request: https://github.com/python/cpython/pull/16287

___
Python tracker 

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



[issue38147] add Py_ASSUME() macro for __builtin_unreachable()

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
title: add macro for __builtin_unreachable -> add Py_ASSUME() macro for 
__builtin_unreachable()

___
Python tracker 

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



[issue38147] add macro for __builtin_unreachable

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:

> Here's example: 
> https://github.com/sir-sigurd/cpython/commit/c8699d0c614a18d558216ae7d432107147c95c28.

"_Py_ASSUME((size_t)size <= MAX_LONG_DIGITS);"

Typically, such code use assert() and is removed for release build.

assert() is more for contract base programming: when the error "cannot" happen 
at runtime (it would be a programming error).

For other cases, I prefer to always emit code to handle the error (the error 
can happen, for example, the function must check inputs), even in release build.

--

___
Python tracker 

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



[issue38216] Fix for issue30458 prevents crafting invalid requests

2019-09-19 Thread Larry Hastings


Larry Hastings  added the comment:

FWIW I planned to tag and release 3.5.8 final early next week.  I don't have 
the domain knowledge to assess the severity of this bug--much less pitch in and 
help fix it--so I suspect this will simply hold up 3.5.8 final.

Depending on the complexity of the fix for this issue, I may also insert a 
second rc into the 3.5.8 schedule.

--

___
Python tracker 

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



[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Roundup Robot


Change by Roundup Robot :


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

___
Python tracker 

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



[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Miki Tebeka


Miki Tebeka  added the comment:

I don't think it violates " Explicit is better than implicit."
There's a lot of work done to make pathlib.Path objects work in places where 
str or bytes is expected (e.g PEP 519), IMO this is another case.

--

___
Python tracker 

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



[issue38147] add macro for __builtin_unreachable

2019-09-19 Thread Sergey Fedoseev


Sergey Fedoseev  added the comment:

> If you care of _PyLong_Copy() performance, you should somehow manually inline 
> _PyLong_New() inside _PyLong_Copy().

It doesn't solve this:

> We could add a function that bypass that check, but in LTO build 
> PyObject_MALLOC() is inlined into _PyLong_New() and it also checks the size. 
> Adding Py_ASSUME((size_t)size <= MAX_LONG_DIGITS) allows to bypass both 
> checks.

Here's example: 
https://github.com/sir-sigurd/cpython/commit/c8699d0c614a18d558216ae7d432107147c95c28.

I attach some disassembly from this example compiled with LTO, to demonstrate 
how the proposed macro affects generated code.

--
Added file: https://bugs.python.org/file48614/disasm.txt

___
Python tracker 

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



[issue25130] Make tests more PyPy compatible

2019-09-19 Thread Ronan Lamy


Change by Ronan Lamy :


--
nosy: +Ronan.Lamy

___
Python tracker 

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



Re: regular expressions help

2019-09-19 Thread Pradeep Patra
Thanks  David /Anthony for your help. I figured out the issue myself. I
dont need any ^, $ etc to the regex pattern and the plain string (for exp
my-dog) works fine. I am looking at creating a generic method so that
instead of passing my-dog i can pass my-cat or blah blah. I am thinking of
creating a list of probable combinations to search from the list. Anybody
have better ideas?

On Thu, Sep 19, 2019 at 3:46 PM David  wrote:

> On Thu, 19 Sep 2019 at 19:34, Pradeep Patra 
> wrote:
>
> > Thanks David for your quick help. Appreciate it. When I tried on python
> 2.7.3 the same thing you did below I got the error after matches.group(0)
> as follows:
> >
> > AttributeError: NoneType object has no attribute 'group'.
> >
> > I tried to check 'None' for no match for re.search as the documentation
> says but it's not working.
> >
> > Unfortunately I cannot update the python version now to 2.7.13 as other
> programs are using this version and need to test all and it requires more
> testing. Any idea how I can fix this ? I am ok to use any other re
> method(not only tied to re.search) as long as it works.
>
> Hi again Pradeep,
>
> We are now on email number seven, so I am
> going to try to give you some good advice ...
>
> When you ask on a forum like this for help, it is very
> important to show people exactly what you did.
> Everything that you did. In the shortest possible
> way that demonstrates whatever issue you are
> facing.
>
> It is best to give us a recipe that we can follow
> exactly that shows every step that you do when
> you have the problem that you need help with.
>
> And the best way to do that is for you to learn
> how to cut and paste between where you run
> your problem code, and where you send your
> email message to us.
>
> Please observe the way that I communicated with
> you last time. I sent you an exact cut and paste
> from my terminal, to help you by allowing you to
> duplicate exactly every step that I made.
>
> You should communicate with us in the same
> way. Because when you write something like
> your most recent message
>
> > I got the error after matches.group(0) as follows:
> > AttributeError: NoneType object has no attribute 'group'.
>
> this tells us nothing useful!! Because we cannot
> see everything you did leading up to that, so we
> cannot reproduce your problem.
>
> For us to help you, you need to show all the steps,
> the same way I did.
>
> Now, to help you, I found the same old version of
> Python 2 that you have, to prove to you that it works
> on your version.
>
> So you talking about updating Python is not going
> to help. Instead, you need to work out what you
> are doing that is causing your problem.
>
> Again, I cut and paste my whole session to show
> you, see below. Notice that the top lines show that
> it is the same version that you have.
>
> If you cut and paste my commands into
> your Python then it should work the same way
> for you too.
>
> If it does not work for you, then SHOW US THE
> WHOLE SESSION, EVERY STEP, so that we can
> reproduce your problem. Run your python in a terminal,
> and copy and paste the output you get into your message.
>
> $ python
> Python 2.7.3 (default, Jun 20 2016, 16:18:47)
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import re
> >>> mystr = "where is my-dog"
> >>> pattern = re.compile(r'my-dog$')
> >>> matches = re.search(pattern, mystr)
> >>> matches.group(0)
> 'my-dog'
> >>>
>
> I hope you realise that the re module has been used
> by thousands of programmers, for many years.
> So it's extremely unlikely that it "doesn't work" in a way that
> gets discovered by someone who hardly knows how to use it.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38205] Py_UNREACHABLE() no longer behaves as a function call

2019-09-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

_Py_NO_RETURN is a promise that the code past the function is unreachable, not 
that the function call is unreachable.

> I'm not sure how __builtin_unreachable could be used with Py_UNREACHABLE() 
> macro.

In the release mode Py_UNREACHABLE() can be replaced with 
__builtin_unreachable().

> For example, if a function accepts an enum, but is called with a value which 
> is not part of the enum: what should happen? Should Python crash?

If the accessibility of the code depends on the call from Python code, we 
should raise normal exception. If it is not possible to pass it out of the 
function, we should use PyErr_WriteUnraisable().

If the accessibility of the code depends on the call from C code, 
we can use PyErr_BadInternalCall() or raise a SystemError directly.

If we are in the situation where recovering from errors is not possible (for 
example if the memory manager is broken) we use Py_FatalError().

If we are absolutely sure that the code never can be executed (unless memory 
was corrupted or something like), we use Py_UNREACHABLE(). It will silence 
compiler complains, fail loudly in debug mode if our assumption is wrong (this 
is our programming bug), and allow the compiler to optimize out the code if 
substituted by __builtin_unreachable() in the release mode.

> I don't see how the compiler can guess that the code is never executed with 
> the current macro.

But we can make the macro to expand to __builtin_unreachable in the release 
mode. Or just to no-op if there is other way to silence the compiler warning.

> Using a function allows to put a breakpoint on it.

You can put a brackpoint on Py_FatalError().

> In fact, I can easily modify PR 16280 to keep the macro, since I only call 
> Py_FatalError() with a string.

It would be nice. We can consider using __builtin_unreachable() in different 
issue. I am also going to use Py_UNREACHABLE() more widely to write more 
uniform, but still optimal code. It could replace

if (cond1) { ...
} else if (cond2) { ...
} else if (cond3) { ...
} else {
assert (!cond4);
...
}

with

if (cond1) { ...
} else if (cond2) { ...
} else if (cond3) { ...
} else if (cond4) { ...
} else {
Py_UNREACHABLE();
}

--

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:

asyncio.run() now shutdowns the default executor: nice, thanks! That was my 
request. IMHO it will make asyncio more reliable, especially for tests on the 
CI.

If it becomes an issue in Python 3.9 (executor hangs forever), we can add new 
parameters (to run()?) to put a timeout for example.

--

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 079931d12223ec98cbf53185b90db48efa61f93f by Victor Stinner in 
branch 'master':
bpo-34037: test_asyncio uses shutdown_default_executor() (GH-16284)
https://github.com/python/cpython/commit/079931d12223ec98cbf53185b90db48efa61f93f


--

___
Python tracker 

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



[issue37531] Fix regrtest timeout for subprocesses: regrtest -jN --timeout=SECONDS

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +15870
pull_request: https://github.com/python/cpython/pull/16285

___
Python tracker 

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



[issue37531] Fix regrtest timeout for subprocesses: regrtest -jN --timeout=SECONDS

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset b2dd2dd6e9212ba6b03885b998736a180ef283d6 by Victor Stinner in 
branch 'master':
bpo-37531: Skip test_regrtest.test_multiprocessing_timeout() on all platforms 
(GH-16282)
https://github.com/python/cpython/commit/b2dd2dd6e9212ba6b03885b998736a180ef283d6


--

___
Python tracker 

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



[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

I'm also -0 on it. It's up to Antoine.

--

___
Python tracker 

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



[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I am -0 on this. It is a can of worms. Once we add a trivial __format__ in 
Path, we will need to handle numerous requests for adding a trivial __format__ 
in many other classes. It is better to teach users to use !s (and this works 
also on older Python versions!).

As for Path, there many ways to convert it to string: str(), repr(), 
os.fspath(), os.fsdecode(), Path.as_posix(), Path.as_uri(), with possible 
normalization, converting to absolute or relative path. I would not bet that we 
will never have reasons to have a different format specifier language for Path.

--

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +15869
pull_request: https://github.com/python/cpython/pull/16284

___
Python tracker 

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



Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote:

> Thank you, I'm currently investigating importlib and read that
> __builtins__ might be another alternative.
> My ultimate goal would be to have objects available without the need to
> import them, regardless whether used in a script directly or used in an
> imported module.

I'm not sure this is a good idea. Or rather, I'm pretty sure this isn't a 
good idea ;)

To quote the Zen of Python

>>> import this
The Zen of Python, by Tim Peters
[...]
Namespaces are one honking great idea -- let's do more of those!

It looks like you are replacing that line with

"Let's put everything into builtins -- so convenient, no!"

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38147] add macro for __builtin_unreachable

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:

> This check is redundant when _PyLong_New() is called from _PyLong_Copy().

If you care of _PyLong_Copy() performance, you should somehow manually inline 
_PyLong_New() inside _PyLong_Copy().

--

___
Python tracker 

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



[issue38147] add macro for __builtin_unreachable

2019-09-19 Thread STINNER Victor


STINNER Victor  added the comment:

> Real world example. _PyLong_Copy() [1] calls _PyLong_New() [2]. _PyLong_New() 
> checks the size, so that overflow does not occur. This check is redundant 
> when _PyLong_New() is called from _PyLong_Copy(). We could add a function 
> that bypass that check, but in LTO build PyObject_MALLOC() is inlined into 
> _PyLong_New() and it also checks the size. Adding Py_ASSUME((size_t)size <= 
> MAX_LONG_DIGITS) allows to bypass both checks. 

This sounds like a bad usage of __builtin_unreachable().

_PyLong_New() must always check that size <= MAX_LONG_DIGITS, the check must 
not be optimized by the compiler.

__builtin_unreachable() must only be used if the code really be reached by 
design.

For example:

if (...) { Py_FatalError("oops)"; __builtin_unreachable() }

But it's a bad example, since Py_FatalError is decorated with the "noreturn" 
attribute, so the compiler should already know that Py_FatalError() never 
returns.

--
nosy: +vstinner

___
Python tracker 

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



[issue38155] Add __all__ to the datetime module

2019-09-19 Thread Paul Ganssle


Paul Ganssle  added the comment:

Closing this as resolved. I don't think we should backport this, as it's more 
of an enhancement than a bug fix (and since no one has ever complained about it 
to my knowledge, I don't think there's any big rush to see this released).

Thanks Tahia and all the reviewers!

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



Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Richard Damon wrote:

> On 9/19/19 6:16 AM, Eko palypse wrote:
>>> In all cases, if the optional parts are omitted, the code is executed in
>>> the current scope. ...
>>>
>>>
>>> You can see from it that "globals" is optional.
>>> And that, if "globals" is missing, then
>>> "exec" is executed in the current scope ("f1" in your case).
>> Thank you for your answer, and that is exactly what confuses me?
>> Where does x come from? If I only would read x then I would understand
>> why it can be found/read but I alter it and as such I either have to
>> provide the info that this is a global variable, declare it inside of f1
>> or provide the globals dict to exec. But I don't do any of it. Why is
>> exec able to use the global x?
>>
>> Eren
> 
> I think the issue is that x += 1 isn't exactly like x = x + 1, and this
> is one case that shows it. x = x + 1 is an assignment to the symbol x,
> which makes x a local, and thus the read becomes an undefined symbol. x
> += 1 is different, it isn't a plain assignment so doesn't create the
> local. The read of x is inherently tied to the writing of x so x stays
> referring to the global.

I think you are wrong; both x += 1 and x = x + 1 turn x into a local 
variable: 

>>> def f():
...x += 1
... 
>>> x = 42
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
UnboundLocalError: local variable 'x' referenced before assignment
>>> def g():
... x = x + 1
... 
>>> g()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in g
UnboundLocalError: local variable 'x' referenced before assignment

The difference is that

x = x + 1

is evaluated as

x = x.__add__(1)

while x += 1 becomes

x = x.__iadd__(1)

For mutable x this allows modifying x in place with consequences likely to 
surprise when you see it for the first time:

>>> t = ["Nobody expects "],
>>> t[0] = t[0] + ["the Spanish inquisition"]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'tuple' object does not support item assignment
>>> t
(['Nobody expects '],)

The above creates a new list which cannot become the first item of the 
(immutable) tuple.

>>> t[0] += ["the Spanish inquisition"]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'tuple' object does not support item assignment

The above changes the first item of the tuple in place, but afterwards the 
attempt to rebind t[0] still fails.

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38155] Add __all__ to the datetime module

2019-09-19 Thread Paul Ganssle


Paul Ganssle  added the comment:


New changeset 96b1c59c71534db3f0f3799cd84e2006923a5098 by Paul Ganssle (t k) in 
branch 'master':
bpo-38155: Add __all__ to datetime module (GH-16203)
https://github.com/python/cpython/commit/96b1c59c71534db3f0f3799cd84e2006923a5098


--

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread Andrew Svetlov


Andrew Svetlov  added the comment:


New changeset 9fdc64cf1266b6d5bf0503847b5c38e5edc53a14 by Andrew Svetlov (Kyle 
Stanley) in branch 'master':
bpo-34037: Fix test_asyncio failure and add loop.shutdown_default_executor() 
(GH-15735)
https://github.com/python/cpython/commit/9fdc64cf1266b6d5bf0503847b5c38e5edc53a14


--

___
Python tracker 

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



[issue34037] asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads

2019-09-19 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

Thnks, Kyle!

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



Re: exec and globals and locals ...

2019-09-19 Thread Bev In TX
I’m not the OP, but I want to thank you for that clarification.  I had 
previously not understood the ramifications of the following in section “7. 
Simple statements” in “The Python Language Reference”:

“An augmented assignment expression like x += 1 can be rewritten as x = x + 1 
to achieve a similar, but not exactly equal effect. In the augmented version, x 
is only evaluated once. Also, when possible, the actual operation is performed 
in-place, meaning that rather than creating a new object and assigning that to 
the target, the old object is modified instead.”

Thanks again.

Bev

> On Sep 19, 2019, at 5:45 AM, Richard Damon  wrote:
> 
> I think the issue is that x += 1 isn't exactly like x = x + 1, and this
> is one case that shows it. x = x + 1 is an assignment to the symbol x,
> which makes x a local, and thus the read becomes an undefined symbol. x
> += 1 is different, it isn't a plain assignment so doesn't create the
> local. The read of x is inherently tied to the writing of x so x stays
> referring to the global.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38222] pathlib Path objects should support __format__

2019-09-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

I don't think anyone is suggesting reverting the decision on object.__format__. 
That decision should stay.

I think the suggestion is to add Path.__format__, which just converts to a 
string and formats with the given spec.

Unless someone can think of a reason to have a different format specifier 
language for Path, I think this is a good usability improvement.

--

___
Python tracker 

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



Re: exec and globals and locals ...

2019-09-19 Thread Richard Damon
On 9/19/19 6:52 AM, Eko palypse wrote:
> Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon:
>> On 9/19/19 6:16 AM, Eko palypse wrote:
 In all cases, if the optional parts are omitted, the code is executed in 
 the current scope. ...


 You can see from it that "globals" is optional.
 And that, if "globals" is missing, then
 "exec" is executed in the current scope ("f1" in your case).
>>> Thank you for your answer, and that is exactly what confuses me?
>>> Where does x come from? If I only would read x then I would understand why
>>> it can be found/read but I alter it and as such I either have to provide the
>>> info that this is a global variable, declare it inside of f1 or provide 
>>> the globals dict to exec. But I don't do any of it. Why is exec able to use
>>> the global x?
>>>
>>> Eren
>> I think the issue is that x += 1 isn't exactly like x = x + 1, and this
>> is one case that shows it. x = x + 1 is an assignment to the symbol x,
>> which makes x a local, and thus the read becomes an undefined symbol. x
>> += 1 is different, it isn't a plain assignment so doesn't create the
>> local. The read of x is inherently tied to the writing of x so x stays
>> referring to the global.
>>
>> -- 
>> Richard Damon
> Thank you that would never have come to my mind.
> I thought +=1 is just syntactic sugar which clearly isn't.
> If I do the regular x = x + 1 then I do get the expected exception.
>
> Thank you
> Eren

For some objects, += even (possibly) calls a different function __radd__
instead of __add__ (if __radd__ doesn't exist then python will fall back
to using __add__)

This can have a big difference in the case of sharing mutable objects.

x = [1, 2]

y = x

x += [3]

# Now x and y are [1, 2, 3]

x = x + [4]

# Now x = [1, 2, 3, 4] but y is still [1, 2, 3]


-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 12:56:59 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
> 
> >> Then it should be clear that the name 'test01' is put into globals(), if
> >> load_module() doesn't throw an exception. No sharing or nesting of
> >> namespaces takes place.
> > 
> > Thank you too for your answer. Ok, that means that in every case when exec
> > imports something it has its own global namespace, right?
> > Is there a way to manipulate this namespace before any code from that
> > module gets executed?
> 
> Create a module object, preload its namespace, then exec the module's code, 
> like:
> 
> $ python3
> Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys, types
> >>> module = types.ModuleType("module")
> >>> module.x = 42
> >>> exec("print(x)\ndef f(): return x * x", module.__dict__)
> 42
> >>> sys.modules["module"] = module
> >>> import module
> >>> module.f()
> 1764
> 
> The importlib probably has an official way, but I've yet to wrap my head 
> around that part of Python.

Thank you, I'm currently investigating importlib and read that __builtins__
might be another alternative.
My ultimate goal would be to have objects available without the need to import 
them, regardless whether used in a script directly or used in an imported 
module.

Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote:

>> Then it should be clear that the name 'test01' is put into globals(), if
>> load_module() doesn't throw an exception. No sharing or nesting of
>> namespaces takes place.
> 
> Thank you too for your answer. Ok, that means that in every case when exec
> imports something it has its own global namespace, right?
> Is there a way to manipulate this namespace before any code from that
> module gets executed?

Create a module object, preload its namespace, then exec the module's code, 
like:

$ python3
Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, types
>>> module = types.ModuleType("module")
>>> module.x = 42
>>> exec("print(x)\ndef f(): return x * x", module.__dict__)
42
>>> sys.modules["module"] = module
>>> import module
>>> module.f()
1764

The importlib probably has an official way, but I've yet to wrap my head 
around that part of Python.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon:
> On 9/19/19 6:16 AM, Eko palypse wrote:
> >> In all cases, if the optional parts are omitted, the code is executed in 
> >> the current scope. ...
> >>
> >>
> >> You can see from it that "globals" is optional.
> >> And that, if "globals" is missing, then
> >> "exec" is executed in the current scope ("f1" in your case).
> > Thank you for your answer, and that is exactly what confuses me?
> > Where does x come from? If I only would read x then I would understand why
> > it can be found/read but I alter it and as such I either have to provide the
> > info that this is a global variable, declare it inside of f1 or provide 
> > the globals dict to exec. But I don't do any of it. Why is exec able to use
> > the global x?
> >
> > Eren
> 
> I think the issue is that x += 1 isn't exactly like x = x + 1, and this
> is one case that shows it. x = x + 1 is an assignment to the symbol x,
> which makes x a local, and thus the read becomes an undefined symbol. x
> += 1 is different, it isn't a plain assignment so doesn't create the
> local. The read of x is inherently tied to the writing of x so x stays
> referring to the global.
> 
> -- 
> Richard Damon

Thank you that would never have come to my mind.
I thought +=1 is just syntactic sugar which clearly isn't.
If I do the regular x = x + 1 then I do get the expected exception.

Thank you
Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exec and globals and locals ...

2019-09-19 Thread Richard Damon
On 9/19/19 6:16 AM, Eko palypse wrote:
>> In all cases, if the optional parts are omitted, the code is executed in the 
>> current scope. ...
>>
>>
>> You can see from it that "globals" is optional.
>> And that, if "globals" is missing, then
>> "exec" is executed in the current scope ("f1" in your case).
> Thank you for your answer, and that is exactly what confuses me?
> Where does x come from? If I only would read x then I would understand why
> it can be found/read but I alter it and as such I either have to provide the
> info that this is a global variable, declare it inside of f1 or provide 
> the globals dict to exec. But I don't do any of it. Why is exec able to use
> the global x?
>
> Eren

I think the issue is that x += 1 isn't exactly like x = x + 1, and this
is one case that shows it. x = x + 1 is an assignment to the symbol x,
which makes x a local, and thus the read becomes an undefined symbol. x
+= 1 is different, it isn't a plain assignment so doesn't create the
local. The read of x is inherently tied to the writing of x so x stays
referring to the global.

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >