[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Greg Ewing
On 27/04/22 11:07 am, Chris Angelico wrote: You're saying that it's somehow different when the original dev intends for it, and that that makes it "not monkeypatching". I dispute that, and I consider that the feature would be helpful whether the original dev meant for it or not. The forward

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Rob Cliffe via Python-Dev
On 26/04/2022 20:48, Carl Meyer via Python-Dev wrote: On Tue, Apr 26, 2022 at 1:25 PM Guido van Rossum wrote: I also would like to hear more about the problem this is trying to solve, when th real-world examples. (E.g. from pydantic?) Yes please. I think these threads have jumped far too

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Carl Meyer via Python-Dev
On Tue, Apr 26, 2022 at 7:24 PM Greg Ewing wrote: > On 27/04/22 2:01 am, Chris Angelico wrote: > > That would be the case if monkeypatching were illegal. Since it's not, > > wherein lies the difference? > > The proposed feature is analogous to forward declaring a > struct in C. Would you call

[Python-Dev] Re: Reminder: PEP 479's __future__ about to become the default behavior

2022-04-26 Thread tổng vương
___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Steven D'Aprano
On Mon, Apr 25, 2022 at 10:32:15PM -0700, Larry Hastings wrote: [...] > Whichever spelling we use here, the key idea is that C is bound to a > "ForwardClass" object.  A "ForwardClass" object is /not/ a class, it's a > forward declaration of a class.  (I suspect ForwardClass is similar to a >

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Chris Angelico
On Wed, 27 Apr 2022 at 11:18, Greg Ewing wrote: > > On 27/04/22 2:01 am, Chris Angelico wrote: > > That would be the case if monkeypatching were illegal. Since it's not, > > wherein lies the difference? > > The proposed feature is analogous to forward declaring a > struct in C. Would you call

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Greg Ewing
On 27/04/22 2:01 am, Chris Angelico wrote: That would be the case if monkeypatching were illegal. Since it's not, wherein lies the difference? The proposed feature is analogous to forward declaring a struct in C. Would you call what C does monkeypatching? -- Greg

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Chris Angelico
On Wed, 27 Apr 2022 at 08:06, Greg Ewing wrote: > > On 27/04/22 1:04 am, Joao S. O. Bueno wrote: > > MonkeyPatching in Python is not illegal in this sense. > > I'm not suggesting it is. You're seizing on the wrong part > of the analogy. The point is that what you call something > doesn't change

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Greg Ewing
On 27/04/22 1:04 am, Joao S. O. Bueno wrote: MonkeyPatching in Python is not illegal in this sense. I'm not suggesting it is. You're seizing on the wrong part of the analogy. The point is that what you call something doesn't change its nature. -- Greg

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Victor Stinner
The only purpose of proposed -P option is to "not add sys.path[0]". There are use cases which only need that. Victor On Tue, Apr 26, 2022 at 8:37 PM Steve Dower wrote: > > On 4/26/2022 10:46 AM, Victor Stinner wrote: > > I propose adding a -P option to Python command line interface to "not > >

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Carl Meyer via Python-Dev
On Tue, Apr 26, 2022 at 1:25 PM Guido van Rossum wrote: > I also would like to hear more about the problem this is trying to solve, > when th real-world examples. (E.g. from pydantic?) Yes please. I think these threads have jumped far too quickly into esoteric details of implementation and

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Thomas Kehrenberg
Apr 26, 2022 20:32:55 Eric V. Smith : How would runtime consumers of annotations use this? -- Eric On Apr 26, 2022, at 12:05 PM, Thomas Kehrenberg wrote: If the problem is mostly type annotations, then another potential solution would be to make use of .pyi files, which are not

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Eric V. Smith
> On Apr 26, 2022, at 3:05 PM, Thomas Kehrenberg wrote: > >  > Apr 26, 2022 20:32:55 Eric V. Smith : > >> How would runtime consumers of annotations use this? >> >> -- >> Eric >> On Apr 26, 2022, at 12:05 PM, Thomas Kehrenberg wrote: >>> >>> If the problem is mostly type

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Chris Angelico
On Wed, 27 Apr 2022 at 05:05, Larry Hastings wrote: > > > On 4/26/22 09:31, MRAB wrote: >> Perhaps: >> >>class C: ... > > Also, your suggestion is already legal Python syntax; it creates a class with > no attributes. So changing this existing statement to mean something else > would

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Guido van Rossum
I am traveling and have no keyboard right now, but it looks like this thread is confusing the slots that a type gives to its *instances* and extra slots in the type object itself. Only the latter are a problem. I also would like to hear more about the problem this is trying to solve, when th

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Ronald Oussoren via Python-Dev
> On 26 Apr 2022, at 20:52, Larry Hastings wrote: > > > > On 4/25/22 23:56, Ronald Oussoren wrote: >> A problem with this trick is that you don’t know how large a class object >> can get because a subclass of type might add new slots. This is currently >> not possible to do in Python code

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Larry Hastings
On 4/26/22 09:31, MRAB wrote: On 2022-04-26 06:32, Larry Hastings wrote: Note that this spelling is also viable:     class C I don't like that because it looks like you've just forgotten the colon. Perhaps:     class C: ... That's not a good idea.  Every other place in Python where

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Larry Hastings
On 4/25/22 23:56, Ronald Oussoren wrote: A problem with this trick is that you don’t know how large a class object can get because a subclass of type might add new slots. This is currently not possible to do in Python code (non-empty ``__slots__`` in a type subclass is rejected at runtime),

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Steve Dower
On 4/26/2022 10:46 AM, Victor Stinner wrote: I propose adding a -P option to Python command line interface to "not add sys.path[0]": https://github.com/python/cpython/pull/31542 See the documentation in the PR for the exact behavior of this option. I prefer to add an environment variable, only

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Eric V. Smith
How would runtime consumers of annotations use this? -- Eric > On Apr 26, 2022, at 12:05 PM, Thomas Kehrenberg wrote: > > If the problem is mostly type annotations, then another potential > solution would be to make use of .pyi files, which are not hamstrung by > circular definitions. The

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Barry Warsaw
On Apr 25, 2022, at 22:32, Larry Hastings wrote: > The general shape of it is the same. First, we have some sort of forward > declaration of the class. I'm going to spell it like this: > > forward class C > > just for clarity in the discussion. Note that this spelling is also viable: > >

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Brett Cannon
On Tue, Apr 26, 2022 at 2:50 AM Victor Stinner wrote: > Hi, > > There are 4 main ways to run Python: > > (1) python -m module [...] > (2) python script.py [...] > (3) python -c code [...] > (4) python [...] > > (1) and (2) insert the directory of the module/script at sys.path[0]. > (3) and (4)

[Python-Dev] New functionality for unittest.mock side_effect

2022-04-26 Thread Roy Smith
I often want a side_effect of "if called with foo, return bar" functionality. This is really useful when the order of calls to your mock is indeterminate, so you can't just use an iterable. What I end up doing is writing a little function: def f(x): data = { 'foo':

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread MRAB
On 2022-04-26 06:32, Larry Hastings wrote: Sorry, folks, but I've been busy the last few days--the Language Summit is Wednesday, and I had to pack and get myself to SLC for PyCon, I'll circle back and read the messages on the existing threads tomorrow.  But for now I wanted to post "the

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Eryk Sun
On 4/26/22, Victor Stinner wrote: > > There are 4 main ways to run Python: > > (1) python -m module [...] > (2) python script.py [...] > (3) python -c code [...] > (4) python [...] > > (1) and (2) insert the directory of the module/script at sys.path[0]. Running a module with -m inserts the

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Thomas Kehrenberg
If the problem is mostly type annotations, then another potential solution would be to make use of .pyi files, which are not hamstrung by circular definitions. The idea would be that type checkers would merge the annotations from .pyi files into the annotations in the corresponding .py file. So:

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Ronald Oussoren via Python-Dev
> On 26 Apr 2022, at 07:32, Larry Hastings wrote: > > […] > What could go wrong? My biggest question so far: is there such a thing as a > metaclass written in C, besides type itself? Are there metaclasses with a > __new__ that doesn't call super().__new__ or three-argument type? If there

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Chris Angelico
On Tue, 26 Apr 2022 at 22:56, Greg Ewing wrote: > > On 26/04/22 12:33 pm, Chris Angelico wrote: > > That's exactly what I mean though: if the only difference between > > "monkeypatching" and "not monkeypatching" is whether it was intended, > > then the only difference is what you call it. > > No,

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Joao S. O. Bueno
On Tue, Apr 26, 2022 at 4:04 AM wrote: > Larry Hastings wrote: > > [...] > > > > Now comes the one thing that we might call a "trick". The trick: when > > we allocate the ForwardClass instance C, we make it as big as a class > > object can ever get. (Mark Shannon assures me this is simply

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Joao S. O. Bueno
On Tue, Apr 26, 2022 at 9:55 AM Greg Ewing wrote: > On 26/04/22 12:33 pm, Chris Angelico wrote: > > That's exactly what I mean though: if the only difference between > > "monkeypatching" and "not monkeypatching" is whether it was intended, > > then the only difference is what you call it. > >

[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022-04-26 Thread Greg Ewing
On 26/04/22 12:33 pm, Chris Angelico wrote: That's exactly what I mean though: if the only difference between "monkeypatching" and "not monkeypatching" is whether it was intended, then the only difference is what you call it. No, it's not just a matter of what you call it. If I lose my keys

[Python-Dev] Re: Proposal to deprecate mailcap

2022-04-26 Thread Damian Shaw
I didn't spot anyone else report this to mitmproxy so I raised an issue to make them aware: https://github.com/mitmproxy/mitmproxy/issues/5297 On Tue, Apr 26, 2022 at 3:30 AM Victor Stinner wrote: > On Tue, Apr 26, 2022 at 5:47 AM Brett Cannon wrote: > > After talking about this in the SC

[Python-Dev] Add -P command line option to not add sys.path[0]

2022-04-26 Thread Victor Stinner
Hi, There are 4 main ways to run Python: (1) python -m module [...] (2) python script.py [...] (3) python -c code [...] (4) python [...] (1) and (2) insert the directory of the module/script at sys.path[0]. (3) and (4) insert an empty string at sys.path[0]. This behavior is convenient and is

[Python-Dev] Re: Proposal to deprecate mailcap

2022-04-26 Thread Victor Stinner
On Tue, Apr 26, 2022 at 5:47 AM Brett Cannon wrote: > After talking about this in the SC today, we agreed to deprecate mailcap > under the auspices of PEP 594: > https://github.com/python/peps/commit/701999a91dc5f976c00d5bde1510226ebd9c7822 > . Good. I proposed

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread Ronald Oussoren via Python-Dev
> On 26 Apr 2022, at 07:32, Larry Hastings wrote: > > [… snip …] > Next we have the "continue" class statement. I'm going to spell it like this: > > continue class C(BaseClass, ..., metaclass=MyMetaclass): > # class body goes here > ... > > I'll mention other possible spellings

[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022-04-26 Thread dw-git
Larry Hastings wrote: > [...] > > Now comes the one thing that we might call a "trick".  The trick: when > we allocate the ForwardClass instance C, we make it as big as a class > object can ever get.  (Mark Shannon assures me this is simply "heap > type", and he knows far more about CPython