[issue44513] for string methods strip, lstrip, rstrip, when param is a string which has more than one char, those methods is no useful currently

2021-06-25 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Dennis is correct: these are working as attended, you have just misunderstood 
what they are supposed to do.

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



[issue44513] for string methods strip, lstrip, rstrip, when param is a string which has more than one char, those methods is no useful currently

2021-06-25 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

This is the intended behavior. Use s.removeprefix() and s.removesuffix() 
instead.

--
nosy: +Dennis Sweeney

___
Python tracker 

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



[issue44513] for string methods strip, lstrip, rstrip, when param is a string which has more than one char, those methods is no useful currently

2021-06-25 Thread redrose2100


New submission from redrose2100 :

for string methods strip, lstrip, rstrip, when param is a string which has more 
than 1 char, currently those methods remove char ,but not remove string , it is 
no useful

following is the results in python 3.9.5

Python 3.9.5 (default, May 18 2021, 14:42:02) [MSC v.1916 64 bit (AMD64)] :: 
Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s="hellolloehb"
>>> print(s.lstrip("hello"))
b
>>> s="blloehhello"
>>> print(s.rstrip("hello"))
b
>>> s="helloehhollbllohhehello"
>>> print(s.strip("hello"))
b
>>>
In fact,
when s="hellolloehb" , s.lstrip("hello") expect to get "lloehb"
when s="blloehhello" , s.rstrip("hello") expect to get "blloeh"
when s="helloehhollbllohhehello" , s.strip("hello") expect to get 
"ehhollbllohhe"

--
components: Library (Lib)
messages: 396538
nosy: redrose2100
priority: normal
severity: normal
status: open
title: for string methods strip, lstrip, rstrip, when param is a string which 
has more than one char, those methods is no useful currently
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



[issue44504] Make docstring quotes consistent in Lib/_collections_abc.py

2021-06-25 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Marking as closed for the reasons listed in the PR comments.

--
nosy: +rhettinger
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue44512] csv.DictWriter: inconsistency in handling of extrasaction arg

2021-06-25 Thread Andrei Kulakov


New submission from Andrei Kulakov :

In csv.DictWriter, the arg `extrasaction` case is handled inconsistently:

- if it's misspelled, e.g. ignor instead of 'ignore', a ValueError is raised by 
the __init__ method.

- if it's 'Ignore', 'IGNORE', it will work properly

- if it's 'raise', it will also work properly

- BUT: if it's 'Raise' or 'RAISE', it will have the same effect as 'ignore'

The code is here: 
https://github.com/python/cpython/blob/main/Lib/csv.py#L135-L146


[ins] In [1]: from csv import DictWriter

[ins] In [4]: d=DictWriter(open('testcsv','w'),'abc',extrasaction='IGNORE')

[ins] In [5]: list(d._dict_to_list(dict(d=1)))
Out[6]: ['', '', '']

[ins] In [7]: d=DictWriter(open('testcsv','w'),'abc',extrasaction='RAISE')

[ins] In [8]: list( d._dict_to_list(dict(d=1)) )
Out[8]: ['', '', '']

[ins] In [9]: d=DictWriter(open('testcsv','w'),'abc',extrasaction='TEST')
---
ValueErrorTraceback (most recent call last)
 in 
> 1 d=DictWriter(open('testcsv','w'),'abc',extrasaction='TEST')

/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/csv.py
 in __init__(self, f, fieldnames, restval, extrasaction, dialect, *args, **kwds)
134 self.restval = restval  # for writing short dicts
135 if extrasaction.lower() not in ("raise", "ignore"):
--> 136 raise ValueError("extrasaction (%s) must be 'raise' or 
'ignore'"
137  % extrasaction)
138 self.extrasaction = extrasaction

ValueError: extrasaction (TEST) must be 'raise' or 'ignore'


[ins] In [10]: d=DictWriter(open('testcsv','w'),'abc',extrasaction='raise')

[ins] In [11]: list( d._dict_to_list(dict(d=1)) )
---
ValueErrorTraceback (most recent call last)
 in 
> 1 list( d._dict_to_list(dict(d=1)) )

/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/csv.py
 in _dict_to_list(self, rowdict)
147 wrong_fields = rowdict.keys() - self.fieldnames
148 if wrong_fields:
--> 149 raise ValueError("dict contains fields not in 
fieldnames: "
150  + ", ".join([repr(x) for x in 
wrong_fields]))
151 return (rowdict.get(key, self.restval) for key in 
self.fieldnames)

ValueError: dict contains fields not in fieldnames: 'd'



I propose to accept any case of Raise, RAISE, etc, to have the effect of 
'raise'.

I can put up the PR if that sounds good.

--
components: Library (Lib)
messages: 396536
nosy: andrei.avk
priority: normal
severity: normal
status: open
title: csv.DictWriter: inconsistency in handling of extrasaction arg
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



[issue44510] file.read() UnicodeDecodeError with UTF-8 BOM in files on Windows

2021-06-25 Thread Eryk Sun


Eryk Sun  added the comment:

> On Windows we currently still default to your console encoding

In Windows, the default encoding for open() is the ANSI code page of the 
current process [1], from GetACP(), which is based on the system locale, unless 
it's overridden to UTF-8 in the application manifest. The console encoding is 
unrelated and not something we use much anymore since io._WindowsConsoleIO was 
introduced in Python 3.6.

--
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
versions: +Python 3.6, Python 3.9 -Python 3.11

___
Python tracker 

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



[issue44510] file.read() UnicodeDecodeError with UTF-8 BOM in files on Windows

2021-06-25 Thread Steve Dower


Steve Dower  added the comment:

The file that fails contains a UTF-8 BOM at the start, which is a multibyte 
character indicating that the file is definitely UTF-8.

Unfortunately, none of Python's default settings will handle this, because it's 
a convention that only really exists on Windows.

On Windows we currently still default to your console encoding, since that is 
what we have always done and changing it by default is very complex. Apparently 
your console encoding does not include the character represented by the first 
byte of the BOM - in any case, it's not a character you'd ever want to see, so 
if it _had_ worked, you'd just have garbage in your read data.

The immediate fix for your scenario is to use "open(filename, 'r', 
encoding='utf-8-sig')" which will handle the BOM correctly.

For the core team, I still think it's worth having the default encoding be able 
to read and drop the UTF-8 BOM from the start of a file. Since we shouldn't do 
it for any arbitrary operation (which may not be at the start of a file), it'd 
have to be a special default object for the TextIOWrapper case, but it would 
have solved this issue. If the BOM is there, it can switch to UTF-8 (or UTF-16, 
if that BOM exists); if not, it can use whatever the default would have been 
(based on all the other available settings).

--
nosy: +methane
title: file.read() UnicodeDecodeError with large files on Windows -> 
file.read() UnicodeDecodeError with UTF-8 BOM in files on Windows
versions: +Python 3.11 -Python 3.6, Python 3.9

___
Python tracker 

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



[issue44511] Improve the bytecode for mapping patterns

2021-06-25 Thread Brandt Bucher


New submission from Brandt Bucher :

The generated bytecode for mapping patterns is more complicated than it needs 
to be:

- Matching sub-patterns involves indexing into a tuple of values in order to 
extract them. We already know the size of this tuple at compile-time, so we can 
just unpack it onto the stack instead.

- COPY_DICT_WITHOUT_KEYS isn't used anywhere else, and can be emulated with 
existing, smaller instructions (albeit using quite a few of them).

- MATCH_KEYS doesn't need to push a boolean indicating match / no match. It 
already pushes None on no match, so following it with a simple DUP_TOP() + 
LOAD_CONST(None) + IS_OP(1) should suffice.

These are mostly just refactoring opportunities... quick-and-dirty measurements 
of Lib/test_patma.py show no performance impact for these changes.

--
assignee: brandtbucher
components: Interpreter Core
messages: 396533
nosy: brandtbucher
priority: normal
severity: normal
status: open
title: Improve the bytecode for mapping patterns
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



[issue44510] file.read() UnicodeDecodeError with large files on Windows

2021-06-25 Thread Jason Yundt


Change by Jason Yundt :


--
nosy: +jayman

___
Python tracker 

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



[issue44510] file.read() UnicodeDecodeError with large files on Windows

2021-06-25 Thread Rohan Amin


New submission from Rohan Amin :

When using file.read() with a large text file,  
there is a UnicodeDecodeError. I expected file.read(1) to read one character 
from the file. It works with a smaller text file. I experienced this bug on  
Windows 10 version 20H2. My teacher couldn't reproduce this bug on Linux.

--
components: IO, Unicode, Windows
files: Bug Reproduction Code.zip
messages: 396532
nosy: RohanA, ezio.melotti, paul.moore, steve.dower, tim.golden, vstinner, 
zach.ware
priority: normal
severity: normal
status: open
title: file.read() UnicodeDecodeError with large files on Windows
type: behavior
versions: Python 3.6, Python 3.9
Added file: https://bugs.python.org/file50126/Bug Reproduction Code.zip

___
Python tracker 

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



[issue36265] Remove ABCs from collections

2021-06-25 Thread Irit Katriel


Irit Katriel  added the comment:

This was updated in later 3.8.X versions:

https://github.com/python/cpython/blob/71ba16b21cb35923098026117b5e6d823c5f5707/Lib/collections/__init__.py#L49

warnings.warn("Using or importing the ABCs from 'collections' instead "
"of from 'collections.abc' is deprecated since Python 3.3, "
"and in 3.10 it will stop working",
DeprecationWarning, stacklevel=2)

--
nosy: +iritkatriel
resolution:  -> fixed
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



[issue44509] Build in type alias for paths

2021-06-25 Thread alex rakowski


alex rakowski  added the comment:

I just noticed this issue was raised and dismissed in  PEP 519 -- Adding a file 
system path protocol.

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



[issue38055] Starting multiprocessing.Process raises FileNotFoundError unexpectedly

2021-06-25 Thread Irit Katriel


Irit Katriel  added the comment:

Closing as there isn't enough information about the problem. If you are still 
seeing it, please create a new issue with full details.

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

___
Python tracker 

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



[issue32215] sqlite3 400x-600x slower depending on formatting of an UPDATE statement in a string

2021-06-25 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



[issue41866] Document error in chinese version of contextlib.

2021-06-25 Thread Irit Katriel


Change by Irit Katriel :


--
nosy: +zhsj

___
Python tracker 

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



[issue41539] print blocks with multiprocessing and buffered output

2021-06-25 Thread Irit Katriel


Irit Katriel  added the comment:

Is there anything left here?

I've seen it mentioned on other issues of this sort that mixing multiprocessing 
and threading leads to problems. Should we document that?

--

___
Python tracker 

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



[issue15066] make install error: ImportError: No module named _struct

2021-06-25 Thread Irit Katriel


Change by Irit Katriel :


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



[issue38146] QVariant NULL returns anomalous values in equality statements

2021-06-25 Thread Irit Katriel


Change by Irit Katriel :


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



[issue44109] missing dataclass decorator in match-statement example

2021-06-25 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I agree the example is confusing for all of the stated reasons.

It seems to me it's better to use a plain class with a `__init__()` for two 
reason:

- for people who are not familiar with namedtuples or dataclasses, it would be 
harder to learn two fairly complex topics at the same time. Docs for both are 
fairly extensive.

- for those who *are* familiar with namedtuples or dataclasses (whichever is 
used in the example), the example may imply they should be used with pattern 
matching, and that plain classes may not work or not work well.

I can make a PR that adds `__init__` if this makes sense..

--
nosy: +andrei.avk

___
Python tracker 

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



[issue44509] Build in type alias for paths

2021-06-25 Thread alex rakowski


New submission from alex rakowski :

Hello,

I've noticed that when type hinting paths, it often becomes a bit verbose:

from typing import Union
import pathlib 

custom_path = Union[str, pathlib.Path]

def foobar(x:custom_path):
   ...
Writing functions which handle paths are pretty routine, I'm wondering if it is 
worth including something that is importable e.g.

from typing import PathLike #or similar path_obj, PathType etc. 
def foobar(x:PathLike):
 ...

Apologies if similar functionality already exists,

Alex

--
components: Library (Lib)
messages: 396526
nosy: arakowski
priority: normal
severity: normal
status: open
title: Build in type alias for paths
type: enhancement
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



[issue43977] Implement the latest semantics for PEP 634 for matching collections

2021-06-25 Thread miss-islington


miss-islington  added the comment:


New changeset 88970125e7a4917966f711dc7e93cf170977034f by Miss Islington (bot) 
in branch '3.10':
bpo-43977: Properly update the tp_flags of existing subclasses when their 
parents are registered (GH-26864)
https://github.com/python/cpython/commit/88970125e7a4917966f711dc7e93cf170977034f


--

___
Python tracker 

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



[issue43977] Implement the latest semantics for PEP 634 for matching collections

2021-06-25 Thread miss-islington


Change by miss-islington :


--
pull_requests: +25484
pull_request: https://github.com/python/cpython/pull/26908

___
Python tracker 

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



[issue43977] Implement the latest semantics for PEP 634 for matching collections

2021-06-25 Thread Brandt Bucher


Brandt Bucher  added the comment:


New changeset ca2009d72a52a98bf43aafa9ad270a4fcfabfc89 by Brandt Bucher in 
branch 'main':
bpo-43977: Properly update the tp_flags of existing subclasses when their 
parents are registered (GH-26864)
https://github.com/python/cpython/commit/ca2009d72a52a98bf43aafa9ad270a4fcfabfc89


--

___
Python tracker 

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



[issue44508] asyncio: document failure mode for loop.call_soon_threadsafe

2021-06-25 Thread Mark Dickinson


New submission from Mark Dickinson :

`loop.call_soon_threadsafe` raises `RuntimeError` when the event loop has been 
closed, but that fact doesn't seem to be documented. It would be useful to 
document it so that that it's clear that that behaviour is part of the API, and 
can be depended on.

Doc link: I'm looking at 
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_soon_threadsafe

My use-case is that I have a background thread that's making use of 
`loop.call_soon_threadsafe` to place callbacks onto the main thread's event 
loop. The main thread at some point closes that event loop (e.g., as part of 
controlled application shutdown, or in the tearDown of a unit test). The 
background thread isn't in a position to know whether the event loop has been 
closed or not, and obviously checking that using the `is_closed` attribute runs 
into race condition issues. So I'd like to catch the potential exception from 
the `loop.call_soon_threadsafe`, but to do that I need to know what exception 
type to catch.

It would probably also make sense to document the failure mode for 
`loop.call_soon`.

--
assignee: docs@python
components: Documentation, asyncio
messages: 396523
nosy: asvetlov, docs@python, mark.dickinson, yselivanov
priority: normal
severity: normal
status: open
title: asyncio: document failure mode for loop.call_soon_threadsafe
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



[issue43944] Processes in Python 3.9 exiting with code 1 when It's created inside a ThreadPoolExecutor

2021-06-25 Thread Alexandre Sicard


Alexandre Sicard  added the comment:

Thank you very much for this report, Genaro. I encountered the same bug with a 
Process running in the context of a Django view. Downgrading to Python 3.8 also 
fixed the issue for me.

Versions:
python:3.9-alpine Docker image, running Python 3.9.5 and Alpine 3.13. Can also 
reproduce on the standard (Debian Buster based) python:3.9 image, and on Arch 
Linux (bare metal), all also running Python 3.9.5.

--
nosy: +sicard_elda

___
Python tracker 

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



[issue36392] IPv4Interface Object has no attributte prefixlen

2021-06-25 Thread Václav Šmilauer

Václav Šmilauer  added the comment:

This one works: addr.network.prefixlen.  It took me a while to find out; I find 
the documentation somewhat confusing in this point.

--
nosy: +eudoxos

___
Python tracker 

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