[issue44555] Dictionary operations are LINEAR for any dictionary (for a particular code).

2021-07-02 Thread Daniel Fleischman


Daniel Fleischman  added the comment:

Please find attached a more complete example of the issue I am reporting.

tl;dr: I can make `sum(d.values())` run in O(maximum_size_in_d's_history) 
instead of O(len(d)), even when len(d) == 1.

The linked list approach would work in terms of making it faster, but we would 
still be using too much space.

--
Added file: https://bugs.python.org/file50138/bad_dict_example.py

___
Python tracker 

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



[issue44550] DIGITAL CLASSROOM

2021-07-02 Thread skoolbeep


New submission from skoolbeep :

A digital classroom setup can be defined as a learning environment created with 
the help of electronic devices that run on software programmes. This means 
technology sets the tone of a digital classroom and facilitates access to 
networks and learning resources
https://www.skoolbeep.com/blog/what-makes-up-a-good-digital-classroom/

--
status: closed -> open
title: SPAM -> DIGITAL CLASSROOM
versions: +Python 3.11

___
Python tracker 

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



[issue44555] Dictionary operations are LINEAR for any dictionary (for a particular code).

2021-07-02 Thread Daniel Fleischman


Daniel Fleischman  added the comment:

Thank you for your message!

I'm not particularly looking for an implementation, I was just surprised by
this behavior.

It can get even worse. Consider this example:

```
d = large_dict()
# remove all but one element of d, runs in quadratic time as explained above
while len(d) > 1:
del d[next(iter(d))]

# now iterating over d takes O(d), even when d has only one item:

# the following prints one key, but takes O(N)
for key in d:
print(key)
```

I think this example is better, since a person would expect iterating over
a singleton dictionary would be really fast, but it can be made as slow as
one wants. A "print_keys()" function would reasonably be expected to take
O(size of dictionary), but it doesn't.

Am I right to think that this is a performance bug?

On Fri, Jul 2, 2021, 8:10 PM Dennis Sweeney  wrote:

>
> Dennis Sweeney  added the comment:
>
> For what it's worth, using collections.OrderedDict gives constant-time
> behavior you're looking for.
>
> --
> nosy: +Dennis Sweeney
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

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



[issue43336] document whether io.TextIOBase.readline(size>0) will always read the full newline

2021-07-02 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I don't think it's incorrect right now, from the POV of internal data of the 
stream, there's 6 chars, from the POV of caller, 5 chars are read. So this can 
be interpreted as 2 chars are combined into 1 char read.

On the other hand if TextIOBase was reading '\r' and letting caller process it 
and then reading '\n' that would be of course a recipe to shoot the user in 
the foot, and would require a warning in big red letters in the docs. (Or even 
better fixing it to do what it does now.)

--
nosy: +andrei.avk

___
Python tracker 

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



[issue44555] Dictionary operations are LINEAR for any dictionary (for a particular code).

2021-07-02 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

For what it's worth, using collections.OrderedDict gives constant-time behavior 
you're looking for.

--
nosy: +Dennis Sweeney

___
Python tracker 

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



[issue44556] ctypes unittest crashes with libffi 3.4.2

2021-07-02 Thread Zan


New submission from Zan :

Running the unittests after upgrading libffi to latest version 3.4.2 and 
recompiling python, leads to several tests in Lib/ctypes/test/ to crash with 
Abort: trap 6. This does not happen with version 3.3 of libffi.

Steps to reproduce:

git clone https://github.com/libffi/libffi
cd libffi
autoreconf -fvi
export CC=/usr/bin/clang
./configure
make
sudo make install # installs into /usr/local

git clone https://github.com/python/CPython
cd CPython
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="-I/usr/local/include" 
export LDFLAGS="-L/usr/local/lib"
./configure --with-system-ffi
make
./python Lib/ctypes/test/__main__.py -v

...
test_callbacks (ctypes.test.test_as_parameter.AsParamPropertyWrapperTestCase) 
... Abort trap: 6

If I repeat the above steps with 'git checkout v3.3' in libffi, all tests in 
ctypes complete successfully.

Tested with :
- python 3.11 commit ec8759b0 (current master), also tried 3.8.11
- libffi 3.4.2
- macOS 11.4, Xcode 12.5.1
- MacBook Air, x86_64, Intel Sky Lake, i5-8210Y

--
components: ctypes
messages: 396885
nosy: zan
priority: normal
severity: normal
status: open
title: ctypes unittest crashes with libffi 3.4.2
type: crash
versions: Python 3.11, Python 3.8

___
Python tracker 

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



[issue43493] EmailMessage mis-folding headers of a certain length

2021-07-02 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I've looked into this and it seems to be somewhat intentional, as can be seen 
in this test case for example:

test_headerregistry.py", line 1725, in test_fold_address_list
+ To: "Theodore H. Perfect" ,
+  "My address is very long because my name is long" ,
+  "Only A. Friend" 

Relevant code is here: 
https://github.com/python/cpython/blob/main/Lib/email/_header_value_parser.py#L2829-L2849

The logic goes like this:
tstr = header value
 - try to add it to current line, if fits; continue to start of loop
 - try to add it to next line, if fits; continue to start of loop
 - split tstr; continue to start of loop

So as you can see from test case, if split happened before step 2, the name 
would be split over 2 lines which is not ideal.

I tested splitting before step 2, which fixed this bug but failed 11 test 
cases, all of which deal with email address folding. (To and From headers).

So, is this actually an issue worth fixing?

If the answer is yes, one option would be to special case Subject header and 
split it before going to step 2.

IOW, the block that starts here: 
https://github.com/python/cpython/blob/4bcef2bb48b3fd82011a89c1c716421b789f1442/Lib/email/_header_value_parser.py#L2835

would need to be moved after the next block that starts 6 lines below.

--
nosy: +andrei.avk

___
Python tracker 

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



[issue11343] Make errors due to full parser stack identifiable

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:

The patch relates to the old parser. 

With the new parser the 100*(+100*) example works. If we go to 1000 instead of 
100 we get "SyntaxError: too many nested parentheses".

>From the discussion it seems that the idea of a new exception type for 
>implementation-limits vs "real" SyntaxErrors was rejected as not useful.

Is there anything left to do on this issue?

--
nosy: +iritkatriel

___
Python tracker 

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



[issue44552] incomplete documentation of __main__.py

2021-07-02 Thread Erik Carstensen


Erik Carstensen  added the comment:

thanks for the pointer and sorry for the noise! I'll review your text.

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

___
Python tracker 

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



[issue43908] array.array should remain immutable: add Py_TPFLAGS_IMMUTABLETYPE flag

2021-07-02 Thread Erlend E. Aasland


Change by Erlend E. Aasland :


--
pull_requests: +25562
pull_request: https://github.com/python/cpython/pull/27001

___
Python tracker 

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



[issue44555] Dictionary operations are LINEAR for any dictionary (for a particular code).

2021-07-02 Thread Daniel Fleischman


Daniel Fleischman  added the comment:

The linked list solution is not as easy to implement as I expected, because of 
insertions. :(

--

___
Python tracker 

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



[issue44555] Dictionary operations are LINEAR for any dictionary (for a particular code).

2021-07-02 Thread Daniel Fleischman


New submission from Daniel Fleischman :

The following code takes quadratic time on the size of the dictionary passed, 
regardless of the dictionary (explanation below):

```
def slow_dictionary(d):
while len(d) > 0:
# Remove first element
key = next(iter(d))
del d[key]
```

The problem is that when an element is deleted a NULL/NULL placeholder is set 
in its place 
(https://github.com/python/cpython/blob/818628c2da99ba0376313971816d472c65c9a9fc/Objects/dictobject.c#L1534)
 and when we try to find the first element with `next(iter(d))` the code needs 
to skip over all the NULL elements until it finds the first non-NULL element 
(https://github.com/python/cpython/blob/818628c2da99ba0376313971816d472c65c9a9fc/Objects/dictobject.c#L1713).

I'm not sure of what is the best way to fix it, but note that simply adding a 
field to the struct with the position of the first non-NULL element is not 
enough, since a code that always deletes the SECOND element of the dictionary 
would still have linear operations.

An easy (but memory-wasteful) fix would be to augment the struct PyDictKeyEntry 
with the indices of the next/previous non empty elements, and augment 
_dictkeysobject with the index of the first and last non empty elements (in 
other words, maintain an underlying linked list of the non empty entries). With 
this we can always iterate in O(1) per entry.

(I tested it only on version 3.9.2, but I would be surprised if it doesn't 
happen in other versions as well).

--
components: Interpreter Core
messages: 396880
nosy: danielfleischman
priority: normal
severity: normal
status: open
title: Dictionary operations are LINEAR for any dictionary (for a particular 
code).
type: performance
versions: Python 3.10, Python 3.11, 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



[issue39759] os.getenv documentation is misleading

2021-07-02 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It is not so uncommon to write:

foo_rate = float(os.getenv("FOO_RATE", default_foo_rate))

where default_foo_rate is float.

In any case the default value for the default parameter is not a string.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue44554] pdb.main is unnecessarily complicated

2021-07-02 Thread Jason R. Coombs


Change by Jason R. Coombs :


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

___
Python tracker 

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



[issue44388] venv API Docs for EnvBuilder.ensure_directories incorrectly describe behavior

2021-07-02 Thread miss-islington


miss-islington  added the comment:


New changeset 4bcef2bb48b3fd82011a89c1c716421b789f1442 by Matthew Clapp in 
branch 'main':
bpo-44388: Update venv EnvBuilder.ensure_directories() docs. (GH-26663)
https://github.com/python/cpython/commit/4bcef2bb48b3fd82011a89c1c716421b789f1442


--
nosy: +miss-islington

___
Python tracker 

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



[issue44554] pdb.main is unnecessarily complicated

2021-07-02 Thread Jason R. Coombs


New submission from Jason R. Coombs :

While investigating issue44461, I observed some complexities to the current 
pdb.main implementation, some of which likely contributed to the bug being 
present.

- variables are initialized to defaults 
(https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1677-L1678)
 and then mutated 
(https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1684-L1686)
 based on other variables.

- mainpyfile is conditionally mutated based on previous values of conditionally 
mutated variables 
(https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1696).

- There are three different blocks of code 
(https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1690-L1691,
 
https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1696-L1698,
 and 
https://github.com/python/cpython/blob/ec8759b060eff83ff466f42c5a96d83a685016ce/Lib/pdb.py#L1711)
 that are conditionally run based on run_as_module.

These factors mean that all of these lines of code are entangled in ways that 
are somewhat difficult to reason about. For example, it's unclear what states 
have been achieved by the time `pdb._run*` is constructed, or what exceptions 
may or may not be expected for these calls.

A functional or OO approach would limit the amount of mutation and entanglement 
(through encapsulation or scoping).

An OO approach would have a protocol or interface that captures the different 
behaviors required prior to and on invocation of `Pdb._run*`.

For example, the PDB "targets" (script or module) could be modeled as separate 
classes and provide symmetric interfaces with (possibly degenerate) equivalent 
operations for each use-case.

To be sure, the code that's present is adequate and in my opinion right on the 
border of benefiting from a more rigorous abstraction. The current imperative 
approach is fairly readable and mostly comprehensible. It's only because of the 
surprise behavior in the reported issue that I propose to step back and 
contemplate ways to alleviate the concerns above.

--
components: Library (Lib)
messages: 396877
nosy: iritkatriel, jaraco
priority: normal
severity: normal
status: open
title: pdb.main is unnecessarily complicated
versions: Python 3.11

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

In ideal world we would use __int__ for (1), and __trunc__ for (2). But for 
some historical reasons __index__ was introduced for (1) and __int__ is only 
used in the int constructor, although it falls back to __trunc__.

I am wondering whether one of __int__ or __trunc__ should be deprecated.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue44534] unittest.mock.Mock.unsafe doc is garbled

2021-07-02 Thread Jack DeVries


Change by Jack DeVries :


--
keywords: +patch
nosy: +jack__d
nosy_count: 2.0 -> 3.0
pull_requests: +25560
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27000

___
Python tracker 

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



[issue44552] incomplete documentation of __main__.py

2021-07-02 Thread Jack DeVries


Jack DeVries  added the comment:

This is documented in Doc/library/runpy.rst. Specifically, here:

> For a simple script, the specified code is simply executed in a fresh module 
> namespace. For a valid sys.path entry (typically a zipfile or directory), the 
> entry is first added to the beginning of sys.path. The function then looks 
> for and executes a __main__ module using the updated path. Note that there is 
> no special protection against invoking an existing __main__ entry located 
> elsewhere on sys.path if there is no such module at the specified location.

https://docs.python.org/3/library/runpy.html#runpy.run_path


However, I fully agree that Doc/library/__main__.rst is severely lacking; 
that's why I've rewritten it! Please consider providing your feedback on the 
open PR, and see bpo-39452

https://github.com/python/cpython/pull/26883



Note that the new docs in __main__.rst does explicitly reference runpy, so once 
merged, it'll guide people looking for this information in __main__.rst to the 
right place.

--
nosy: +jack__d

___
Python tracker 

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



[issue43950] Include column offsets for bytecode instructions

2021-07-02 Thread miss-islington


miss-islington  added the comment:


New changeset ec8759b060eff83ff466f42c5a96d83a685016ce by Batuhan Taskaya in 
branch 'main':
bpo-43950: optimize column table assembling with pre-sizing object (GH-26997)
https://github.com/python/cpython/commit/ec8759b060eff83ff466f42c5a96d83a685016ce


--
nosy: +miss-islington

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Guido van Rossum


Guido van Rossum  added the comment:

Oh no! Was there a test for this that I ignored? Thanks for cleaning up
after me.--
--Guido (mobile)

--

___
Python tracker 

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



[issue44544] Add full list of possible args to textwrap: wrap, fill, shorten

2021-07-02 Thread Jack DeVries


Change by Jack DeVries :


--
keywords: +patch
nosy: +jack__d
nosy_count: 2.0 -> 3.0
pull_requests: +25559
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26999

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:


New changeset 7a2d2ed1330e464ac186c09501ef51b8261f4292 by Irit Katriel in 
branch '3.10':
[3.10] bpo-30256: [doc] Fix formatting error in news (GH-26994) (GH-26998)
https://github.com/python/cpython/commit/7a2d2ed1330e464ac186c09501ef51b8261f4292


--

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:


New changeset 91db097358bcb00832e53d410035a8b7fcfdd9c3 by Miss Islington (bot) 
in branch '3.9':
bpo-30256: [doc] Fix formatting error in news (GH-26994) (GH-26996)
https://github.com/python/cpython/commit/91db097358bcb00832e53d410035a8b7fcfdd9c3


--

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


--
pull_requests: +25558
pull_request: https://github.com/python/cpython/pull/26998

___
Python tracker 

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



[issue43950] Include column offsets for bytecode instructions

2021-07-02 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
pull_requests: +25557
pull_request: https://github.com/python/cpython/pull/26997

___
Python tracker 

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



[issue41311] Add a function to get a random sample from an iterable (reservoir sampling)

2021-07-02 Thread Oscar Benjamin


Oscar Benjamin  added the comment:

I was contacted by someone interested in this so I've posted the last version 
above as a GitHub gist under the MIT license:
https://gist.github.com/oscarbenjamin/4c1b977181f34414a425f68589e895d1

--

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:


New changeset 2560c612c89ea2534b90a266aabf76dc74d93a12 by Ken Jin in branch 
'main':
bpo-30256: [doc] Fix formatting error in news (GH-26994)
https://github.com/python/cpython/commit/2560c612c89ea2534b90a266aabf76dc74d93a12


--
nosy: +iritkatriel

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread miss-islington


Change by miss-islington :


--
pull_requests: +25556
pull_request: https://github.com/python/cpython/pull/26996

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Mark Dickinson


Mark Dickinson  added the comment:

Thanks, that's helpful. I guess what you _really_ want there is a duck-typed 
"tell me whether this value is integral and if so give me the corresponding 
Python int", but that's not currently easily available, so I suppose x == 
int(x) is the next-best thing. Possibly the "right" way from the point of view 
of PEP 3141 is to be testing x == math.trunc(x) instead and asking for 
typing.SupportsTrunc, but it seems to me that __trunc__ never did really take 
off the way it was intended to.

tl;dr: I agree it would make sense to add __int__ to fractions.Fraction for 
3.11.

--

___
Python tracker 

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



[issue30256] Adding a SyncManager Queue proxy to a SyncManager dict or Namespace proxy raises an exception

2021-07-02 Thread Ken Jin


Change by Ken Jin :


--
nosy: +kj
nosy_count: 12.0 -> 13.0
pull_requests: +2
pull_request: https://github.com/python/cpython/pull/26994

___
Python tracker 

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



[issue44550] SPAM

2021-07-02 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
title: DIGITAL CLASSROOM -> SPAM

___
Python tracker 

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



[issue44550] SPAM

2021-07-02 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
Removed message: https://bugs.python.org/msg396854

___
Python tracker 

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



[issue44553] types.Union should support GC

2021-07-02 Thread Ken Jin


Change by Ken Jin :


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

___
Python tracker 

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



[issue44553] types.Union should support GC

2021-07-02 Thread Ken Jin


New submission from Ken Jin :

types.Union objects can contain reference cycles, therefore causing memory 
leaks.

E.g.::

```
import sys, gc
from typing import TypeVar

gc.collect()
for _ in range(10):
 sys.gettotalrefcount()
 T = TypeVar('T')
 U = int | list[T]
 T.blah = U
 del T
 del U
 gc.collect()
```
Result:
84470
0
84488
0
84504
0
84520
0
84536
0

I'm sending a small PR soon to implement GC methods to fix this.

--
messages: 396867
nosy: gvanrossum, kj
priority: normal
severity: normal
status: open
title: types.Union should support GC
versions: Python 3.10, Python 3.11

___
Python tracker 

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



[issue43950] Include column offsets for bytecode instructions

2021-07-02 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 98eee94421dcb42c15f2d7fc4cd21357722fbe2a by Pablo Galindo in 
branch 'main':
bpo-43950: Add code.co_positions (PEP 657) (GH-26955)
https://github.com/python/cpython/commit/98eee94421dcb42c15f2d7fc4cd21357722fbe2a


--

___
Python tracker 

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



[issue44552] incomplete documentation of __main__.py

2021-07-02 Thread Erik Carstensen


New submission from Erik Carstensen :

I can find partial information on how Python treats __main__.py here: 
https://docs.python.org/3/library/__main__.html

However, it is not documented how python handles __main__.py when passing the 
Python package to the interpreter without -m. If I have a program defined by 
/tmp/foo/bar.py and a file /tmp/foo/__main__.py, and I run

python /tmp/foo

... then Python will run __main__.py, with /tmp/foo prepended to sys.path.

I find this behaviour unfortunate; to me it would make more sense to prepend 
/tmp to sys.path, because then "python /tmp/foo" would be equivalent to 
"PYTHONPATH=/tmp python -m foo". With the current behaviour, if __main__.py 
wants to import bar.py, then it must write 'import bar' or 'import foo.bar' 
depending on whether the interpreter was invoked with -m.

Unfortunately, by Hyrum's Law, you can find people describing and encouraging 
reliance upon the current undocumented behaviour, e.g.:
https://www.geeksforgeeks.org/usage-of-__main__-py-in-python/
so perhaps the behaviour can't be changed that easily. Therefore, my request is 
to document how it works.

--
assignee: docs@python
components: Documentation
messages: 396865
nosy: docs@python, mandolaerik
priority: normal
severity: normal
status: open
title: incomplete documentation of __main__.py
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Michael Amrhein


Michael Amrhein  added the comment:

The background is an implementation of __pow__ for a fixed-point decimal number:

SupportsIntOrFloat = Union[SupportsInt, SupportsFloat]

def __pow__(self, other: SupportsIntOrFloat, mod: Any = None) -> Complex:
if isinstance(other, SupportsInt):
exp = int(other)
if exp == other:
... handle integer exponent
if isinstance(other, SupportsFloat):
# fractional exponent => fallback to float
return float(self) ** float(other)
return NotImplemented

I came across SupportsInt and SupportsFloat, because they are used in typeshed 
as param types for int and float.

--

___
Python tracker 

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



[issue44461] 'Pdb' object has no attribute 'botframe'

2021-07-02 Thread Jason R. Coombs


Change by Jason R. Coombs :


--
pull_requests: +25553
pull_request: https://github.com/python/cpython/pull/26992

___
Python tracker 

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



[issue39759] os.getenv documentation is misleading

2021-07-02 Thread Sergey Fedoseev


Change by Sergey Fedoseev :


--
nosy: +sir-sigurd

___
Python tracker 

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



[issue44551] Substraction: unprecise result

2021-07-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

This is not a bug, but expected floating point behavior. See 
https://docs.python.org/3/tutorial/floatingpoint.html

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

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



[issue44551] Substraction: unprecise result

2021-07-02 Thread user_0101


New submission from user_0101 :

```
>>> 2.11-1.56
0.5498
```

--
messages: 396862
nosy: user_0101
priority: normal
severity: normal
status: open
title: Substraction: unprecise result
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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree this should be closed (and I'm closing it). I don't see any reason why 
this function should do something other than raise TypeError if given bs=None. 
If you want that behavior, write a small wrapper function.

The "if not bs" check appears to be an optimization for the case of zero-length 
input. Hopefully the code would continue to work without that test (or instead 
testing for len(bs)==0), but in my opinion it's not worth the risk of removing 
or changing it.

--
stage:  -> resolved
status: pending -> closed

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Mark Dickinson


Mark Dickinson  added the comment:

> As another data point, complex supporting __int__ is a little bit of an 
> oddity, since all that __int__ method does is raise a TypeError.

This was fixed in 3.10: #41974

--

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:

I meant:

... it will be true for bs which is an empty bytes().


You are thinking of b'' and None as if they are the same thing. They are not.  
If this was a check for None it would be "if bs is None" and not "if not bs".

--
status: pending -> open

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


--
status: open -> pending

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Mark Dickinson


Mark Dickinson  added the comment:

> Maybe typing.SupportsIndex

Apologies: that already exists, of course. It was introduced in #36972.

--

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


--
status: open -> pending

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:

There is still a point in the "if not bs:" check, it will be true for bs which 
is an empty string.

--

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Mark Dickinson


Mark Dickinson  added the comment:

I'm actually struggling to think of situations where typing.SupportsInt would 
be useful in its current form: if I'm writing a function that wants to do a 
duck-typed acceptance of integer-like things (for example because I want my 
function to work with NumPy integers as well as plain old Python ints) then I 
want an __index__ check rather than an __int__ check. If I'm writing a function 
that allows general numeric inputs, then I'm not sure why I'd be calling 'int' 
on those inputs.

As another data point, complex supporting __int__ is a little bit of an oddity, 
since all that __int__ method does is raise a TypeError.

@Michael: are you in a position to share the use-case that motivated opening 
the issue? I'd be interested to see any concrete uses of typing.SupportsInt.

Maybe typing.SupportsIndex (or typing.UsableAsInt, or ... --- naming things is 
hard) is what we actually need?

On this particular issue: I'm not opposed to adding __int__ to 
fractions.Fraction purely for the sake of consistency, but it's not yet clear 
to me that it solves any real issue.

--

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Олег Масло

Олег Масло  added the comment:

If you pass None to the quote_from_bytes function, then there is no point in 
the "if not bs" check, because it won't even reach it. 

This function is not with dynamic behavior, which violates python concepts. If 
you pass a string instead of bytes, it will throw a TypeError exception, it's 
ok. But if for some reason you need to pass None, and this happens, then the 
function does not behave as expected.

Why even check that bs is not None, if this can never be? And if it does, there 
will always be a TypeError exception.

--
status: pending -> open

___
Python tracker 

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



[issue44550] DIGITAL CLASSROOM

2021-07-02 Thread skoolbeep


New submission from skoolbeep :

A digital classroom setup can be defined as a learning environment created with 
the help of electronic devices that run on software programmes. 
https://www.skoolbeep.com/blog/what-makes-up-a-good-digital-classroom/

--
messages: 396854
nosy: skoolbeep
priority: normal
severity: normal
status: open
title: DIGITAL CLASSROOM

___
Python tracker 

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



[issue44549] BZip 1.0.6 Critical Vulnerability

2021-07-02 Thread siddhartha shankar mahato


New submission from siddhartha shankar mahato :

Python (3.9.5 and 3.9.6 are using Bzip2 1.0.6 which has a known critical 
vulnerability. 
CVE-2019-12900 (BDSA-2019-1844)
9.8 Critical NVD CVE-2016-3189 (BDSA-2019-2036).

Please upgrade the same to a stable version.

--
components: Windows
messages: 396853
nosy: paul.moore, s.s.mahato, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: BZip 1.0.6 Critical Vulnerability
type: crash
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



[issue34798] pprint ignores the compact parameter for dicts

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


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



[issue34798] pprint ignores the compact parameter for dicts

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


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



[issue34798] pprint ignores the compact parameter for dicts

2021-07-02 Thread Irit Katriel

Irit Katriel  added the comment:


New changeset 42c26282a123d14591e1aa31107e566b302a19ac by Miss Islington (bot) 
in branch '3.10':
bpo-34798: [doc] clearer presentation of pprint.PrettyPrinter constru… 
(GH-26967) (GH-26990)
https://github.com/python/cpython/commit/42c26282a123d14591e1aa31107e566b302a19ac


--

___
Python tracker 

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



[issue43832] asyncio + multiprocessing = core dump in sem_trywait

2021-07-02 Thread Andrew Svetlov


Change by Andrew Svetlov :


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

___
Python tracker 

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



[issue34798] pprint ignores the compact parameter for dicts

2021-07-02 Thread Irit Katriel

Irit Katriel  added the comment:


New changeset 943e77d42d3f84b581f32c05f1fc8c05366b8ed3 by Irit Katriel in 
branch 'main':
bpo-34798: [doc] clearer presentation of pprint.PrettyPrinter constru… 
(GH-26967)
https://github.com/python/cpython/commit/943e77d42d3f84b581f32c05f1fc8c05366b8ed3


--

___
Python tracker 

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



[issue34798] pprint ignores the compact parameter for dicts

2021-07-02 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 5.0 -> 6.0
pull_requests: +25552
pull_request: https://github.com/python/cpython/pull/26990

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:

The documentation states that this function accepts bytes:

https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_from_bytes

None is not of type bytes, so raising a TypeError is not unreasonable. It would 
certainly be wrong to return any string. It could have returned None but that 
doesn't make a massive usability difference and it's not worth changing now.

I propose to close this as 'not a bug'.

--
resolution:  -> not a bug
status: open -> pending

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Irit Katriel


Irit Katriel  added the comment:

As I wrote on the PR, and again on this issue, a PR that makes a behavior 
change (like this one) is not complete without a unit test (which fails before 
the change and passes after the change, and can show what the bug being fixed 
is).  You could add such a test.

In this case, it is also not clear that the current behavior is a bug at all, 
and if it is then what the fix should be (you propose to map None to ''. But 
why not 'None'? Why not 'Mary had a little lamb'?  I suggested to return None 
rather than some arbitrary string). You could explain why you think it's a bug 
and why you think '' is the correct return value.

Once you do write the test and there is consensus that it is a bug and we agree 
what the fix should be, it should be some core dev's top priority to review and 
merge the PR (as opposed to reviewing and merging another PR). So you could 
push it forward by explaining why this bug is important.

--

___
Python tracker 

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



[issue43518] textwrap.shorten does not always respect word boundaries

2021-07-02 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
versions: +Python 3.11 -Python 3.8

___
Python tracker 

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



[issue44520] In Lib/urllib/parse.py quote_from_bytes, exception is thrown if bs = None

2021-07-02 Thread Олег Масло

Олег Масло  added the comment:

What are the next actions? Do I need to do something or are we waiting for 
something?

--

___
Python tracker 

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



[issue44547] fraction.Fraction does not implement __int__.

2021-07-02 Thread Mark Dickinson


Mark Dickinson  added the comment:

FWIW, there's some history here: there's a good reason that fractions.Fraction 
didn't originally implement __int__.

Back in the Bad Old Days, many Python functions that expected an integer would 
accept anything whose type implemented __int__ instead, and call __int__ to get 
the required integer. For example:

Python 3.7.10 (default, Jun  1 2021, 23:43:35) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> chr(Decimal("45.67"))
'-'

Effectively, __int__ was being used to mean two different things: (1) this 
value can be used as an integer, and (2) this value can be truncated to an 
integer. The solution was to introduce two new dedicated magic methods 
__index__ and __trunc__ for these two different meanings. See PEP 357 and PEP 
3141 for some of the details. So adding __int__ to fractions.Fraction would 
have made things like `chr(Fraction("5/2"))` possible, too.

The behaviour above is still present (with a deprecation warning) in Python 
3.9, and `chr(Decimal("45.67"))` has only finally been made a TypeError in 
Python 3.10.

We may now finally be in a state where ill-advised uses of __int__ in internal 
functions have all been deprecated and removed, so that it's safe to re-add 
__int__ methods.

But still, this seems mostly like an issue with the typing library. What is 
typing.SupportsInt intended to indicate? That an object can be used _as_ an 
integer, or that an object can be _truncated_ to an integer?

--
nosy: +mark.dickinson
type: behavior -> enhancement
versions:  -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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