[issue41229] Asynchronous generator memory leak

2020-11-09 Thread Joongi Kim


Change by Joongi Kim :


--
pull_requests: +22115
pull_request: https://github.com/python/cpython/pull/23217

___
Python tracker 

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



[issue42305] Added Auto_Complete DropBox Suggestion For Tkinter

2020-11-09 Thread Mechtron 750


New submission from Mechtron 750 :

# This is auto complete drop box suggestion wiget for tkinter
# Tkinter Autocomplete

Text autocompletion provides relevant real-time results to users. Because 
tkinter does not provide a widget for adding autocompletion to GUIs out of the 
box, I decided to make one myself. This utility is compatible with and has been 
tested on Python 2.7.1 and Python 3.6.0.

### Structure

## NOTE: The `Tkinter` library for Python 2 and `tkinter` library for 
Python 3 will from now on be referred to as `tk`.

The `AutocompleteEntry` class (which can be found 
[here](https://github.com/RajvirSingh1313/Tkinter_Autocomplete_DropBox/blob/master/main.py))
derives from `tk.Frame` and is a container used to group a `tk.Entry` and 
`tk.Listbox` widget. Should you need to modify the widgets,
they can be accessed as (respectively) `AutocompleteEntry` s `entry` and 
`listbox` attributes.

The entry widget acts like a normal textbox. When activated, it binds 
`` to a private method which will update
the list of suggestions. The listbox widget contains the suggestions 
themselves. When activated, it binds `<>` to a
private method which sets the entry widget to whatever value was selected.

Since an instance of `AutocompleteEntry` is a `tk.Frame` instance too, you can 
place it by calling its `pack` or `grid` methods with
their respective arguments.

### Quickstart

## NOTE: These examples will only run under Python 3. To make them Python 
2-compatible, replace `tkinter` with `Tkinter`.

To add a new autocompletion frame to our interface, first initialize one:

```python
import tkinter as tk

from tkinter import auto_complete

root = tk.Tk()

frame = tk.Frame(root)
frame.pack()

entry = auto_complete.AutocompleteEntry(frame)
# You can pass additional parameters to further customize the window;
# all parameters that you can pass to tk.Frame, are valid here too.
```

Now you need to configure the instance by passing it an iterable containing all 
autocompletion entries.
Do this by calling its `build` method:

```python
ENTRIES = (
"Foo",
"Bar"
)

entry.build(ENTRIES)
```

You can pass additional arguments to `build`:

* `max_entries` (integer):
  The maximum number of entries to display at once. This value directly 
corresponds to the listbox widget's `height` attribute. Defaults to `5`.

* `case_sensitive` (boolean):
  If `True`, only autocomplete entries that enforce the same capitalization as 
the current entry will be displayed.
  If `False`, all autocomplete entries that match with the current entry will 
be displayed.
  Defaults to `False`.

* `no_results_message` (string or `None`):
  The message to display if no suggestions could be found for the current 
entry.
  This argument may include a formatting identifier (`{}`) which, at runtime, 
gets formatted as the current entry. If `None` is specified, the listbox will 
instead be hidden until the next `` event.

Let's play around with these arguments:

```python
entry.build(
entries=ENTRIES,
no_results_message="< No results found for '{}' >"
# Note that this is formatted at runtime
)
```

## NOTE: You may call the `build` method multiple times on an instance of 
`AutocompleteEntry`, to dynamically change the available suggestions.

With that out of the way, you can display `entry`:

```python
entry.pack()
```

Now, each time a user presses a key while the entry widget has focus, a list of 
suggestions will display below it.

---

### Additional options

By default, the `tk.Listbox` widget has a width of `25` pixels and a height of 
`5` (items). The `tk.Entry` widget also has a default width of `25` pixels. 
These settings can be modified through the following class attributes:

* `auto_complete.AutocompleteEntry.LISTBOX_HEIGHT`: The height to specify when 
creating the `tk.Listbox` widget. There's no need to modify this, since the 
maximum number of entries to be displayed can be passed as an argument to 
`build`.

* `auto_complete.AutocompleteEntry.LISTBOX_WIDTH`: The width to specify when 
creating the `tk.Listbox` widget. Any positive integer is valid.

* `auto_complete.AutocompleteEntry.ENTRY_WIDTH`: The width to specify when 
creating the `tk.Entry` widget. Any positive integer is valid.

## NOTE: You almost always want to keep the 1:1 
`LISTBOX_WIDTH`:`ENTRY_WIDTH` ratio.

You can retrieve the current entry by accessing the instance's `text` attribute 
(which is a `tk.StringVar` instance):

```python
text = entry.text.get()
```

To further customize the entry widget, you may set its font options, for 
example:

```python
entry.entry["font"] = (, , )
```

Or to change the background color for the listbox widget:

```python
entry.listbox["background"] = "#cfeff9"
# Light blue
```


## This the demo

```python
try:
import tkinter as tk
from tkinter import ttk
from tkinter import auto_complete
except ImportError:
# Python 2
import Tkinter as tk

Re: Changing strings in files

2020-11-09 Thread Cameron Simpson
On 10Nov2020 07:24, Manfred Lotz  wrote:
>I have a situation where in a directory tree I want to change a certain
>string in all files where that string occurs.
>
>My idea was to do
>
>- os.scandir and for each file

Use os.walk for trees. scandir does a single directory.

>   - check if a file is a text file

This requires reading the entire file. You want to check that it 
consists entirely of lines of text. In your expected text encoding - 
these days UTF-8 is the common default, but getting this correct is 
essential if you want to recognise text. So as a first cut, totally 
untested:

for dirpath, filenames, dirnames in os.walk(top_dirpath):
is_text = False
try:
# expect utf-8, fail if non-utf-8 bytes encountered
with open(filename, encoding='utf-8', errors='strict') as f:
for lineno, line in enumerate(f, 1):
... other checks on each line of the file ...
if not line.endswith('\n'):
raise ValueError("line %d: no trailing newline" lineno)
if str.isprintable(line[:-1]):
raise ValueError("line %d: not all printable" % lineno)
# if we get here all checks passed, consider the file to 
# be text
is_text = True
except Exception as e:
print(filename, "not text", e)
if not is_text:
print("skip", filename)
continue

You could add all sorts of other checks. "text" is a loosely defined 
idea. But you could assert: all these lines decoded cleanly, so I can't 
do much damage rewriting them.

>   - if it is not a text file skip that file
>   - change the string as often as it occurs in that file

You could, above, gather up all the lines in the file in a list. If you 
get through, replace your string in the list and if anything was 
changed, rewrite the file from the list of lines.

>What is the best way to check if a file is a text file? In a script I
>could use the `file` command which is not ideal as I have to grep the
>result.

Not to mention relying on file, which (a) has a simple idea of text and 
(b) only looks at the start of each file, not the whole content. Very 
dodgy.

If you're really batch editing files, you could (a) put everything into 
a VCS (eg hg or git) so you can roll back changes or (b) work on a copy 
of your directory tree or (c) just print the "text" filenames to stdout 
and pipe that into GNU parallel, invoking "sed -i.bak s/this/that/g" to 
batch edit the checked files, keeping a backup.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue42304] [easy C] long type performance waste in 64-bit Windows build

2020-11-09 Thread Ma Lin


New submission from Ma Lin :

C type `long` is 4-byte integer in 64-bit Windows build (MSVC behavior). [1]
In other compilers, `long` is 8-byte integer in 64-bit build.

This leads to a bit unnecessary performance waste, issue38252 fixed this 
problem in a situation.

Search `SIZEOF_LONG` in CPython code, there's still a few long type waste.

Novices are welcome to try contribution.

[1] https://stackoverflow.com/questions/384502

--
components: Windows
messages: 380638
nosy: malin, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: [easy C] long type performance waste in 64-bit Windows build
type: performance
versions: Python 3.10

___
Python tracker 

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



Re: Changing strings in files

2020-11-09 Thread Loris Bennett
Manfred Lotz  writes:

> I have a situation where in a directory tree I want to change a certain
> string in all files where that string occurs.
>
> My idea was to do
>
> - os.scandir and for each file
>- check if a file is a text file
>- if it is not a text file skip that file
>- change the string as often as it occurs in that file
>
>
> What is the best way to check if a file is a text file? In a script I
> could use the `file` command which is not ideal as I have to grep the
> result. In Perl I could do  -T file.
>
> How to do best in Python?

If you are on Linux and more interested in the result than the
programming exercise, I would suggest the following non-Python solution:

   find . -type -f -exec sed -i 's/foo/bar/g' {} \;

Having said that, I would be interested to know what the most compact
way of doing the same thing in Python might be.

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue42303] I found a bug while checking string with find()

2020-11-09 Thread DongwonTTuna

DongwonTTuna  added the comment:

That was a mistake.

upload another picture file.

--
resolution:  -> wont fix
Added file: https://bugs.python.org/file49586/스크린샷 2020-11-10 16.14.28.png

___
Python tracker 

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



[issue42303] I found a bug while checking string with find()

2020-11-09 Thread DongwonTTuna

New submission from DongwonTTuna :

USED THE PYTHON-BINANCE MODULE FOR THIS

from binance.client import Client
from binance.exceptions import *

client = Client(api_key='Your_Public_Apikey',
api_secret='Your_Secret_Apikey')

def buy_limit_test(coin, amount):
client.create_test_order(
symbol=coin + 'USDT',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=amount)

try:
buy_limit_test(coin='HOT', amount=-19298.0)
except BinanceAPIException as E:
print(E.message.find("'quaaantity'; legal range is"))
if E.message.find("'quantity'; legal range is"):
print(E.message)
else:
print("yes")





And the parameters.



E.message.find("'quantity'; legal range is") = 38

E.message = "Illegal characters found in parameter 'quantity'; legal range is 
'^([0-9]{1,20})(\.[0-9]{1,20})?$'."



If I run with this

if E.message.find("'quanatity'; legal range is"):

It should be run with print("yes"), but It shows print(E.message).

But If I run with
if E.message.find("'quanatity'; legal range is") == 
True:

It's now run with print("yes") not the print(E.message).

I think it's a bug

--
files: 스크린샷 2020-11-10 16.02.46.png
messages: 380636
nosy: DongwonTTuna
priority: normal
severity: normal
status: open
title: I found a bug while checking string with find()
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file49585/스크린샷 2020-11-10 16.02.46.png

___
Python tracker 

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



[issue42302] [Turtle] Add clockwise and anticlockwise method as alias to right and left

2020-11-09 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

As a new feature, it can only go into 3.10. All other versions have reached 
feature-freeze and can accept no new features.

We might argue that rotations should have always been written as 
"anticlockwise" and "clockwise", but they are long and verbose, and in English 
"left" and "right" are more common. I doubt many people will prefer 
"anticlockwise" over "left".

--
nosy: +steven.daprano
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



Changing strings in files

2020-11-09 Thread Manfred Lotz
I have a situation where in a directory tree I want to change a certain
string in all files where that string occurs.

My idea was to do

- os.scandir and for each file
   - check if a file is a text file
   - if it is not a text file skip that file
   - change the string as often as it occurs in that file


What is the best way to check if a file is a text file? In a script I
could use the `file` command which is not ideal as I have to grep the
result. In Perl I could do  -T file.

How to do best in Python?

-- 
Thanks,
Manfred

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


[issue42302] [Turtle] Add clockwise and anticlockwise method as alias to right and left

2020-11-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

What other Turtle graphics implementations use commands clockwise and 
anticlockwise? Is it popular enough?

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue39679] functools: singledispatchmethod doesn't work with classmethod

2020-11-09 Thread mental


Change by mental :


--
nosy: +mental

___
Python tracker 

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



[issue41987] singledispatchmethod raises an error when relying on a forward declaration

2020-11-09 Thread mental


Change by mental :


--
keywords: +patch
nosy: +mental
nosy_count: 5.0 -> 6.0
pull_requests: +22113
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/23216

___
Python tracker 

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



[issue21664] multiprocessing leaks temporary directories pymp-xxx

2020-11-09 Thread Zackery Spytz


Zackery Spytz  added the comment:

Python 2.7 is no longer supported, so I think this issue should be closed.

--
nosy: +ZackerySpytz

___
Python tracker 

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



[issue42302] [Turtle] Add clockwise and anticlockwise method as alias to right and left

2020-11-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

This doesn't seem useful to me.

--
nosy: +rhettinger

___
Python tracker 

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



[issue42302] [Turtle] Add clockwise and anticlockwise method as alias to right and left

2020-11-09 Thread Ravi Chityala


New submission from Ravi Chityala :

The current implementation of turtle.py has right and left method for rotation. 
 Another approach to view rotation is either clockwise or anticlockwise. These 
two methods can be an alias to right and left respectively.

--
components: Library (Lib)
messages: 380631
nosy: zenr
priority: normal
severity: normal
status: open
title: [Turtle] Add clockwise and anticlockwise method as alias to right and 
left
type: 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



[issue40988] singledispatchmethod significantly slower than singledispatch

2020-11-09 Thread mental


Change by mental :


--
keywords: +patch
nosy: +mental
nosy_count: 1.0 -> 2.0
pull_requests: +22112
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23213

___
Python tracker 

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



[issue42301] Add function to exploit heapq structure to locate an index of element

2020-11-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

See: https://stackoverflow.com/questions/2372994/search-an-element-in-a-heap

--

___
Python tracker 

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



[issue42301] Add function to exploit heapq structure to locate an index of element

2020-11-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

What is the use case for this?

This doesn't seem to be a typical heap operation.  
https://en.wikipedia.org/wiki/Heap_(data_structure)#Operations

Have you seen the in other heap APIs?

--
components: +Library (Lib) -Extension Modules
title: Lack function to track index of an element in heapq -> Add function to 
exploit heapq structure to locate an index of element
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



[issue41122] functools.singledispatchfunction has confusing error message if no positional arguments are passed in

2020-11-09 Thread mental


Change by mental :


--
nosy: +mental
nosy_count: 2.0 -> 3.0
pull_requests: +22111
pull_request: https://github.com/python/cpython/pull/23212

___
Python tracker 

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



[issue42301] Lack function to track index of an element in heapq

2020-11-09 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +rhettinger, stutzbach

___
Python tracker 

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



[issue42301] Lack function to track index of an element in heapq

2020-11-09 Thread Sam Yan


New submission from Sam Yan :

Github PR #23204:
For a given element in a heap, we can leverage the fact that we can
search this element quicker thinking of the property of a heap. Therefore
out of h.index(x) that a list linear search uses, I propose to use a special 
written index method to look for an index of a heap element.This issue has been 
proposed on Github (with my changes to heapq also put there). Open a discussion 
under suggestion of Karthikeyan Singaravelan (tirkarthi).

--
components: Extension Modules
hgrepos: 393
messages: 380628
nosy: SamUnimelb
priority: normal
pull_requests: 22110
severity: normal
status: open
title: Lack function to track index of an element in heapq
type: behavior
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



[issue42300] Typo in translation to portuguese

2020-11-09 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

The Portuguese translation is maintained in GitHub and uses GitHub issues. 
Please report issues at https://github.com/python/python-docs-pt-br

--
nosy: +xtreak

___
Python tracker 

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



Re: How can I make this more complex?

2020-11-09 Thread dn via Python-list

On 10/11/2020 10:04, Quentin Bock wrote:

grade = input("Enter your grade: ")
if grade >= 90:
 print("You got an A ")
if grade >= 80:
 print("You got a B ")
if grade >= 70:
 print("You got a C")
if grade >= 60:
 print("You got a D ")
if grade >= 50:
 print("You failed")



First: open a Python terminal (REPL) and try:

import this

(wrt the post's title, lines three and four apply. This output is known 
as "The Zen of Python"!)



Did you ever run the code? Hint: it won't work, and even when 'fixed' 
won't work the way you want, either. What if the grade is < 50?


If the grade is 55, which message(s) should be printed?
(compare: syntax errors, semantic errors, and errors in logic)


Others have mentioned elif. Why?
If the code looks like a "ladder" with criteria being applied to the 
same variable at every step, only one will be chosen with an elif 
structure, but >=1 choice will be made without (as above).



Complexity?
Sure, if that's what you want, we've got complexity, but it'll cost you...
(as I tell my trainees: "just because we can do it, does not make it a 
good idea!")


Build a dictionary of "buckets" - with the (lowest point) grade-steps as 
keys and the applicable messages as values (this will actually be easier 
to maintain than the 'ladder'!), eg


90:"You got an A "
80:"You got a B "
...
0:"You didn't say what should happen"

Take the grade, check, and properly prepare it(!)
(why "check"?)

Loop through the dictionary:
if the grade 'fits into' this bucket:
print the message
break# no point in continuing to loop
# otherwise continue looping


Not to be recommended
- but if you are a 'glutton for punishment', don't bother with the 
dictionary's 0/last entry. Instead use a for-else structure...
Such would be an excellent case-study illustration of why 'simple' beats 
'complex'!
(sorry for the sardonic humor, disregard the last paragraph - most 
professional coders (in fact, all that I know) eschew for-else, or-else!)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


[issue42300] Typo in translation to portuguese

2020-11-09 Thread Ronan Soares

New submission from Ronan Soares :

Change "múltiplo menos comum" to "menor múltiplo comum" in the portuguese 
section of the what changed in python 3.9

--
assignee: docs@python
components: Documentation
messages: 380626
nosy: docs@python, ronan.soares
priority: normal
severity: normal
status: open
title: Typo in translation to portuguese
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



[issue14019] Unify tests for str.format and string.Formatter

2020-11-09 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Victor: Irit is reviewing old issues to decide whether to close or not.  She 
has to touch it somehow to mark it as reviewed.

Irit: if you only change the version, others may think that you blindly updated 
the version.  Better to say something that moves the issue forward.  Also, only 
marking for the next version, now 3.10, would delay the possible future 
obsolescence of the version marking.  In any case, any coredev who merges would 
decide about backports.

This particular issue needs major surgery as it is two interleaved but 
unrelated discussions.  Francisco should have moved his unrelated patch to a 
new issue as Eric Smith asked.  I opened new issue 42299 and moved the revised 
patch there, with credit to Francisco and Ezio as reviewer.  I unlinked both 
from here.

To make the discussion of Nick's issue more readable, the unrelated messages 
about the unrelated patch should be unlinked.  I believe each message unlink 
would generate a separate email, as did the file unlinks.

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



[issue14019] Unify tests for str.format and string.Formatter

2020-11-09 Thread Terry J. Reedy


Change by Terry J. Reedy :


Removed file: https://bugs.python.org/file31453/mywork2.patch

___
Python tracker 

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



Re: How can I make this more complex?

2020-11-09 Thread MRAB

On 2020-11-09 21:04, Quentin Bock wrote:

grade = input("Enter your grade: ")
if grade >= 90:
 print("You got an A ")
if grade >= 80:
 print("You got a B ")
if grade >= 70:
 print("You got a C")
if grade >= 60:
 print("You got a D ")
if grade >= 50:
 print("You failed")




How can I make this to say if your grade is 90 or higher BUT less than 100
you got an A,

In addition to other the answers, you should note that the 'input' 
function returns a string, so you'll need to convert that string to a 
number, most probably by using 'int', and, ideally, print a helpful 
message if that raises ValueError because it's not a valid number.

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


[issue42260] [C API] Add PyInterpreterState_SetConfig(): reconfigure an interpreter

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +22109
pull_request: https://github.com/python/cpython/pull/23211

___
Python tracker 

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



[issue42299] Add test_formatter (or remove deprecated formatter module?)

2020-11-09 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

The patch is by Francisco Freire (francisco.freire) * (CLA signed).  There is 
apparently no way to directly move a patch from one issue to another, so I 
download and upload.

--
keywords: +patch
Added file: https://bugs.python.org/file49584/mywork2.patch

___
Python tracker 

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



[issue14019] Unify tests for str.format and string.Formatter

2020-11-09 Thread Terry J. Reedy


Change by Terry J. Reedy :


Removed file: https://bugs.python.org/file31202/mywork.patch

___
Python tracker 

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



[issue42299] Add test_formatter (or remove deprecated formatter module?)

2020-11-09 Thread Terry J. Reedy


New submission from Terry J. Reedy :

#14019 has a patch, unrelated to the issue, that adds test.test_formatter.  
There still is no such file, so I open this issue to move the patch here.  It 
is the second version, responding to review by Ezio Melotti.

But formatter has been deprecated since 3.4.  It was originally scheduled to be 
removed in 3.6, but we decided to delay such removals until after 2.7 EOL.  
That is now past.  Do we add tests for a deprecated module?  If so, the patch, 
aDo we still want to remove formatter?  If so, when?

--
messages: 380623
nosy: terry.reedy
priority: normal
severity: normal
stage: patch review
status: open
title: Add test_formatter (or remove deprecated formatter module?)
type: enhancement
versions: Python 3.10

___
Python tracker 

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



Re: How can I make this more complex?

2020-11-09 Thread Bob Gailer
On Nov 9, 2020 5:59 PM, "Quentin Bock"  wrote:
>
> grade = input("Enter your grade: ")
> if grade >= 90:
> print("You got an A ")
> if grade >= 80:
> print("You got a B ")
> if grade >= 70:
> print("You got a C")
> if grade >= 60:
> print("You got a D ")
> if grade >= 50:
> print("You failed")
>
>
>
>
> How can I make this to say if your grade is 90 or higher BUT less than 100
> you got an A

if 100 > grade <= 90:

Additional suggestions:

change all but the first if to elif
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I make this more complex?

2020-11-09 Thread inhahe
if 100 > grade >= 90:



On Mon, Nov 9, 2020 at 6:01 PM Quentin Bock  wrote:

> grade = input("Enter your grade: ")
> if grade >= 90:
> print("You got an A ")
> if grade >= 80:
> print("You got a B ")
> if grade >= 70:
> print("You got a C")
> if grade >= 60:
> print("You got a D ")
> if grade >= 50:
> print("You failed")
>
>
>
>
> How can I make this to say if your grade is 90 or higher BUT less than 100
> you got an A,
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I make this more complex?

2020-11-09 Thread Quentin Bock
grade = input("Enter your grade: ")
if grade >= 90:
print("You got an A ")
if grade >= 80:
print("You got a B ")
if grade >= 70:
print("You got a C")
if grade >= 60:
print("You got a D ")
if grade >= 50:
print("You failed")




How can I make this to say if your grade is 90 or higher BUT less than 100
you got an A,
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36310] pygettext3.7 Does Not Recognize gettext Calls Within fstrings

2020-11-09 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10 -Python 3.7

___
Python tracker 

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



[issue36310] pygettext3.7 Does Not Recognize gettext Calls Within fstrings

2020-11-09 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:


New changeset bfc6b63102d37ccb58a71711e2342143cd9f4d86 by jack1142 in branch 
'master':
bpo-36310: Allow pygettext.py to detect calls to gettext in f-strings. 
(GH-19875)
https://github.com/python/cpython/commit/bfc6b63102d37ccb58a71711e2342143cd9f4d86


--
nosy: +BTaskaya

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Guido van Rossum


Change by Guido van Rossum :


--
nosy:  -gvanrossum

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I concur with Mark.

If you want to work only with non-borrowed references, use PySequence_GetItem() 
and PySequence_SetItem(). It has a cost: it is slower and needs checking 
errors. If you need more performant solution and binary compatibility across 
versions, use PyTuple_GetItem() and PyTuple_SetItem() (borrowed references is 
the part of optimization). If you don't need binary compatibility, but need 
speed, use macros.

And no need to expand the C API. It is already large enough.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue26200] SETREF adds unnecessary work in some cases

2020-11-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Py_SETREF() is simple wrappers around Py_DECREF() and assignment. If there are 
macros in Rust it is better to implement Py_SETREF() as Rust macro.

Py_SETREF() was not added to the limited API for reason. If arguments against 
Py_SETREF() are still valid, the same arguments are applicable to Py_SetRef(). 
And even if Py_SETREF() will be added to the limited C API I do not think that 
there is a need of adding Py_SetRef(). It is more cumbersome (additional &), 
slower and affects the optimization of surrounded code (pointer cannot be in 
register), and does not have any advantage in addition to the macro.

This issue was closed 4 years ago. Please open a new issue for Py_SetRef().

--

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread Jake Hunsaker


Jake Hunsaker  added the comment:

Ok, yeah there seem to be several paths to avoid this behavior then. We should 
be fine exploring those options.


Thanks for the pointer!

--

___
Python tracker 

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-09 Thread Kevin Keating


Kevin Keating  added the comment:

My colleague just tested this on Mac and confirms that the bug also occurs 
there using Python 3.8.3.

--

___
Python tracker 

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-09 Thread Kevin Keating


Kevin Keating  added the comment:

An __init__.py shouldn't be necessary.  If I comment out the 'b = 
lazy_import("foo.b")' line in a.py (i.e. disable the lazy import), then the 
print statement works correctly as written without any other changes.

Also, I double checked with the colleague who originally ran into this issue, 
and it turns out he encountered the bug on Linux, not on Mac (still Python 
3.8.3).

--

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread paul j3


paul j3  added the comment:

It's the subparser that's producing this error, specifically its 'prog' 
attribute.

If I use a custom usage with a simple parser:

1129:~/mypy$ python3 issue42297.py --foo=on
usage: issue42297.py
one
two
three
issue42297.py: error: argument --foo: ignored explicit argument 
'on'

Notice that the error line includes the 'prog'.  

With subparsers, the main usage is included in the subcommand prog:

print(subcmd_parser.prog)

produces:

test usage string ending in newlines

foo  --bar
foo  --bar
foo  --bar foo

That's the usage plus the subcommand name, 'foo'.

Generating the explicit error in the subcommand:

1244:~/mypy$ python3 issue42297.py foo --bar=on
test usage string ending in newlines

foo  --bar
foo  --bar
foo  --bar foo: error: argument --bar: ignored explicit 
argument 'on'

'issue42297.py: ' has been replaced by the usage+'foo', and no newline.

We don't see this in the 'unrecognized' case because that error issued by the 
main parser.

issue42297.py: error: unrecognized arguments: on

If I explicitly set the prog of the subcommand:

subcmd_parser = subparser.add_parser('foo', prog='myscript foo')

The error becomes:

1256:~/mypy$ python3 issue42297.py foo --bar=on
usage: myscript foo [-h] [--bar]
myscript foo: error: argument --bar: ignored explicit argument 'on'

I can also add 'usage=usage_string' to the add_parser.  For the most part 
add_parser takes the same parameters as ArgumentParser.

Alternatively we can specify prog in 

subparser = parser.add_subparsers(dest='subcmd', metavar='subcmd', 
prog='myscript')

resulting in:

myscript foo: error: argument --bar: ignored explicit argument 'on'

I recently explored how 'prog' is set with subparsers in

https://bugs.python.org/issue41980

I don't think anything needs to be corrected in argparse.  There are enough 
options for setting prog and usage in subcommands to get around this issue.  

In the worse case, you might want to create an alternative 

_SubParsersAction

Action subclass that defines the prog/usage differently.

--

___
Python tracker 

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



[issue42133] Update the stdlib to fall back to __spec__.loader if __loader__ isn't defined

2020-11-09 Thread Brett Cannon


Change by Brett Cannon :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
title: Update the stdlib to fall back to __spec__.parent if __loader__ isn't 
defined -> Update the stdlib to fall back to __spec__.loader if __loader__ 
isn't defined

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread Jake Hunsaker


Jake Hunsaker  added the comment:

Ah, ok - so I neglected to mention we're using subparsers which appears to be 
relevant here. My apologies.

Here's a minimal reproducer that shows the behavior when using './arg_test.py 
foo --bar=on'

```
#! /bin/python3

import argparse

usage_string = 'test usage string ending in newlines\n\n'
sub_cmd_usage = ''

for i in range(0, 3):
sub_cmd_usage += '\tfoo  --bar\n'

usage_string += sub_cmd_usage

parser = argparse.ArgumentParser(usage=usage_string)
subparser = parser.add_subparsers(dest='subcmd', metavar='subcmd')
subcmd_parser = subparser.add_parser('foo')
subcmd_parser.add_argument('--bar', action="store_true", default=False)

if __name__ == '__main__':
args = parser.parse_args()

```

--

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I am sad that such code (as well as my former code in total_ordering) no longer 
works, but this is just a clever trick, and the code can be written in less 
clever but more explicit way.

On other hand, the warning helps to catch common mistakes like

   not self.__lt__(other)
   self.__lt__(other) or self.__eq__(other)
   super().__eq__(other) and self.x == other.x

Even non-beginners often make such kind of mistakes, and it is hard to catch 
them if you have not trained yourself specially. I suggest you to include 
lessons about writing complex comparison methods in your course for advanced 
users.

--

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> I assume you've been recommending this?

Not really, but it does come up and I've seen it in customer code more than 
once.

I do show people this:

>>> data = [10.5, 3.27, float('Nan'), 56.1]
>>> list(filter(isfinite, data))
[10.5, 3.27, 56.1]
>>> list(filterfalse(isnan, data))
[10.5, 3.27, 56.1]

The question does arise about how to do this for None using functional 
programming.  The answer is a bit awkward:

>>> from operator import is_not
>>> from functools import partial
>>> data = [10.5, 3.27, None, 56.1]
>>> list(filter(partial(is_not, None), data))
[10.5, 3.27, 56.1]

>From a teaching point of view, the important part is to show that this code 
>does not do what people typically expect:

>>> data = [10.5, 0.0, float('NaN'), 3.27, None, 56.1]
>>> list(filter(None, data))
[10.5, nan, 3.27, 56.1]

FWIW, this issue isn't important to me.  Just wanted to note that one of the 
idioms no longer works.  There are of course other ways to do it.

--

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread Jake Hunsaker


Jake Hunsaker  added the comment:

I'll try and get a simple reproducer made shortly, however as a quick note I've 
found that using '--all-logs on' results in a properly formatted error message.

--

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread paul j3


paul j3  added the comment:

Provide a minimal reproducible example.  I can't reproduce that run on error 
message.

Also test with arguments like '--all-logs on', which issues an 'unrecognizeable 
argument' error (with a different error reporting path).

Stripping excess newlines is normal, both in the full help and error.  That's 
done at the end of help formatting.

--

___
Python tracker 

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



[issue41712] REDoS in purge

2020-11-09 Thread Steve Dower


Steve Dower  added the comment:

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Eryk Sun


Eryk Sun  added the comment:

Yes, if I force the return value of _Py_ThreadCanHandleSignals to 1, the loop 
is broken by a KeyboardInterrupt.

--

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

So you're saying this war broken by 
https://github.com/python/cpython/pull/19087 ?

--

___
Python tracker 

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



[issue42179] Clarify chaining exceptions in tutorial/errors.rst

2020-11-09 Thread Vladimir Ryabtsev


Vladimir Ryabtsev  added the comment:

All right, you won. I hope beginner users will be happy :)

I removed my proposal paragraph about __cause__ and __context__ and kept only 
changes about exception type (https://bugs.python.org/issue42179#msg380435).

--

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Eryk Sun


Eryk Sun  added the comment:

See bpo-40010. COMPUTE_EVAL_BREAKER() in Python/ceval.c -- or 
_Py_ThreadCanHandleSignals in Include/internal/pycore_pystate.h -- needs to 
take into account that SIGNAL_PENDING_SIGNALS() gets called on a completely new 
thread in Windows.

--

___
Python tracker 

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



Re: Is there a conflict of libraries here?

2020-11-09 Thread Ethan Furman

On 11/8/20 9:20 PM, Chris Angelico wrote:


Perhaps, but certainly the confusion is far less when the module is
always imported as itself, and then the class is "datetime.datetime"
which nicely parallels "datetime.date" and "datetime.time".


I find doubled names such as "datetime.datetime" both jarring and visual noise.

Thankfully, we can rename modules on import:

  import datetime as dt
  import time as t
  import PIL.Image as im

As for "from blablah import *" -- that should only be done with modules specifically designed for it; having said that, 
it looks like datetime.py was so designed.  So, if I had a module making extensive use of the datetime contents, and 
wasn't using the time module, I would have no problem with "from datetime import *".  On the other hand, if datetime was 
only a small portion of my module, I would "import datetime as dt".


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


[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Eryk Sun


Change by Eryk Sun :


--
nosy: +vstinner

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

That's off topic for this issue -- you can go to python-ideas to propose that.

--

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Vedran Čačić

Vedran Čačić  added the comment:

... as it probably should: look at https://bugs.python.org/msg349303

Yes, filtering comprehensions are a frequently used niche, and too long in the 
"official" parlance. I seem to recall that 

[x in mylist if x is not None]

(instead of triple-x version) was rejected because it was too hard to parse. 
Maybe now we can really implement it?

--

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

> list(filter(None.__ne__, L))

I assume you've been recommending this? To me it looks obfuscated. People 
should just use a comprehension, e.g.

[x for x in L if x is not None]

--

___
Python tracker 

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



[issue42298] Documented interaction of single-stage init and sub-interpreters inaccurate

2020-11-09 Thread pkerling

New submission from pkerling <9b6ab...@casix.org>:

The C API documentation says this about single-phase initialization and 
sub-interpreters:

"[T]he first time a particular extension is imported, it is initialized 
normally, and a (shallow) copy of its module’s dictionary is squirreled away. 
When the same extension is imported by another (sub-)interpreter, a new module 
is initialized and filled with the contents of this copy; the extension’s init 
function is not called."
- from https://docs.python.org/3.10/c-api/init.html#c.Py_NewInterpreter

I was investigating crashes relating to the _datetime module and 
sub-interpreters and from my observations, this does not seem to be true.
I have tracked this functionality down to the m_base.m_copy dictionary of the 
PyModuleDef of an extension and the functions _PyImport_FixupExtensionObject 
and _PyImport_FindExtensionObject in Python/import.c. However, modules are only 
ever added to the `extensions` global when imported in the main interpreter, 
see 
https://github.com/python/cpython/blob/1f73c320e2921605c4963e202f6bdac1ef18f2ce/Python/import.c#L480

Furthermore, even if they were added and m_base.m_copy was set, it would be 
cleared again on sub-interpreter shutdown here: 
https://github.com/python/cpython/blob/1f73c320e2921605c4963e202f6bdac1ef18f2ce/Python/pystate.c#L796
 - implying that the module will be loaded and initialized again next time due 
to this check: 
https://github.com/python/cpython/blob/1f73c320e2921605c4963e202f6bdac1ef18f2ce/Python/import.c#L556

These observations are supported by the fact that in my tests, if "import 
_datetime" is ran subsequently in two different sub-interpreters, 
PyInit__datetime is indeed called twice.

Test code - set a breakpoint on PyInit__datetime to observe the behavior:

#include 
#include 
int main()
{
Py_Initialize();
for (int i = 0; i < 100; ++i) {
PyThreadState* ts = Py_NewInterpreter();
assert(ts);
int result = PyRun_SimpleString("import _datetime");
assert(result == 0);
Py_EndInterpreter(ts);
}
return 0;
}

In summary, it seems to me that the documented behavior is not accurate (any 
more?) - so either the docs or the implementation should change.

--
assignee: docs@python
components: Documentation
messages: 380602
nosy: docs@python, pkerling
priority: normal
severity: normal
status: open
title: Documented interaction of single-stage init and sub-interpreters 
inaccurate
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



[issue41712] REDoS in purge

2020-11-09 Thread Steve Dower


Steve Dower  added the comment:


New changeset 1f73c320e2921605c4963e202f6bdac1ef18f2ce by Yash Shete in branch 
'master':
bpo-41712: Avoid runaway regex match in upload scripts (GH-23166)
https://github.com/python/cpython/commit/1f73c320e2921605c4963e202f6bdac1ef18f2ce


--

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Eryk Sun


Eryk Sun  added the comment:

It also cannot be interrupted in 3.9. But 3.8 and earlier work correctly.

--
nosy: +eryksun
type:  -> behavior
versions: +Python 3.9

___
Python tracker 

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



[issue41798] [C API] Revisit usage of the PyCapsule C API with multi-phase initialization API

2020-11-09 Thread pkerling


Change by pkerling <9b6ab...@casix.org>:


--
nosy: +pkerling

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

> PyTuple_SetItem() does clear the previous item, it uses Py_XSETREF. The macro 
> version (PyTuple_SET_ITEM) does not clear the previous item.

Oh sorry, I was thinking at PyTuple_SET_ITEM().

--

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +paul.j3, rhettinger

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Guido van Rossum


Change by Guido van Rossum :


--
priority: normal -> release blocker

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Guido van Rossum


Change by Guido van Rossum :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue42297] [argparse] Bad error message formatting when using custom usage text

2020-11-09 Thread Jake Hunsaker


New submission from Jake Hunsaker :

In the sos project, we build a custom `usage` string for our argparser parser, 
and have noticed that doing so causes error messages from argparse to be badly 
formatted.

For example if a bad option value is given, the error message is mangled into 
the last line of our usage string:

```
# python3 bin/sos report --all-logs=on
usage: sos report [options]
sos  [options]

[..snip...]
collect, collectorCollect an sos report from multiple nodes 
simultaneously report: error: argument --all-logs: ignored explicit argument 
'on'
```


This is especially strange since we build the usage string with a trailing 
newline character:

```
for com in self._components:
aliases = self._components[com][1]
aliases.insert(0, com)
_com = ', '.join(aliases)
desc = self._components[com][0].desc
_com_string += (
"\t{com:<30}{desc}\n".format(com=_com, desc=desc)
)
usage_string = ("%(prog)s  [options]\n\n"
"Available components:\n")
usage_string = usage_string + _com_string
epilog = ("See `sos  --help` for more information")
self.parser = ArgumentParser(usage=usage_string, epilog=epilog)
```


So it appears the trailing newlines are being stripped (in our case, 
unintentionally?). As expected, removing the trailing newline when passing 
`usage_string` to our parse does not change this behavior.

However, if we don't set the usage string at all when instantiating our parser, 
the error message is properly formatted beginning on a new line. Slightly 
interesting is that without the usage_string being passed, the error message is 
prefixed with "sos: report:" as expected for %(prog)s expansion, but when the 
error message is mangled `%(prog)s` is left out as well.

A little more context is available here: 
https://github.com/sosreport/sos/issues/2285

--
components: Library (Lib)
messages: 380598
nosy: TurboTurtle
priority: normal
severity: normal
status: open
title: [argparse] Bad error message formatting when using custom usage text
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Guido van Rossum


New submission from Guido van Rossum :

This code cannot be interrupted with ^C on Windows (e.g. in the REPL)

while True:
pass

This seems to be a regression, it works in earlier versions.

--
messages: 380597
nosy: Mark.Shannon, gvanrossum, steve.dower
priority: normal
severity: normal
status: open
title: Infinite loop uninterruptable on Windows in 3.10
versions: Python 3.10

___
Python tracker 

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



[issue42296] Infinite loop uninterruptable on Windows in 3.10

2020-11-09 Thread Guido van Rossum


Change by Guido van Rossum :


--
components: +Windows
nosy: +paul.moore, tim.golden, zach.ware

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread hai shi


Change by hai shi :


--
nosy: +shihai1991

___
Python tracker 

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

One of the idioms for removing None no longer works:

>>> L = [0, 23, 234, 89, None, 0, 35, 9]
>>> list(filter(None.__ne__, L))
Warning (from warnings module):
  File "", line 1
DeprecationWarning: NotImplemented should not be used in a boolean context
[0, 23, 234, 89, 0, 35, 9]

--
nosy: +rhettinger

___
Python tracker 

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



[issue39931] Global variables are not accessible from child processes (multiprocessing.Pool)

2020-11-09 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

Can this issue be closed?  Multiprocessing seems to work as designed. There is 
a behaviour change between 3.7 and 3.8, but that's documented in What's New.

--

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

PyTuple_SetItem() does clear the previous item, it uses Py_XSETREF. The macro 
version (PyTuple_SET_ITEM) does not clear the previous item.

--
nosy: +ronaldoussoren

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

Mark Shannon:
> The old functions aren't going away, so these additional functions provide no 
> real safety. You can't stop C programmers trading away correctness for some 
> perceived performance benefit :(

In my experience, newcomers tend to copy existing more. If slowly, the code 
base moves towards safer code less error-prone code like Py_NewRef() or 
Py_SETREF(), slowly, we will avoid a bunch of bugs.


> If we were designing the API from scratch, then this would be a better set of 
> functions. But because the old functions remain, it just means we are making 
> the API larger.

New API VS enhance the existing API. So far, no approach won. I wrote the PEP 
620 to enhance the C API and towards a more opaque API, and there is the HPy 
project which is a new API written correctly from the start. But HPy is not 
usable yet, and migrating C extensions to HPy will take years.

Also, enhancing the existing API and writing a new API are not exclusive option.

What is the issue of making the C API larger?


> Please don't add macros, use inline functions.

For Py_NewRef(), I used all at once :-) static inline function + function + 
macro :-)

It's exported as a regular function for the stable ABI, but overriden by a 
static inline function with a macro. The idea is to allow to use it for 
developers who cannot use static inline functions (ex: extension modules not 
written in C).

I chose to redefine functions as static inline functions in the limited C API. 
If it's an issue, we can consider to only do that in Include/cpython/object.h.


> There seems to be some confusion about borrowed references and stolen 
> references in 
> https://pythoncapi.readthedocs.io/bad_api.html#borrowed-references
"Stealing" a reference is perfectly safe. Returning a "borrowed" reference is 
not.
>
> So, don't bother with `PyTuple_SetItemRef()`, as `PyTupleSetItem()` is safe.

I'm really annoyed that almost all functions increase the refcount of their 
arugments, except a bunch of special cases. I would like to move towards a more 
regular API.

PyTuple_SetItem() is annoying because it steals a reference to the item. Also, 
it doesn't clear the reference of the previous item, which is also likely to 
introduce a reference leak.

--

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread Mark Shannon


Mark Shannon  added the comment:

I'm not convinced that this is worth the effort.

The old functions aren't going away, so these additional functions provide no 
real safety.
You can't stop C programmers trading away correctness for some perceived 
performance benefit :(

If we were designing the API from scratch, then this would be a better set of 
functions. But because the old functions remain, it just means we are making 
the API larger.


Please don't add macros, use inline functions.

There seems to be some confusion about borrowed references and stolen 
references in https://pythoncapi.readthedocs.io/bad_api.html#borrowed-references
"Stealing" a reference is perfectly safe. Returning a "borrowed" reference is 
not.

So, don't bother with `PyTuple_SetItemRef()`, as `PyTupleSetItem()` is safe.

--
nosy: +Mark.Shannon

___
Python tracker 

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



[issue42290] Unicode inconsistent display after concencated

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
nosy:  -vstinner

___
Python tracker 

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



[issue2931] optparse: various problems with unicode and gettext

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

This issue was reported in 2008 on Python 2.5. The latest comment is about 
Python 2.

The latest Python version is now Python 3.9 and uses Unicode by default.

I close the issue since there is no activity for 4 years. More tests are always 
welcomed, so someone can still add new tests. Note that the optparse module is 
deprecated since Python 3.2.

--
resolution:  -> out of date
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



[issue41972] bytes.find consistently hangs in a particular scenario

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
nosy:  -vstinner

___
Python tracker 

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



[issue14019] Unify tests for str.format and string.Formatter

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

@Irit Katriel: Please avoid changing the versions field of old inactive issues. 
It changes artificially the last activity date of an issue and it sends an 
email to all people in the nosy list. There is no need to update the Version 
field of the +7500 open bugs.

--

___
Python tracker 

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



[issue12625] sporadic test_unittest failure

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

> Is this test still failing? Or can this be closed?

The OpenIndiana buildbot is gone for many years. See also bpo-42173.

--
resolution:  -> out of date
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



[issue42291] Incorrect signature of CodeType.replace()

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

> Argument Clinic and the inspect module do not support this case.

That's why I used -1 and None.

> But -1 and None are incorrect values for many parameters, and even if they 
> would be correct, they are not default values. By default, if you do not 
> specify some argument, the value of the corresponding attribute would not be 
> changed.

If you consider that this issue matters, you may hack the code to accept None 
as if no parameter was passed (pass NULL).

--

___
Python tracker 

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



[issue25259] readline macros can segfault Python

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

No activity for 4 years, I close the issue.

--
resolution:  -> out of date
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



[issue42225] Tkinter hangs or crashes when displaying astral chars

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
nosy:  -vstinner

___
Python tracker 

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



[issue26200] SETREF adds unnecessary work in some cases

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:

I wrote PR 23209 to add Py_SetRef() and Py_XSetRef() functions to the limited C 
API and the stable ABI. Py_SETREF() and Py_XSETREF() macros are excluded from 
the limited C API and some extension modules cannot use them, like extension 
modules written in Rust.

--

___
Python tracker 

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



[issue26200] SETREF adds unnecessary work in some cases

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +22108
pull_request: https://github.com/python/cpython/pull/23209

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +22107
pull_request: https://github.com/python/cpython/pull/23209

___
Python tracker 

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



[issue19561] request to reopen Issue837046 - pyport.h redeclares gethostname() if SOLARIS is defined

2020-11-09 Thread Jakub Kulik


Change by Jakub Kulik :


--
pull_requests: +22106
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23208

___
Python tracker 

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



[issue19561] request to reopen Issue837046 - pyport.h redeclares gethostname() if SOLARIS is defined

2020-11-09 Thread Jakub Kulik


Jakub Kulik  added the comment:

And for the reference, Solaris distros are already removing this code:

https://github.com/oracle/solaris-userland/blob/master/components/python/python37/patches/15-gethostname.patch
https://github.com/OpenIndiana/oi-userland/blob/oi/hipster/components/python/python37/patches/15-gethostname.patch
https://github.com/omniosorg/omnios-build/blob/master/build/python37/patches/15-gethostname.patch

--

___
Python tracker 

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



[issue41543] contextlib.nullcontext doesn't work with async context managers

2020-11-09 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10

___
Python tracker 

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



[issue19561] request to reopen Issue837046 - pyport.h redeclares gethostname() if SOLARIS is defined

2020-11-09 Thread Jakub Kulik


Jakub Kulik  added the comment:

I think this code should be removed.

It was added in its current form more than 20 years ago with the intention to 
add function declarations missing from system include files:
https://github.com/python/cpython/commit/1e0c2f4bee43728930bd5f4dc77283f09c4ba004

Today, every Solaris system should have gethostname() available in unistd.h. I 
am not sure when exactly was it added, but it was available in the OpenSolaris 
since the first commit (year 2005):
https://github.com/illumos/illumos-gate/blame/master/usr/src/head/unistd.h#L344


Also, AFAIK, 'SOLARIS' macro is not predefined on Solaris systems in compiler 
preprocessors today *; hence, unless compiled with `-DSOLARIS`, this code has 
no effect.

*) I tested this with several GCC [7|9|10] and Solaris studio and neither of 
those defined it. It seems like it might have worked many years ago, but it 
certainly isn't a way to #ifdef Solaris today.

--
nosy: +kulikjak

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +22105
pull_request: https://github.com/python/cpython/pull/23207

___
Python tracker 

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



[issue40624] add support for != (not-equals) in ElementTree XPath

2020-11-09 Thread Antony Lee


Change by Antony Lee :


--
nosy:  -Antony.Lee

___
Python tracker 

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



[issue42295] Error should be flagged if Walrus operator is used for multiple assigment

2020-11-09 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 23c5f93b83f78f295313e137011edb18b24c37c2 by Victor Stinner in 
branch 'master':
bpo-42294: Add borrowed/strong reference to doc glossary (GH-23206)
https://github.com/python/cpython/commit/23c5f93b83f78f295313e137011edb18b24c37c2


--

___
Python tracker 

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



[issue41543] contextlib.nullcontext doesn't work with async context managers

2020-11-09 Thread Andrew Svetlov


Andrew Svetlov  added the comment:


New changeset a117167d8dc8fa673a4646f509551c7950f824e5 by Tom Gringauz in 
branch 'master':
bpo-41543: contextlib.nullcontext can fill in for an async context manager 
(GH-21870)
https://github.com/python/cpython/commit/a117167d8dc8fa673a4646f509551c7950f824e5


--

___
Python tracker 

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



[issue42294] [C API] Add new C functions with more regular reference counting like PyTuple_GetItemRef()

2020-11-09 Thread STINNER Victor


Change by STINNER Victor :


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

___
Python tracker 

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



[issue42295] Error should be flagged if Walrus operator is used for multiple assigment

2020-11-09 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

Due to the precedence of the walrus operator, it is not actually a multiple 
assignment but rather a tuple of 3 elements with one being the value of the 
assignment expression.

 $ python -m ast  
(a, b := 3, 4)
Module(
   body=[
  Expr(
 value=Tuple(
elts=[
   Name(id='a', ctx=Load()),
   NamedExpr(
  target=Name(id='b', ctx=Store()),
  value=Constant(value=3)),
   Constant(value=4)],
ctx=Load()))],
   type_ignores=[])

In this case, it creates a tuple with loading the name `a` from the current 
scope, using the value of the 3 and also assigning 3 to the b, and loading 
constant 4.

So basically (a, b := 3, 4) is actually (a, (b := 3), 4)

--
nosy: +BTaskaya

___
Python tracker 

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



[issue42295] Error should be flagged if Walrus operator is used for multiple assigment

2020-11-09 Thread John Zalewski


New submission from John Zalewski :

#The 'Walrus' operator does not support multiple assignment but does not #flag 
an attempt to make a multiple assigment as an error
#This results in unexpected behavior at execution time:

a, b = 100, 200

print (a, b)
#result is
#100 200

if (a, b := 3, 4): #this should be flagged as an error but is not



  print ("found true")
else:
  print ("found false")

print (a, b)
#result is
#100 3 but if multiple assigment were allowed this would be '3, 4'


--
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\John PC 
2017\AppData\Local\Programs\Python\Python38-32\walrustest.py
100 200
found true
100 3
>>>

--
files: walrustest.py
messages: 380580
nosy: JohnPie
priority: normal
severity: normal
status: open
title: Error should be flagged if Walrus operator is used for multiple assigment
type: compile error
versions: Python 3.9
Added file: https://bugs.python.org/file49583/walrustest.py

___
Python tracker 

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



[issue41287] __doc__ attribute is not set in property-derived classes

2020-11-09 Thread Sergei Izmailov


Change by Sergei Izmailov :


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

___
Python tracker 

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



  1   2   >