[issue44801] Type expression is coerced to a list of parameter arguments in substitution of ParamSpec

2021-08-01 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

Type expression is coerced to a list of parameter arguments in substitution of 
ParamSpec. For example:

>>> from typing import *
>>> T = TypeVar('T')
>>> P = ParamSpec('P')
>>> C = Callable[P, T]
>>> C[int, str]
typing.Callable[[int], str]

int becomes [int]. There is even a dedicated test for this.

But it is not followed from PEP 612. Furthermore, it contradicts one of 
examples in the PEP:

>>> class X(Generic[T, P]):
... f: Callable[P, int]
... x: T
... 
>>> X[int, int]  # Should be rejected
__main__.X[int, int]

It makes the implementation (at least the code in issue44796) more complex and 
makes the user code more errorprone.

--
messages: 398687
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Type expression is coerced to a list of parameter arguments in 
substitution of ParamSpec

___
Python tracker 

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



[issue44801] Type expression is coerced to a list of parameter arguments in substitution of ParamSpec

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
components: +Library (Lib)
dependencies: +Arguments ignored in substitution in typing.Callable
type:  -> behavior
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



[issue44801] Type expression is coerced to a list of parameter arguments in substitution of ParamSpec

2021-08-01 Thread Ken Jin


Ken Jin  added the comment:

> Type expression is coerced to a list of parameter arguments in substitution 
> of ParamSpec.

It's not, only the repr is like that. Internally it's not coerced.

>>> C[int, str]
typing.Callable[[int], str]
>>> C[int, str].__args__
(, )

Because Callable's correct form is Callable[[type], type] (where type is not 
ParamSpec or Concatenate) so the repr reflects that.

Internally, Callable also flattens the list of args:

>>> Callable[[int, str], int].__args__
(, , )

Because __args__ *must* be hashable and immutable. Otherwise, it will not work 
with Union or Literal. Some time ago we tried converting to nested tuple. But 
that was too difficult (and backwards incompatible) because every other typing 
operation expected __args__ to contain types, not a tuple.

--

___
Python tracker 

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



[issue25947] Installation problem

2021-08-01 Thread Jon Camilleri


Jon Camilleri  added the comment:

this is your call, sorry.

On Tue, Jun 22, 2021 at 4:06 PM Irit Katriel  wrote:

>
> Irit Katriel  added the comment:
>
> Version 3.5 is no longer supported. If you are having issues installing a
> current version (3.9+) please create a new issue.
>
> --
> nosy: +iritkatriel
> resolution:  -> out of date
> stage:  -> resolved
> status: open -> closed
>
> ___
> Python tracker 
> 
> ___
>

-- 
Jonathan Camilleri

Mobile (MT): ++356 7982 7113
E-mail: camilleri@gmail.com
Please consider your environmental responsibility before printing this
e-mail.

I usually reply to emails within 2 business days.  If it's urgent, give me
a call.
https://worldhappiness.report/

--

___
Python tracker 

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



[issue44590] Create frame objects lazily when needed

2021-08-01 Thread Nick Coghlan


Change by Nick Coghlan :


--
nosy: +ncoghlan
nosy_count: 3.0 -> 4.0
pull_requests: +26041
pull_request: https://github.com/python/cpython/pull/27525

___
Python tracker 

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



[issue44800] Code readability: rename interpreter frames to execution frames

2021-08-01 Thread Nick Coghlan


Change by Nick Coghlan :


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

___
Python tracker 

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



[issue44800] Code readability: rename interpreter frames to execution frames

2021-08-01 Thread Nick Coghlan


Nick Coghlan  added the comment:

PR for this proposed refactoring is now up, with a review requested from Mark: 
https://github.com/python/cpython/pull/27525/

The PR mostly follows what I originally posted, except that I went with 
_Py_execution_frame and _PyExecFrame for the struct and typedef names, since 
these are present in a public header.

The outdated GDB hooks I found were in the gdbinit example file, rather than 
the actual libpython.py file that test_gdb covers. I suspect the gdbinit 
example will need further adjustments to actually work with Python 3.11, so 
rather than fully updating the implementation dependent pieces, I just added a 
comment suggesting it be checked after the interpreter optimisation development 
for 3.11 settles down.

--

___
Python tracker 

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



[issue43596] change assertRaises message when wrong exception is raised

2021-08-01 Thread Irit Katriel

Irit Katriel  added the comment:

Another way to look at it is that your test has two problems. One is that the 
expected exception didn’t happen and the other is that an unexpected exception 
happened. 

The two problems are usually unrelated, and trying to conflate them into one 
error message can be confusing in some cases. When a test has multiple problems 
you get an error for the first one.

--

___
Python tracker 

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



[issue44186] TimedRotatingFileHandler overwrite log

2021-08-01 Thread Harry


Harry  added the comment:

The issue appears when the TimedRotatingHandler rolls over to a filename that 
already exists. Running your bash script, the handler correctly rolls over so 
you end up with the expected behaviour. This issue arises in the case that 
there is already a file with the target name, that file will be overwritten 
when the handler rolls over.

This can be seen clearly if you modify test.sh to contain

python3 log_44186.py foo
python3 log_44186.py bar
python3 log_44186.py baz

results are below:

$ python3 --version
Python 3.9.5
$ bash ./test.sh
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : foo 2021-08-01T10:14:51.521266
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : bar 2021-08-01T10:14:51.577802
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : baz 2021-08-01T10:14:51.634795
$ ls | grep .log
test.log
test.log.2021-07-31
$ cat test.log
baz 2021-08-01T10:14:51.634795
$ cat test.log.2021-07-31 
bar 2021-08-01T10:14:51.577802

as you can see, the logs from foo have been overwritten.

A very similar result can be seen if you manually create a file and then run 
the test script.

$ python3 --version
Python 3.9.5
$ echo "logging test" > test.log.2021-07-31
$ python3 log_44186.py foo
10 33 25
TEST > [INFO] [2021-08-01 10:33:25] : foo 2021-08-01T10:33:25.003750
$ cat test.log
foo 2021-08-01T10:33:25.003750
$ cat test.log.2021-07-31
$

once again, you can see that the handler overwrote the target file (this time 
leaving it blank as there were no logs to write).

--

___
Python tracker 

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



[issue43596] change assertRaises message when wrong exception is raised

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I concur with Irit. The test is failed in any case, so you need to look at the 
code to fix it.

For the same reason we do not have assertNotRaises().

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue44802] Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars

2021-08-01 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

If the user generic with ParamSpec parameter substituted with a parametrised 
list containing TypeVar, that TypeVar cannot be substituted.

>>> from typing import *
>>> T = TypeVar("T")
>>> P = ParamSpec("P")
>>> class X(Generic[P]):
... f: Callable[P, int]
... 
>>> Y = X[[int, T]]
>>> Y
__main__.X[(, ~T)]
>>> Y[str]
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/typing.py", line 309, in inner
return func(*args, **kwds)
   ^^^
  File "/home/serhiy/py/cpython/Lib/typing.py", line 1028, in __getitem__
_check_generic(self, params, len(self.__parameters__))
^^
  File "/home/serhiy/py/cpython/Lib/typing.py", line 228, in _check_generic
raise TypeError(f"{cls} is not a generic class")

TypeError: __main__.X[(, ~T)] is not a generic class

Expected result equal to X[[int, str]].

--
components: Library (Lib)
messages: 398694
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Substitution does not work after ParamSpec substitution of the user 
generic with a list of TypeVars
type: behavior
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



[issue20779] Add pathlib.chown method

2021-08-01 Thread Emmanuel Arias


Emmanuel Arias  added the comment:

Hello!

I also use it frequently, but looking this issue I can agree with pitrou that 
there aren't  lot of people that use chown.

If I'm not wrong, there's a trend to move os to pathlib, perhaps chown should 
be in pathlib too :)

I can work on this.

--
nosy: +eamanu

___
Python tracker 

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



[issue20779] Add pathlib.chown method

2021-08-01 Thread Emmanuel Arias


Change by Emmanuel Arias :


--
versions: +Python 3.11 -Python 3.5

___
Python tracker 

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



[issue44590] Create frame objects lazily when needed

2021-08-01 Thread Nick Coghlan


Nick Coghlan  added the comment:

The newly linked pull request isn't actually for this ticket, it's for 
bpo-44800, a follow-up refactoring proposal related to the variable, struct 
field, and API naming schemes used for the new lighter weight execution frames.

However, the commit message and PR description refer back to this ticket as 
well, so the RoundUp automation picked it up.

--

___
Python tracker 

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



[issue43183] Asyncio can't close sockets properly on Linux cause CLOSE_WAIT

2021-08-01 Thread Nathan Collins


Nathan Collins  added the comment:

What was the resolution for this issue? I'm experiencing 
asyncio.StreamReader.readline() hanging forever on a socket in CLOSE_WAIT state.

--
nosy: +NathanCollins

___
Python tracker 

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



[issue22240] argparse support for "python -m module" in help

2021-08-01 Thread Nick Coghlan


Nick Coghlan  added the comment:

(Note: this is an old enough ticket that it started out with patch files on the 
tracker rather than PRs on GitHub. That's just a historical artifact, so feel 
free to open a PR as described in the devguide if you would prefer to work that 
way)

There are two common ways of solving import bootstrapping problems that affect 
the build process:

1. Make the problematic import lazy, so it only affects the specific operation 
that needs the binary dependency; or
2. Wrap a try/except around the import, and do something reasonable in the 
failing case

However, I think in this case it should be possible to avoid the zipfile 
dependency entirely, and instead make the determination based on the contents 
of __main__ and __main__.__spec__ using the suggestions I noted in an earlier 
comment (see 
https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec 
for the info the module spec makes available).

This should also solve a problem I believe the current patch has, where I think 
directory execution will give the wrong result (returning "python -m __main__" 
as the answer instead of the path to the directory containing the __main__.py 
file).

The three cases to cover come from 
https://docs.python.org/3/using/cmdline.html#interface-options:

* if `__main__.__spec__` is None, the result should continue to be 
`_os.path.basename(_sys.argv[0])` (as it is in the patch)
* if `__main__.__spec__.name` is exactly the string "__main__", 
`__main__.__spec__.parent` is the empty string, and 
`__main__.__spec__.has_location` is true, and sys.argv[0] is equal to 
`__main__.__spec__.origin` with the trailing `__main__.py` removed, then we 
have a directory or zipfile path execution case, and the result should be a 
Python path execution command using f'{py} {arg0}
* otherwise, we have a `-m` invocation, using f'{py} -m 
{mod.__spec__.name.removesuffix(".__main__")}'


The patch gets the three potential results right, but it gets the check for the 
second case wrong by looking specifically for zipfiles instead of looking at 
the contents of __main__.__spec__ and seeing if it refers to a __main__.py file 
located inside the sys.argv[0] path (which may be a directory, zipfile, or any 
other valid sys.path entry).

For writing robust automated tests, I'd suggest either looking at 
test.support.script_helper for programmatic creation of executable zipfiles and 
directories ( 
https://github.com/python/cpython/blob/208a7e957b812ad3b3733791845447677a704f3e/Lib/test/support/script_helper.py#L209
 ) or else factoring the logic out such that there is a helper function that 
receives "__main__.__spec__" and "sys.argv[0]" as parameters, allowing the test 
suite to easily control them.

The latter approach would require some up front manual testing to ensure the 
behaviour of the different scenarios was being emulated correctly, but would 
execute a lot faster than actually running subprocesses would.

--

___
Python tracker 

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



[issue44803] change tracemalloc.BaseFilter to an abstract class

2021-08-01 Thread Anton Grübel

New submission from Anton Grübel :

during some work on typeshed I found the BaseFilter class in tracemalloc and it 
totally looks like and is used as a typical abstract class.

I will also directly create the PR :) if you think I'm missing something, I'm 
happy to hear some other thoughts.

--
components: Library (Lib)
messages: 398699
nosy: anton.gruebel
priority: normal
severity: normal
status: open
title: change tracemalloc.BaseFilter to an abstract class
type: enhancement
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



[issue43838] There is a way to access an underlying mapping in MappingProxyType

2021-08-01 Thread Nick Coghlan


Nick Coghlan  added the comment:

Ouch, you're right - I forgot that dict just returned NotImplemented from 
comparisons and unions and made it the other operand's problem:

>>> d1 = dict(x=1)
>>> d2 = dict(x=1)
>>> from types import MappingProxyType as proxy
>>> d1.__eq__(proxy(d2))
NotImplemented
>>> d1.__or__(proxy(d2))
NotImplemented

Perhaps we could mitigate the performance hit by skipping the copy when the 
other side is either a builtin dict (subclasses don't count), or a proxy around 
a builtin dict?

--

___
Python tracker 

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



[issue44803] change tracemalloc.BaseFilter to an abstract class

2021-08-01 Thread Anton Grübel

Change by Anton Grübel :


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

___
Python tracker 

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



[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-01 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +carljm, ncoghlan, pydanny

___
Python tracker 

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



[issue43596] change assertRaises message when wrong exception is raised

2021-08-01 Thread Mark Dickinson


Mark Dickinson  added the comment:

I think I understand where the request comes from: in the case where you've 
changed the exception type that an API is expected to raise, and you've either 
updated the test to check for the new exception type and missed an update in 
the business logic, or vice versa, you'd like the test to tell you that the 
wrong exception type was raised. I've definitely done this myself on more than 
a few occasions.

So this *particular* case is an exception to Irit's observation that "The two 
problems are usually unrelated [...]". But I think it *is* an exception: I 
agree that the rule holds in general, and that the current behaviour shouldn't 
be changed.

I think we've got sufficient agreement from core devs to close here.

--
nosy: +mark.dickinson
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

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



[issue43596] change assertRaises message when wrong exception is raised

2021-08-01 Thread Irit Katriel

Irit Katriel  added the comment:

I agree. That’s what the “usually” was for.

--

___
Python tracker 

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



[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Possible replacement recipes:

-- Implement as a class -

class LRU:

def __init__(self, func, maxsize=128):
self.func = func
self.d = OrderedDict()

def __call__(self, *args):
if args in self.d:
value = self.d[args]
self.d.move_to_end(args)
return value
value = self.func(*args)
if len(self.d) >= self.maxsize:
self.d.popitem(False)
self.d[args] = value
return value

-- Implement as a closure ---

def lru_cache(maxsize):
def deco(func):
d = OrderedDict()
def inner(*args):
if args in d:
d.move_to_end(args)
return d[args]
answer = func(args)
d[args] = answer
if len(d) > maxsize:
d.popitem(False)
return answer
return inner
return deco

--

___
Python tracker 

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



[issue37398] contextlib.ContextDecorator decorating async functions

2021-08-01 Thread Nick Coghlan


Nick Coghlan  added the comment:

You are correct that this proposal is technically rejected, rather than being a 
true duplicate of the AsyncContextManager addition.

The core problem with the automatic inference idea is that it isn't possible 
for the standard library to reliably distinguish at decoration time between 
"synchronous function that happens to return an awaitable" and "coroutine 
factory function written as a synchronous function that should nevertheless be 
treated like a coroutine function".

That ambiguity doesn't exist when ContextDecorator and AsyncContextDecorator 
are applied to distinct helper functions.

Within a given codebase, you may be able to write a "coroutine argument 
detection" function that is robust enough for that particular codebase (and 
iscoroutinefunction() may even be adequate for that purpose), in which case 
ContextDecorator and AsyncContextDecorator provide the building blocks for 
implementing the two halves of the solution, leaving only the auto-switching 
code as project specific.

--
resolution: duplicate -> rejected

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> I think Serhiy's patch here (before revert) may be a 
> good idea (to re-apply).

That seems sensible to me as well.  It keeps the C version in harmony with the 
pure python version and it follows how regular dict's are implemented.

Serhiy, do you remember why your patch was reverted?

--

___
Python tracker 

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



[issue44789] CPython cannot be compiled with -pedantic

2021-08-01 Thread Dennis Clarke


Dennis Clarke  added the comment:

I very likely do not understand what is happening here. From my little
perspective the Python project has become far too critical to be yet
another language that can not be ported and used just about anywhere. I
often port software from various places into strange machines and even
onto z/OS mainframe type places. There is nothing more beautiful than
to take some C89 clean code and watch it just work. Flawlessly. Even the
OpenSSL project is locked neatly to that old C89 standard. I have tried
to get into a discussion about C99 but was always flatly told that we
need OpenSSL to work everywhere. Pretty much on anything that you can
get a compiler will do just fine. With the exception of some very small
embedded devices or tight memory constraints. It just works. Sadly the
Go Programming language is not like that. Neither is Rust. When I look
at The Python Project "Style Guide for C Code" here : 

https://www.python.org/dev/peps/pep-0007/ 

The message is clearly stated :

Python versions greater than or equal to 3.6 use C89 with 
several select C99 features:

- Standard integer types in  and .
We require the fixed width integer types.

- static inline functions

- designated initializers (especially nice for type
 declarations)

- intermingled declarations

- booleans

- C++-style line comments

Future C99 features may be added to this list in the future
depending on compiler support (mostly significantly MSVC).

Don't use GCC extensions (e.g. don't write multi-line strings
   without trailing backslashes).

All function declarations and definitions must use full prototypes
 (i.e. specify the types of all arguments).

Only use C++ style // one-line comments in Python 3.6 or later.

No compiler warnings with major compilers (gcc, VC++, a few others).

That last line is a bit of a dream but I didn't write that. I merely 
took a copy from the "Style Guide for C Code".  So perhaps that needs a
rewrite and just state that the code will be mostly C99 safe and maybe
it would be best to just say iso9899:2011 and keep on plowing forwards.

One thing is certain, I built the OpenSSL 3.0.0 beta1 software on a pile
of systems in the last few weeks and then rebuilt a pile of dependant
libs and tools. They all work. Curl and libCurl is flawless. I am trying
to get Apache httpd 2.4.x ( and also trunk ) built and running. The only
major piece missing, critical and really important, is Python.  OKay I 
also have issues with ISC Bind but they seem to be drinking some strange
brew lately and their unit tests and other code has gone crab sideways.
That is another problem in someone elses backyard.  Python however looks
to be very highly portable and it just works on everything. Pretty much.

So having said all that should this just be iso9899:2011 with no major
surprises?

ps: from the "Style Guide for C Code" we also see these gems : 

Use 4-space indents and no tabs at all.

No line should be longer than 79 characters. If this and the
previous rule together don't give you enough room to code, your
code is too complicated -- consider using subroutines.

No line should end in whitespace. If you think you need significant
trailing whitespace, think again -- somebody's editor might delete
it as a matter of routine.

Those are just priceless old rules from the Fortan punchcard days.

--

___
Python tracker 

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



[issue41973] Docs: TypedDict is now of type function instead of class

2021-08-01 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I haven't looked too much into typing module, so take this with a grain of 
salt, but my understanding is that TypedDict is a special construct (as the 
first sentence in the docs defines it), which can be used as a base. I think 
most users would consider something a kind of a class if it can be inherited 
from by a user-defined class, so this classification in the docs is useful.

Normally functions can't be used as a base of course. There's no "inheritable 
from" abc or anything like that and functions are not inherited from "function 
type". You generally don't care if something is a function, you care if it's a 
callable and test for that with `callable()`.

So in a sense a function is the most inherently duck typed object in Python.

The only way for a specific check of a function type is AFAIK 
type(known_function) == type(myobj), but this type of checking is discouraged.

So static checkers that run into a problem with this are probably assuming too 
much about what a function is or should be in Python.

To sum up, TypedDict is a kind of a construct between a class and a function 
that's more usefully documented as, and used as, a class. The docs make it very 
clear that it's not your usual, run of the mill class.

--
nosy: +andrei.avk

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It was reverted because it did not keep the C version in harmony with the pure 
Python version. In the pure Python version pop() calls __getitem__ and 
__delitem__ which can be overridden in subclasses of OrederedDict. My patch 
always called dict.__getitem__ and dict.__delitem__.

But I see now clearer what is the problem with the current C code. It removes 
the key from the linked list before calling __delitem__ which itself removes 
the key from the linked list. Perhaps I can fix it correctly this time.

--

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.5, Python 3.6, Python 
3.7

___
Python tracker 

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



[issue44789] CPython cannot be compiled with -pedantic

2021-08-01 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I understand where you are coming from and I do agree, but this is something 
bigger than just what we can do in an issue, as it spawns multiple other places 
(again, many files fail with -pedantic). Is not a titanic task but is also not 
straightforward. My recommendation is to send a brief email to python-dev about 
these concerns to gather some feedback from the community, as this issue is 
probably not going to have all the attention that this would otherwise require.

For example, there are several pieces of infrastructure that use GNU extensions 
already by default when compiled with clang and gcc (like computed gotos), so 
activating -pedantic will invalidate those simple checks.

--

___
Python tracker 

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



[issue44789] CPython cannot be compiled with -pedantic

2021-08-01 Thread Dennis Clarke


Dennis Clarke  added the comment:

Oh, I think we can give up on -pedantic and -pedantic-errors. It is
just a nifty litmus paper test to see how code cranks under nasty
contraints. I would be hapyp with iso9899:1999 or even iso9899:2011.

Thank you for the feedback and the excellent response time. I am so
very happy with the Python team bug report process and quite frankly
there are a lot of good people working on the quality code. 


-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional

--

___
Python tracker 

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



[issue42019] Override MagicMock special methods

2021-08-01 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I think this can be closed.

--
nosy: +andrei.avk

___
Python tracker 

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



[issue42019] Override MagicMock special methods

2021-08-01 Thread Irit Katriel


Irit Katriel  added the comment:

+ Michael, in case he has something to add.

--
nosy: +michael.foord

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It is complicated. The pure Python implementation of OrderedDict.popitem() and 
OrderedDict.pop() are not consistent. The former uses dict.pop() which doesn't 
call __getitem__ and __setitem__. The latter calls __getitem__ and __setitem__. 
The C implementation shared code between popitem() and pop(), therefore it will 
differ from the pure Python implementation until we write separate code for 
popitem() and pop().

--

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +26043
pull_request: https://github.com/python/cpython/pull/27528

___
Python tracker 

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



[issue42038] Tracemalloc's format() doc contradictory

2021-08-01 Thread Andrei Kulakov


Change by Andrei Kulakov :


--
keywords: +patch
nosy: +andrei.avk
nosy_count: 2.0 -> 3.0
pull_requests: +26044
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27529

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Let's do the right thing and fix the pure python OrderedDict.pop() method as 
well.

--

___
Python tracker 

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



[issue42038] Tracemalloc's format() doc contradictory

2021-08-01 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

I agree that the doc is wrong; I've put up the tiny PR here:
https://github.com/python/cpython/pull/27529/files

Note that linecache.getline() returns line with \n but is then .strip()'ed.

--

___
Python tracker 

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



[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I agree that composition is methodologically more correct than inheritance for 
implementing a variant of lru_cache(). But if you need lru_cache() why not use 
lru_cache() from the stdlib? I think that instead of showing a poor version of 
the lru_cache() decorator, it is better to show a tool which can be used for 
LRU caching. The key and the value should be evaluated externally. In other 
word, class LRU with methods __contains__(), __getitem__() and __setitem__() 
(or get() and set()). It should use composition.

Alternatively we can add a comment that it is just an example, and some methods 
(like pop()) can not work.

--

___
Python tracker 

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



[issue41973] Docs: TypedDict is now of type function instead of class

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

TypeDict is a callable, it can be used as

Point2D = TypedDict('Point2D', x=int, y=int, label=str)

It can also be used as a base in class definition, but is is not a class 
itself. It does not occur in __bases__ of the created class, and it cannot be 
used in isinstance() and issubclass() checks. It is just yet one weird way to 
customize class creation.

I agree that documenting it as class is not correct. Perhaps it should be 
declared as a function (with specifying its signature when used as a function) 
and referred with the :data: role.

--

___
Python tracker 

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



[issue41973] Docs: TypedDict is now of type function instead of class

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Actually most names defined in typing are no longer classes.

--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python, gvanrossum, kj
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



[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> It is hard to get rid of the execution lock once 
> it was introduced, but I think we should do it.

It's likely some apps are relying on the locking feature.
So if we can fix it, we should do prefer that over more
disruptive changes.

Addenda to my code sketch:  It should use "(id(instance), instance)" rather 
than just "instance" as the key.

--

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +26045
pull_request: https://github.com/python/cpython/pull/27530

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

PR 27528 makes the C implementation of OrderedDict.popitem() consistent with 
the Python implementation (do not call overridden __getitem__ and __setitem__).

PR 27530 changes also both implementations of OrderedDict.pop(). It simplifies 
the C code, but adds a duplication of the code in Python.

I am not sure how far we should backport these changes if backport them.

--

___
Python tracker 

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



[issue31724] test_xmlrpc_net should use something other than buildbot.python.org

2021-08-01 Thread Irit Katriel


Irit Katriel  added the comment:

The test is now skipped, but still need to be fixed.

--
keywords:  -patch
nosy: +iritkatriel
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 2.7, Python 3.6, Python 
3.7

___
Python tracker 

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



[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-01 Thread Joshua Bronson


Change by Joshua Bronson :


--
nosy: +jab

___
Python tracker 

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



[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> I am not sure how far we should backport these changes
> if backport them.

We've had no reports of the current code causing problems for any existing 
applications (except the LRU recipe in the docs), so there is likely no value 
in making backports.  Instead, we can clean it up so there won't be new issues 
going forward.

--
versions:  -Python 3.10, Python 3.9

___
Python tracker 

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



[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger


Change by Raymond Hettinger :


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

___
Python tracker 

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



[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> But if you need lru_cache() why not use lru_cache() 
> from the stdlib?

This gives a foundation for people who want to roll their own variants of the 
standard library lru_cache().  From here, people can experiment with pickle 
support, dynamic resizing, invalidation methods, max age parameters, other ways 
to construct a key, tests for total available memory, direct access to cache 
entries, or any of the other feature requests we've declined because they 
weren't appropriate for the standard library.

Also, it nicely shows-off the original motivating use case for move_to_end().

--

___
Python tracker 

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



[issue41980] Argparse documentation is slightly misleading

2021-08-01 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

Yannick: the PRs are submitted via github; you can find more detail on 
contributions workflow / process here:

https://devguide.python.org/

--
nosy: +andrei.avk

___
Python tracker 

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



[issue42235] [macOS] Use --enable-optimizations in build-installer.py

2021-08-01 Thread Ned Deily


Change by Ned Deily :


--
pull_requests:  -24521

___
Python tracker 

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



[issue44804] Port fix of "issue44422" to Python3.6.x

2021-08-01 Thread Arun


New submission from Arun :

We have seen multiple occurrences of the issue reported and fixed in 
https://bugs.python.org/issue44422, on RHEL8.3 with Python3.6.x. I understand 
RHEL8.4 is also shipping with Python3.6.x as the default version and it's going 
to be the same with RHEL8.5 as well. 

This bug is to port that fix to Python3.6.x version as well. This is impacting 
lot of our customers running large scale enterprise application.

--
components: Library (Lib)
messages: 398725
nosy: arunshan
priority: normal
severity: normal
status: open
title: Port fix of "issue44422" to Python3.6.x
versions: Python 3.6

___
Python tracker 

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



[issue32397] textwrap output may change if you wrap a paragraph twice

2021-08-01 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

This issue is due to *drop_whitespace* arg being True by default.

Documentation states that *drop_whitespace* applies after wrapping, so the fix 
in the PR would break that promise because, as far as I understand, it applies 
the wrapping after *drop_whitespace*. (Irit's comment on the PR refers to this).

I feel like the behaviour in the PR is more logical and probably what most 
users would prefer and need in most cases. But it's a backwards compatibility 
change of behaviour that's not buggy.

'foo  bar'
# wrap for width=10
['foo','bar']  # current behaviour
['foo bar']# more intuitive wrapping to width=10

As I was looking at this, I thought that wrapping with drop_whitespace=False 
would surely be stable. Not so!

It looks like the logic assumes that \n needs to be replaced by a space for 
cases like 'foo\nbar', which makes sense because otherwise two words would be 
joined together. But with drop_whitespace=False, repeated fill() calls will 
keep replacing \n with a space and then adding a new \n to split lines again:

  original: '    .  '
   wrapped: '    .  \n'
 wrapped twice: '    .   \n'
wrapped thrice: '    .\n'

Further, a newline with a nearby space within the requested width will be 
converted to two spaces:
'a\n b' => 'a  b'

I don't know if the original issue is worth fixing or not, but I think the 
issue shown above would be good to fix.

--
nosy: +andrei.avk

___
Python tracker 

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



[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Having a side effect at import time is not good. It will interfere with 
programs which just import pdb, but not use it.

There are two other options:

1. Import readline at top level, but call set_completer_delims() lazily.

2. Do not import readline at all. Call set_completer_delims() only if readline 
is already imported (sys.modules.get('readline') is not None).

I prefer the latter one.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue44804] Port fix of "issue44422" to Python3.6.x

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +ned.deily

___
Python tracker 

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



[issue44793] Arguments ignored in substitution in typing.Callable

2021-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset f92b9133ef67e77605cbd315b6b6c81036ce110e by Serhiy Storchaka in 
branch 'main':
bpo-44793: Fix checking the number of arguments when subscribe a generic type 
with ParamSpec parameter. (GH-27515)
https://github.com/python/cpython/commit/f92b9133ef67e77605cbd315b6b6c81036ce110e


--

___
Python tracker 

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



[issue44793] Arguments ignored in substitution in typing.Callable

2021-08-01 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 3.0 -> 4.0
pull_requests: +26047
pull_request: https://github.com/python/cpython/pull/27537

___
Python tracker 

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



[issue44785] test_pickle issues "DeprecationWarning: The Tix Tk.."

2021-08-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +serhiy.storchaka
nosy_count: 2.0 -> 3.0
pull_requests: +26048
pull_request: https://github.com/python/cpython/pull/27538

___
Python tracker 

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



[issue44804] Port fix of "issue44422" to Python3.6.x

2021-08-01 Thread Ned Deily


Ned Deily  added the comment:

Sorry you are running into this problem. Alas, Python 3.6 has been in the 
"security-fix-only" phase of its life cycle for over 2.5 years now and will 
reach end-of-life in several months at the end of 2021. Our criteria for 
changes to a "security" branch are:
"The only changes made to a security branch are those fixing issues exploitable 
by attackers such as crashes, privilege escalation and, optionally, other 
issues such as denial of service attacks. Any other changes are not considered 
a security risk and thus not backported to a security branch."

The problem referenced here does not seem to meet those criteria and thus the 
original fix was not considered for backporting to current security branches, 
i.e. 3.8, 3.7, and 3.6. Unless it can be shown that the problem can be 
exploited as an attack vector, it is not eligible to be officially backported 
to 3.6.

However, there is nothing stopping either you or a downstream supplier of 
Python 3.6 (like RedHat) from backporting it yourselves.

https://devguide.python.org/devcycle/#security-branches

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