[issue42836] docs: struct: clarify struct caching behaviour

2021-01-07 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
nosy: +python-dev
nosy_count: 2.0 -> 3.0
pull_requests: +22992
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24164

___
Python tracker 

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



[issue42836] docs: struct: clarify struct caching behaviour

2021-01-06 Thread Sandeep Subramanian

New submission from Sandeep Subramanian :

As per docs in :https://docs.python.org/3.7/library/struct.html#struct.Struct

> The compiled versions of the most recent format strings passed to Struct and 
> the module-level functions are cached, so programs that use only a few format 
> strings needn’t worry about reusing a single Struct instance.

This statement seems to imply that the format string passed as 
`struct.Struct(format)` is also cached. This doesn't appear to be the case.

Only format strings passed to the module level functions seems to be cached.

`cache_struct_converter` at 
https://github.com/python/cpython/blob/v3.7.7/Modules/_struct.c#L2052 
appears to be used only in the top module level functions `pack` and 
`pack_into` and is *not* used in `Struct.__init__`.


Would it be better to change the doc to:

> The compiled versions of the most recent format strings passed to the 
> module-level functions are cached, so programs that use only a few format 
> strings needn’t worry about reusing a single Struct instance.

This issue was introduced by 
https://github.com/python/cpython/commit/3666b3c1f695a145adab1bf644c22e564e8eb0ee

and is present in every version since.

Refs:
https://github.com/python/cpython/pull/7700
https://bugs.python.org/issue33032

--
assignee: docs@python
components: Documentation
messages: 384476
nosy: docs@python, sandeep2
priority: normal
severity: normal
status: open
title: docs: struct: clarify struct caching behaviour
type: enhancement
versions: Python 3.10, 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