[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Steven D'Aprano
On Mon, Dec 28, 2020 at 11:36:55PM -0800, Christopher Barker wrote: > Side Question: when should one use __dict__ vs vars() vs getattr() ??? all > three work in this case, but I'm never quite sure which is prefered, and > why. `vars(obj)` is defined as returning `obj.__dict__` so technically it

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Guido van Rossum
On Tue, Dec 29, 2020 at 8:11 AM Steven D'Aprano wrote: > On Mon, Dec 28, 2020 at 11:36:55PM -0800, Christopher Barker wrote: > > > Side Question: when should one use __dict__ vs vars() vs getattr() ??? > all > > three work in this case, but I'm never quite sure which is prefered, and > > why. > >

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Anton Abrosimov
So, I’m ready to admit that I was mistaken in considering `**` as an operator. Therefore, my further reasoning and suggestions were not correct. If I had the right to vote, I would vote for `dict.update()` like behaviour. Thanks for your attention and clarification. I think it is worth creating a

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Guido van Rossum
On Mon, Dec 28, 2020 at 11:36 PM Christopher Barker wrote: > On Mon, Dec 28, 2020 at 12:33 PM Guido van Rossum > wrote: > >> On Mon, Dec 28, 2020 at 12:15 PM Christopher Barker >> wrote: >> >>> Though frankly, I would rather have had it use .items() -- seems more >>> efficient to me, and you do

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Brendan Barnwell
On 2020-12-29 10:30, Guido van Rossum wrote: I don't understand why LBYL is considered such an anti-pattern. It helps produce much clearer error messages in this case for users who are exploring this feature, and distinguishing *early* between sequences and mappings is important for that. Long ag

[Python-ideas] Right way to dataclass -> dict conversion.

2020-12-29 Thread Anton Abrosimov
Example task: ``` from dataclasses import dataclass, asdict, fields from typing import List @dataclass class Point: x: int y: int @dataclass class Axes: title: str points: List[Point] def plot(title: str, points: List[Point]): print(title) for point in points: pr

[Python-ideas] Re: Right way to dataclass -> dict conversion.

2020-12-29 Thread Anton Abrosimov
Way 5: Add default `False` `iter` flag to `dataclass` decorator. ``` def __iter__(self) : return ((f.name, getattr(axes, f.name)) for f in fields(axes)) ``` And use: `plot(**dict(axes))` ___ Python-ideas mailing list -- python-ideas@python.org

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Christopher Barker
On Tue, Dec 29, 2020 at 11:18 AM Brendan Barnwell wrote: > On 2020-12-29 10:30, Guido van Rossum wrote: > > Long ago we decided that the distinctive > > feature is that mappings have a `keys()` method whereas sequences don't > It seems the real issue here is one of documentation. Exac

[Python-ideas] Option to not raise if file does not exists for os.remove()?

2020-12-29 Thread Marco Sulla
What about a parameter, false by default, that suppresses the FileNotFoundError exception if true for os.remove()? Something similar to exist_ok for os.makedirs(). ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to py

[Python-ideas] Re: Option to not raise if file does not exists for os.remove()?

2020-12-29 Thread Serhiy Storchaka
29.12.20 22:58, Marco Sulla пише: > What about a parameter, false by default, that suppresses the > FileNotFoundError exception if true for os.remove()? Something similar > to exist_ok for os.makedirs(). You have two options (and it's too much in my opinion): try: os.remove(filename)

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Christopher Barker
On Tue, Dec 29, 2020 at 10:30 AM Guido van Rossum wrote: > Interesting -- thanks for taking up the challenge. I still suspect that if > we ran the corresponding benchmark at the C level, the first form would win, > I was thinking that might be the case -- but either way, there is little differen

[Python-ideas] Re: Option to not raise if file does not exists for os.remove()?

2020-12-29 Thread Eelke van den Bos
Hi Sergio, The pathlib module includes this feature: https://docs.python.org/3/library/pathlib.html#pathlib.Path.unlink Best, Eelke On Tue, Dec 29, 2020, 22:12 Serhiy Storchaka wrote: > 29.12.20 22:58, Marco Sulla пише: > > What about a parameter, false by default, that suppresses the > > Fil

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Brendan Barnwell
On 2020-12-29 12:44, Christopher Barker wrote: On Tue, Dec 29, 2020 at 11:18 AM Brendan Barnwell mailto:brenb...@brenbarn.net>> wrote: On 2020-12-29 10:30, Guido van Rossum wrote: > Long ago we decided that the distinctive > feature is that mappings have a `keys()` method whereas

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Chris Angelico
On Wed, Dec 30, 2020 at 8:49 AM Brendan Barnwell wrote: > To my mind, every time a change is made to Python behavior there must > be a corresponding change to the main documentation describing the > change. I would go so far as to say that the lack of such documentation > updates should b

[Python-ideas] Re: built in to clear terminal

2020-12-29 Thread Mike Miller
On 2020-12-28 23:33, Stephen J. Turnbull wrote: The thing is, this is a destructive capability. In some cases it only clears the "screen" (whatever that means), which may cost you some diagnostics. Probably (but not always) you can recreate them by repeating a command from history. But in so

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Christopher Barker
On Tue, Dec 29, 2020 at 1:51 PM Brendan Barnwell wrote: > > they all overlap a bit in purpose. And "protocols" seem to be the least > > clearly specified. Indeed, the "iteration protocol" is well known and > > talked about, but not well documented in the standard docs: > > No offense to a

[Python-ideas] Re: built in to clear terminal

2020-12-29 Thread Chris Angelico
On Wed, Dec 30, 2020 at 9:57 AM Mike Miller wrote: > Also, I'd argue the likelihood of a newbie clearing important work... is not > very high. > Disputed on the basis of having seen it all too often :) ChrisA ___ Python-ideas mailing list -- python-id

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Brendan Barnwell
On 2020-12-29 13:54, Chris Angelico wrote: Documentation bugs are bugs to be fixed, just like any other. Rather than complaining that this should have prevented the feature from being released, just propose an improvement. Where should this be documented? How should it be worded? Well, I did p

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Steven D'Aprano
On Tue, Dec 29, 2020 at 10:30:16AM -0800, Guido van Rossum wrote: [Christopher] > > Does there need to be a single defined "protocol" for a mapping (other > > than the ABC)? -- that is, would **unpacking be able to use .items() and > > keys() be used in other contexts? Yes, I think there should b

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Steven D'Aprano
On Tue, Dec 29, 2020 at 02:20:05PM -0800, Brendan Barnwell wrote: > So, to give an example, the iterator protocol should be documented > right where the `for` statement is documented, and it should be > explicitly framed as "this is the definition of what the `for` statement > does", not

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Greg Ewing
On 30/12/20 9:44 am, Christopher Barker wrote: So there are dunders, and protocols, and ABCs, and they all overlap a bit in purpose. And "protocols" seem to be the least clearly specified. > there are various protocols described in the C API docs, including > the Mapping protocol: > > https://

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Greg Ewing
On 30/12/20 11:20 am, Brendan Barnwell wrote: So, to give an example, the iterator protocol should be documented right where the `for` statement is documented, and it should be explicitly framed as "this is the definition of what the `for` statement does", Not sure about that -- there ar

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Brendan Barnwell
On 2020-12-29 16:18, Steven D'Aprano wrote: On Tue, Dec 29, 2020 at 02:20:05PM -0800, Brendan Barnwell wrote: So, to give an example, the iterator protocol should be documented right where the `for` statement is documented, and it should be explicitly framed as "this is the definition o

[Python-ideas] Re: built in to clear terminal

2020-12-29 Thread Mike Miller
On 2020-12-29 15:07, Chris Angelico wrote: On Wed, Dec 30, 2020 at 9:57 AM Mike Miller wrote: Also, I'd argue the likelihood of a newbie clearing important work... is not very high. Disputed on the basis of having seen it all too often :) Note, I added the word *important* on purpose.