[issue39105] Spam

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
components:  -asyncio
nosy:  -asvetlov, yselivanov
stage:  -> resolved
status: open -> closed
title: Printer offline -> Spam

___
Python tracker 

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



[issue39105] Printer offline

2019-12-19 Thread Printer offline


New submission from Printer offline :

This blog has increased the level of information sharing. I just simply loved 
this blog. It has helped me a lot. A great and learning blog. I am very 
satisfied after reading this. https://www.printer-offline.com/

--
components: asyncio
files: Roko-Logo-2-fi18353094x260.png
messages: 358698
nosy: Printer offline, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Printer offline
type: resource usage
versions: Python 3.8
Added file: https://bugs.python.org/file48795/Roko-Logo-2-fi18353094x260.png

___
Python tracker 

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



[issue39104] ProcessPoolExecutor hangs on shutdown nowait with pickling failure

2019-12-19 Thread Thomas Moreau


Change by Thomas Moreau :


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

___
Python tracker 

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



[issue39104] ProcessPoolExecutor hangs on shutdown nowait with pickling failure

2019-12-19 Thread Thomas Moreau


New submission from Thomas Moreau :

The attached scripts hangs on python3.7+.
This is due to the fact that the main process closes the communication channels 
directly while the queue_management_thread might still use them.

To prevent that, all the closing should be handled by the 
queue_management_thread.

--
components: Library (Lib)
files: main.py
messages: 358697
nosy: tomMoral
priority: normal
severity: normal
status: open
title: ProcessPoolExecutor hangs on shutdown nowait with pickling failure
versions: Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48794/main.py

___
Python tracker 

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



[issue39103] [linux] strftime renders %Y with only 3 characters

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



[issue39102] Increase Enum performance

2019-12-19 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman

___
Python tracker 

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



[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Thought experiment: Suppose someone proposed, "math.log(x) should take an 
optional default argument because it is inconvenient to a catch a ValueError if 
the input is non-positive".   Or more generally, what if someone proposed, 
"every function in Python that can raise a ValueError should offer a default 
argument."  One could imagine a use case for both of these proposals but that 
doesn't mean that the API extensions would be warranted.

Also, ISTM the analogy to min() and max() is imperfect.  Those aren't 
descriptive statistics.  For min() and max() we can know a priori that a 
probability is never lower than 0.0 or greater than 1.0 for example.

Lastly, in common cases where the input is a sequence (rather than just an 
iterator), we already have a ternary operator to does the job nicely:

   central_value = mean(data) if data else 'unknown'

For the less common case, a try/except is not an undue burden; after all, it is 
a basic core language feature.

--

___
Python tracker 

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



[issue39103] [linux] strftime renders %Y with only 3 characters

2019-12-19 Thread Jason R. Coombs


New submission from Jason R. Coombs :

On Python 3.8, there's a difference between how datetime.datetime.strftime 
renders %Y for years < 1000 between Linux and other platforms.

# Linux
$ docker run -it python python -c 'import datetime; 
print(datetime.date(900,1,1).strftime("%Y"))'   
900

# macOS
$ python -c 'import datetime; print(datetime.date(900,1,1).strftime("%Y"))' 

0900


According to the docs 
(https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior), 
one should expect `''` for year zero and so I'd expect `'0900'` for the 
year 900, so the macOS behavior looks correct to me.

--
components: Library (Lib)
messages: 358695
nosy: jaraco
priority: normal
severity: normal
status: open
title: [linux] strftime renders %Y with only 3 characters
versions: Python 3.8

___
Python tracker 

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



[issue39102] Increase Enum performance

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +barry, eli.bendersky, ethan.furman

___
Python tracker 

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



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


Change by Arseny Boykov :


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

___
Python tracker 

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



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


New submission from Arseny Boykov :

Now enum has very poor speed on trying values and attributes access (especially 
when it comes to accessing members name/value attrs)

There are two major reasons why attrs access is slow:
  - All values/names access going through DynamicClassAttribute (x10 slower 
than accessing attr directly)
  - EnumMeta has __getattr__ which is slowing down even direct class attributes 
access (up to x6 slower)

However, there are no need to use it, as we could just set value and name to 
newly created enum members without affecting its class.

The main issue with values check is the slow _missing_ hook handling when it 
raising exception, which happens pretty much always, if value is not valid enum 
and we talking about vanilla Enum class.

Also I found Flag performance issue being fixed already:
https://bugs.python.org/issue38045
It's also related, because new Flag creation involves many member.name lookups


My proposal:
  - I think we should completely get rid of __getattr__ on Enum (~6x speed 
boost)
  - Rework DynamicClassAttribute so it could work without __getattr__ or 
perhaps completely get rid of it
  - Don't use DynamicClassAttribute for member.name and .value (~10x speed 
boost)
  - Think of faster handling of _missing_ hook  (~2x speed boost)
  - Make other improvements to the code


Proposed changes doesn't require changing public API or behaviour.

By far I were able to implement almost things proposed here and will be happy 
to make a PR.

--
components: Library (Lib)
files: benchmark_result.txt
messages: 358694
nosy: MrMrRobat
priority: normal
severity: normal
status: open
title: Increase Enum performance
type: performance
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48793/benchmark_result.txt

___
Python tracker 

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



[issue38815] test_ssl: test_min_max_version() fails on FreeBSD and Fedora

2019-12-19 Thread Kubilay Kocak


Kubilay Kocak  added the comment:

@Christian As current assignee, are you able to produce a test that fixes the 
remaining issue (per msg357792)? I can rebuild OpenSSL on the worker at your 
direction at any time to make the test fail again or provide you with an SSH 
account to assist

--
stage: patch review -> needs patch

___
Python tracker 

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



[issue39099] scandir.dirfd() method

2019-12-19 Thread Eryk Sun


Eryk Sun  added the comment:

> I am not sure if it's possible to also support Windows.

For reference, FindFirstFileW doesn't support handle-relative names, and 
neither does CreateFileW. At a lower level in Windows NT, NtCreateFile has 
always supported handle-relative names, but CPython doesn't use the NT API.

fd support (not dirfd) could be added to listdir and scandir in Windows. A 
directory can be listed via GetFileInformationByHandleEx: 
FileFullDirectoryInfo. This doesn't query the short name, so it may perform 
better than FindFirstFileW. However, opening a directory with os.open can't be 
supported. VC++ still hasn't documented the _O_OBTAIN_DIR (0x2000) flag.

--
nosy: +eryksun

___
Python tracker 

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



[issue38971] codecs.open leaks file descriptor when invalid encoding is passed

2019-12-19 Thread Roundup Robot


Change by Roundup Robot :


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

___
Python tracker 

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



[issue39070] Uninstalling 3.8.0 fails but it says it succeeds..

2019-12-19 Thread Steve Dower


Steve Dower  added the comment:

The only issue I see in that log is an apparent failure communicating between 
the unelevated and the elevated components of the uninstaller. But that doesn't 
seem to have interfered with the rest of the process, so I'm at a bit of a loss.

Possibly it has gotten confused because of running as administrator to install 
the py.exe launcher for all users, but not the rest of it.

When you say the system asked for admin right - do you mean you had to 
authenticate as a different user? Or you had to click "Yes" to give it 
permissions?

--

___
Python tracker 

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



[issue39101] IsolatedAsyncioTestCase freezes when exception is raised

2019-12-19 Thread Fabio Pugliese Ornellas


Change by Fabio Pugliese Ornellas :


--
type:  -> crash

___
Python tracker 

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



[issue39101] IsolatedAsyncioTestCase freezes when exception is raised

2019-12-19 Thread Fabio Pugliese Ornellas


New submission from Fabio Pugliese Ornellas :

IsolatedAsyncioTestCase freezes whenever an exception that inherits from 
BaseException is raised:


import unittest
class TestHangsForever(unittest.IsolatedAsyncioTestCase):
async def test_hangs_forever(self):
raise BaseException("Hangs forever")
if __name__ == "__main__":
import unittest
unittest.main()

A kind of similar issue present on 3.7 was fixed on 3.8 here 
https://github.com/python/cpython/blob/3.8/Lib/asyncio/events.py#L84, where 
BaseExceptions would not be correctly handled by the event loop, this seems 
somewhat related.

I had a look at IsolatedAsyncioTestCase implementation, did not spot any 
obvious broken thing there, I could use some light here. Thanks.

--
components: asyncio
messages: 358690
nosy: asvetlov, fornellas, yselivanov
priority: normal
severity: normal
status: open
title: IsolatedAsyncioTestCase freezes when exception is raised
versions: Python 3.8

___
Python tracker 

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



[issue39100] email.policy.SMTP throws AttributeError on invalid header

2019-12-19 Thread Anton Khirnov


New submission from Anton Khirnov :

When parsing a (broken) mail from linux-me...@vger.kernel.org (message-id 
20190212181908.horde.peighvv2khy9ekuy8ta8...@webmail.your-server.de, headers 
attached) with email.policy.SMTP, I get an AttributeError on trying to read the 
'to' header:

/usr/lib/python3.7/email/headerregistry.py in (.0)
345  mb.local_part or '',
346  mb.domain or '')
--> 347  for mb in addr.all_mailboxes]))
348 defects = list(address_list.all_defects)
349 else:

AttributeError: 'Group' object has no attribute 'local_part'

The header in question is:
To: unlisted-recipients:; (no To-header on input)

The problem seems to be that mb is a Group and not an Address, gets token_type 
of 'invalid-mailbox', but does not have the attributes local_part/domain that 
are expected in mailboxes. Copying the line

local_part = domain = route = addr_spec = display_name

from InvalidMailbox to Group fixes this, but it is not clear to me this is the 
right solution, so not sending a patch.

--
components: email
files: mail.eml
messages: 358689
nosy: barry, elenril, r.david.murray
priority: normal
severity: normal
status: open
title: email.policy.SMTP throws AttributeError on invalid header
type: behavior
Added file: https://bugs.python.org/file48792/mail.eml

___
Python tracker 

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



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Giampaolo Rodola'  added the comment:

Good point, I didn't consider that. I suppose you're right. =)
Closing.

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



[issue39099] scandir.dirfd() method

2019-12-19 Thread Benjamin Peterson


Benjamin Peterson  added the comment:

Why not just os.open the directory yourself and pass it to os.scandir?

--
nosy: +benjamin.peterson

___
Python tracker 

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



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


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

___
Python tracker 

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



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


New submission from Giampaolo Rodola' :

PR in attachment adds a new dirfd() method to the scandir() object (POSIX 
only). This can be be passed to os.* functions supporting the "dir_fd" 
parameter, and avoid opening a new fd as in:

>>> dirfd = os.open("basename", os.O_RDONLY, dir_fd=topfd)

At the moment I am not sure if it's possible to also support Windows.

--
components: Library (Lib)
messages: 358686
nosy: giampaolo.rodola
priority: normal
severity: normal
status: open
title: scandir.dirfd() method
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



[issue39093] tkinter objects garbage collected from non-tkinter thread cause panic and core dump

2019-12-19 Thread obserience


obserience  added the comment:

My proposed fix isn't compatible with a lot of current Tkinter using code. It 
was a naive first attempt and breaks existing code and doesn't completely solve 
the problem.

Variables currently retain a reference to the TCL interpreter self._tk and 
aren't linked into the widget tree or otherwise accessible to any cleanup logic.

Existing code:
-may expect the self.tk attribute of destroyed widgets to still be set

Existing code (after calling root.destroy()):
-calls methods like Tk.quit() which runs Tcl commands requiring self.tk to 
still be there
--Idle does this "# (Needed for clean exit on Windows 98)" <--apparently
---is this still the case??
-may call get() and set() on Variable instances (this currently works)


Given this it might be better to track all references to the TCL interpreter in 
a separate data structure and add a Tk.cleanup() method that gets rid of them 
all with documentation indicating all calls after this will fail. Alternate 
implementation of this deallocates the TCL interpreter in the _tkinter.c 
bindings with the same results.

One of the core issues here is that the cause of the crash is asynchronous 
signal handlers installed by the TCL library and necessary for the TCL 
interpreter to run at all. If you can run TCL commands, the crash can still be 
triggered.

###separate issue###
The Tk.Quit() doc is wrong. Current inline docs say that it destroys all 
widgets, which it does not. All it seems to do is cause mainloop to return 
after which mainloop can be called again and the GUI resumes functioning. This 
has caused problems when the main thread doesn't exit since the GUI continues 
to exist but is frozen. (See quit_behavior.py)

--
Added file: https://bugs.python.org/file48791/quit_behavior.py

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17130
pull_request: https://github.com/python/cpython/pull/17662

___
Python tracker 

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



[issue38980] Compile libpython with -fno-semantic-interposition

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

Pablo:
> I have seen people using LD_PRELOAD (...) to interpose faster versions of 
> some functions or to collect metrics (although there are better ways).

IMHO if someone has to go so far into "hacking" Python, they should recompile 
Python with specific options. I'm not sure that using LD_PRELOAD to get "faster 
versions of some functions" is the best approach in term of performance, but I 
expect it to be convenient :-)


Charalampos:
> I think it will add to the complexity of the --with-optimizations flag which 
> already implies PGO and LTO.

It doesn't enable LTO, only PGO :-) We had to disable LTO because of multiple 
compiler bugs last years.


Serhiy:
> I am sure some C API functions are purposed to be overridden.

Is it a theorical use case, or are you aware of such use case being currently 
used in the wild?


Ammar Askar:
> Just for a quick datapoint: llvm/clang do this by default and you need an 
> explicit `-fsemantic-interposition` to disable it 
> http://lists.llvm.org/pipermail/llvm-dev/2016-November/107625.html

Oh, that's really interesting, thanks!

--

___
Python tracker 

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



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread STINNER Victor

STINNER Victor  added the comment:

Thanks Paul Sokolovsky for the bug report and thanks Batuhan Taşkaya for the 
fix ;-)

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



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread miss-islington

miss-islington  added the comment:


New changeset eba61f33d60cc63e35d5f5fcada837a66c89774a by Miss Islington (bot) 
(Batuhan Taşkaya) in branch '3.8':
[3.8] bpo-38316: Fix co_stacksize documentation (GH-16983) (GH-17661)
https://github.com/python/cpython/commit/eba61f33d60cc63e35d5f5fcada837a66c89774a


--

___
Python tracker 

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



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread miss-islington

miss-islington  added the comment:


New changeset 917419f58b2869d71691c5ba54a9e02e5dcf73b2 by Miss Islington (bot) 
(Batuhan Taşkaya) in branch '3.7':
[3.7] bpo-38316: Fix co_stacksize documentation (GH-16983). (GH-17660)
https://github.com/python/cpython/commit/917419f58b2869d71691c5ba54a9e02e5dcf73b2


--
nosy: +miss-islington

___
Python tracker 

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



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17128
pull_request: https://github.com/python/cpython/pull/17660

___
Python tracker 

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



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17129
pull_request: https://github.com/python/cpython/pull/17661

___
Python tracker 

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



[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith, mark.dickinson

___
Python tracker 

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



[issue34850] Emit a syntax warning for "is" with a literal

2019-12-19 Thread thautwarm


thautwarm  added the comment:

Thanks.
However, unfortunately, this warning seems impossible to suppress.

Use following example:

  import warnings
  warnings.filterwarnings('ignore')

  warnings.warn(SyntaxWarning("test"))

  def f(x):
return x is 5

  print(f(5))

I succeeded in suppressing my own  SyntaxWarning("test") , but the output is 
still:
  
  python a.py
  a.py:7: SyntaxWarning: "is" with a literal. Did you mean "=="?
return x is 5
  True

--

___
Python tracker 

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



[issue39098] OSError: handle is closed in ProcessPoolExecutor on shutdown(wait=False)

2019-12-19 Thread Patrick Buxton


New submission from Patrick Buxton :

When shutting down a ProcessPoolExecutor with wait=False, an `OSError: handle 
is closed` is raised.

The error can be replicated with a script as simple as:

```
from concurrent.futures import ProcessPoolExecutor

e = ProcessPoolExecutor()
e.submit(id)
e.shutdown(wait=False)

--
components: Library (Lib)
messages: 358679
nosy: patbuxton
priority: normal
severity: normal
status: open
title: OSError: handle is closed in ProcessPoolExecutor  on shutdown(wait=False)
type: crash
versions: 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



[issue11245] Implementation of IMAP IDLE in imaplib?

2019-12-19 Thread Josh de Kock


Josh de Kock  added the comment:

Hi, I'm new to python but I had a go at implementing this for imaplib(1) using 
a different approach. It works but it has a couple issues (see patch), I would 
appreciate any thoughts/improvements.

--
nosy: +jdek
versions: +Python 3.9 -Python 3.6
Added file: 
https://bugs.python.org/file48790/0001-Add-IDLE-support-to-imaplib.patch

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Change by Inada Naoki :


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

___
Python tracker 

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



[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread songyuc


songyuc <466309...@qq.com> added the comment:

Hi, Andrew!
Thanks for your explanation! I am sorry about my unfamiliarity about the 
shortcut, as a student from China whose mother tongue is not English. So I am 
not quite familiar with the English customs in Computer engineering.

--

___
Python tracker 

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



[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

While your suggestion is technically correct, CPU as a shortcut for "logical 
processor" is very common in software engineering.

For me, "number of CPU threads" is more unclear than just "number of CPUs"

--
nosy: +asvetlov

___
Python tracker 

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



[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread songyuc


New submission from songyuc <466309...@qq.com>:

In the documentation of Python 3.7, the description of 
multiprocessing.cpu_count() is "Return the number of CPUs in the system.", but, 
in fact, this function return the CPU threads number.

--
assignee: docs@python
components: Documentation
messages: 358675
nosy: docs@python, songyuc
priority: normal
severity: normal
status: open
type: enhancement
versions: Python 3.7

___
Python tracker 

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



[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

TL;DR: I'm not likely to accept this feature request without at least one of 
(1) a practical use-case, (2) prior art in other statistics software, or (3) a 
strong mathematical justification for why this is meaningful and useful.


I'm not categorically against this idea, but it seems a bit fishy to me. If you 
have no data, how do you know what default value to give that would be 
appropriate for your (non-existent) observations?

It might help if you could show a real-life example of how, and why, you would 
use this, and how you would choose the default?

Another possibility would be to find prior-art: another language, library or 
stats calculator which already offers this feature.

Alternatively, a mathematical/statistical justification for a default. For 
example, the empty sum is normally taken as 0 and the empty product as 1. R 
returns either a NAN or NA for the empty mean (depending on precisely how you 
calculate it).

While I'm personally sympathetic to the nuisance factor of having to wrap code 
in try...except blocks (my *personal* preference would have been for mean to 
return NAN on empty input) I think you will need to make a stronger case than 
just the analogy with min and max.

--

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

> Don't you need to DECREF bytes somehow, at least, in case of failure?

Thanks.  I will create a pull request with suggested changes.

--

___
Python tracker 

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



[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

> I've tried think of other solutions, such as a generic wrapper for such 
> functions or a helper to check whether an iterable is empty, and they all 
> turn out to be very clunky to use and un-Pythonic.

So the main use case would be to detect an empty iterable in an efficient 
fashion? Something like the following code?

sentinel = objet()
avg = mean(data, default=sentinel)
if avg is sentinel:
   ... # special code path

Why not adding a statistics.StatisticsError subclass for empty set (ex: 
StatisticsEmptyError)? Something like:

try:
   avg = mean(data)
except statistics.StatisticsEmptyError:
   ... # special code path, ex: avg = default

Or is there another use case for the proposed default parameter?

--
nosy: +vstinner

___
Python tracker 

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



[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Mark Dickinson


Mark Dickinson  added the comment:

What would the proposal look like for `statistics.stdev`? There you need at 
least two data points to compute a result, and a user might want to do 
different things for an empty dataset versus a single data point.

--
nosy: +mark.dickinson

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

return PyBytesType.tp_as_buffer(bytes, view, PyBUF_CONTIG_RO);

Don't you need to DECREF bytes somehow, at least, in case of failure?

--

___
Python tracker 

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



[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Michael Amrhein


Michael Amrhein  added the comment:

For a discussion of the different behaviour of float and Decimal see 
https://bugs.python.org/issue39077.

--

___
Python tracker 

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



[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-19 Thread Michael Amrhein


Michael Amrhein  added the comment:

Created new issue for tracking the deficiencies in the documentation:
https://bugs.python.org/issue39096.

--
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Michael Amrhein


New submission from Michael Amrhein :

The description of the "Format Specification Mini-Language" states for float 
and Decimal regarding presentation type 'f':
"The default precision is 6."
Regarding presentation type None it reads:
"Similar to 'g', except that fixed-point notation, when used, has at least one 
digit past the decimal point."
While both statements are accurate for float, they don't hold for Decimal.
In order to preserve the information about the decimal exponent, in both cases 
Decimal formatting displays as many fractional digits as dictated by it's 
exponent.

--
assignee: docs@python
components: Documentation
messages: 358667
nosy: docs@python, mamrhein
priority: normal
severity: normal
status: open
title: Description of "Format Specification Mini-Language" not accurate for 
Decimal
type: behavior
versions: 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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

s/return NULL/return -1/g

--

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

> Would it be possible to use a "container" object like a Py_buffer? Is there a 
> way to customize the code executed when a Py_buffer is "released"?

It looks nice idea!  Py_buffer.obj is decref-ed when releasing the buffer.
https://docs.python.org/3/c-api/buffer.html#c.PyBuffer_Release


int PyUnicode_GetUTF8Buffer(PyObject *unicode, Py_buffer *view)
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(unicode) == -1) {
return NULL;
}

if (PyUnicode_UTF8(unicode) != NULL) {
return PyBuffer_FillInfo(view, unicode,
 PyUnicode_UTF8(unicode),
 PyUnicode_UTF8_LENGTH(unicode),
 1, PyBUF_CONTIG_RO);
}
PyObject *bytes = _PyUnicode_AsUTF8String(unicode, NULL);
if (bytes == NULL) {
return NULL;
}
return PyBytesType.tp_as_buffer(bytes, view, PyBUF_CONTIG_RO);
}

--
nosy:  -skrah

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

> Would it be possible to use a "container" object like a Py_buffer?

Looks like a good idea.

int PyUnicode_GetUTF8Buffer(Py_buffer *view, const char *errors)

--
nosy: +skrah

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

> The returned object is the owner of the *utf8*.  You need to Py_DECREF() it 
> after
> you finished to using the *utf8*.  The owner may be not the unicode.

Would it be possible to use a "container" object like a Py_buffer? Is there a 
way to customize the code executed when a Py_buffer is "released"?

Py_buffer would be nice since it already has a pointer attribute (data) and a 
length attribute, and there is an API to "release" a Py_buffer. It can be 
marked as read-only, etc.

--

___
Python tracker 

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



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Do you mean some concrete code? Several times I wished similar feature. To get 
a UTF-8 cache if it exists and encode to UTF-8 without creating a cache 
otherwise. 

The private _PyUnicode_UTF8() macro could help

if ((s = _PyUnicode_UTF8(str))) {
size = _PyUnicode_UTF8_LENGTH(str);
tmpbytes = NULL;
}
else {
tmpbytes = _PyUnicode_AsUTF8String(str, "replace");
s = PyBytes_AS_STRING(tmpbytes);
size = PyBytes_GET_SIZE(tmpbytes);
}

but it is not even available outside of unicodeobject.c.

PyUnicode_BorrowUTF8() looks too complex for the public API. I am not sure that 
it will be easy to implement it in PyPy. It also does not cover all use cases 
-- sometimes you want to convert to UTF-8 but does not use any memory 
allocation at all (either use an existing buffer or raise an error if there is 
no cached UTF-8 or the string is not ASCII).

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue20443] __code__. co_filename should always be an absolute path

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

I reverted my change, so I remove "release blocker" priority.

--
priority: release blocker -> 

___
Python tracker 

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