[Python-ideas] Re: contextlib.redirect_stdio function

2022-05-02 Thread sam . z . ezeh
sam.z.ezeh@gmail.com wrote: > I've now created a GitHub issue [2] and a draft PR [3] for > contextlib.redirect_stdin. To provide an update, contextlib.redirect_stdin isn't happening [1] [1]: https://github.com/python/cpython/issues/92178#issuecomment-1115486367

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Joao S. O. Bueno
Anyway, there is something dataclasses do today that prevent you from jsut adding a @dataclass for binding __init__ attributes from an otherwise "complete class that does things": it overwrites __init__ itself - one hass to resort to write "__post_init__" instead,¨ That means that if some class

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Christopher Barker
On Mon, May 2, 2022 at 7:42 PM Steven D'Aprano wrote: > On Sun, May 01, 2022 at 10:40:49PM -0700, Christopher Barker wrote: > > > Yes, any class could use this feature (though it's more limited than > what > > dataclasses do) -- what I was getting is is that it would not be > > (particularly)

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Steven D'Aprano
On Sun, May 01, 2022 at 10:40:49PM -0700, Christopher Barker wrote: > Yes, any class could use this feature (though it's more limited than what > dataclasses do) -- what I was getting is is that it would not be > (particularly) useful for all classes -- only classes where there are a lot > of

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 07:44:14PM +0100, Paul Moore wrote: > I have classes with 20+ parameters (packaging metadata). You can argue > that a dataclass would be better, or some other form of refactoring, > and you may actually be right. But it is a legitimate design for that > use case. Indeed.

[Python-ideas] Re: infile and outfile parameters for the input function

2022-05-02 Thread Chris Angelico
On Tue, 3 May 2022 at 11:14, Steven D'Aprano wrote: > > On Mon, May 02, 2022 at 07:55:16PM -, sam.z.e...@gmail.com wrote: > > > Using the prospective redirect_stdin context manager, the following code > > > > ``` > > with open("/dev/tty", 'r+') as file: > > with

[Python-ideas] Re: infile and outfile parameters for the input function

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 07:55:16PM -, sam.z.e...@gmail.com wrote: > Using the prospective redirect_stdin context manager, the following code > > ``` > with open("/dev/tty", 'r+') as file: > with contextlib.redirect_stdin(file), contextlib.redirect_stdout(file): > name =

[Python-ideas] Re: infile and outfile parameters for the input function

2022-05-02 Thread Chris Angelico
On Tue, 3 May 2022 at 05:56, wrote: > > > (Plus not-yet-existing, but hopefully soon, redirect_stdin.) > Mentioned on the redirect_stdio thread, I've now created a GitHub issue and > PR for contextlib.redirect_stdin. > > I think I want to see some examples of how and why you would use it, and >

[Python-ideas] Re: infile and outfile parameters for the input function

2022-05-02 Thread sam . z . ezeh
> (Plus not-yet-existing, but hopefully soon, redirect_stdin.) Mentioned on the redirect_stdio thread, I've now created a GitHub issue and PR for contextlib.redirect_stdin. > I think I want to see some examples of how and why you would use it, and > why one couldn't just use the redirect_stdout

[Python-ideas] Re: contextlib.redirect_stdio function

2022-05-02 Thread sam . z . ezeh
> (2) I don't see `redirect_stdio(stout=None ...)` as meaning "leave > stdout alone". I see it as equivalent to some variation of unsetting > stdout, say setting it to /dev/null. This makes sense, perhaps None could be an alias for a stream created from os.devnull [1]. Then the default

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Paul Moore
On Mon, 2 May 2022 at 18:46, Steven D'Aprano wrote: > > But **not once** when I have read that same method later on have I > regretted that those assignments are explicitly written out, or wished > that they were implicit and invisible. I have classes with 20+ parameters (packaging metadata).

[Python-ideas] Re: infile and outfile parameters for the input function

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 05:42:12PM -, sam.z.e...@gmail.com wrote: > input(prompt=None, /, infile=None, outfile=None) > What do people think about this? I think I want to see some examples of how and why you would use it, and why one couldn't just use the redirect_stdout context manager.

[Python-ideas] Re: contextlib.redirect_stdio function

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 05:29:56PM -, sam.z.e...@gmail.com wrote: > > There's already contextlib.redirect_stdout() and > > contextlib.redirect_stderr(). Adding contextlib.redirect_stdin() would > > be logical, but I think a more flexible > > > > contextlib.redirect_stdio(stdin=None,

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 10:34:56AM -0600, Pablo Alcain wrote: > For what it's worth, > the choice of the `@` was because of two different reasons: first, because > we were inspired by Ruby's syntax (later on learned that CoffeeScript and > Crystal had already taken the approach we are proposing)

[Python-ideas] infile and outfile parameters for the input function

2022-05-02 Thread sam . z . ezeh
Previously discussed here [1] [2], it was raised that the input function could take file objects to display prompts in places other than sys.stdout and receive input from places other than sys.stdin. Locally, the patch I have produces the following help text: ``` Help on built-in function

[Python-ideas] contextlib.redirect_stdio function

2022-05-02 Thread sam . z . ezeh
Previously raised here [1], contextlib.redirect_stdio would be a utility function to help redirect standard input, output and error. The idea of a function called "stdio" that does the same thing was also raised. The function would combine the functionality of contextlib.redirect_stdout and

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Pablo Alcain
On Mon, May 2, 2022 at 7:21 AM Steven D'Aprano wrote: > On Sun, May 01, 2022 at 06:22:08PM -0700, Devin Jeanpierre wrote: > > > Is it unreasonable to instead suggest generalizing the assignment target > > for parameters? For example, if parameter assignment happened left to > > right, and

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Pablo Alcain
On Sun, May 1, 2022 at 10:35 AM Ethan Furman wrote: > On 5/1/22 00:21, Christopher Barker wrote: > > On Sat, Apr 30, 2022 at 2:17 PM Pablo Alcain wrote: > > > >> It shows that out of 20k analyzed classes in the selected libraries > (including black, > >> pandas, numpy, etc), ~17% of them

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 05:57:45PM +0900, Stephen J. Turnbull wrote: > def __init__(s, s.x, s.y): pass I think that if this proposal threatens to encourage people to write that horro, that would be enough of a reason to reject it. -- Steve ___

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Steven D'Aprano
On Sun, May 01, 2022 at 06:22:08PM -0700, Devin Jeanpierre wrote: > Is it unreasonable to instead suggest generalizing the assignment target > for parameters? For example, if parameter assignment happened left to > right, and allowed more than just variables, then one could do: > > def

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Steven D'Aprano
On Mon, May 02, 2022 at 09:58:35AM +0200, Marc-Andre Lemburg wrote: > Just a word of warning: numeric bases are not necessarily the same > as numeric encodings. The latter usually come with other formatting > criteria in addition to representing numeric values, e.g. base64 is > an encoding and

[Python-ideas] Re: Auto assignment of attributes

2022-05-02 Thread Stephen J. Turnbull
Devin Jeanpierre writes: > Is it unreasonable to instead suggest generalizing the assignment target > for parameters? For example, if parameter assignment happened left to > right, and allowed more than just variables, then one could do: > > def __init__(self, self.x, self.y): pass At a

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Chris Angelico
On Mon, 2 May 2022 at 17:58, Marc-Andre Lemburg wrote: > > On 02.05.2022 08:54, Chris Angelico wrote: > > On Mon, 2 May 2022 at 16:46, Serhiy Storchaka wrote: > >> > >> 02.05.22 08:03, Chris Angelico пише: > >>> Let's not go as far as a PEP yet, and figure out a couple of things: > >> > >> A PEP

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Marc-Andre Lemburg
On 02.05.2022 08:54, Chris Angelico wrote: > On Mon, 2 May 2022 at 16:46, Serhiy Storchaka wrote: >> >> 02.05.22 08:03, Chris Angelico пише: >>> Let's not go as far as a PEP yet, and figure out a couple of things: >> >> A PEP is necessary if we add Roman numerals and Cyrillic numerals, and >>

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Chris Angelico
On Mon, 2 May 2022 at 16:46, Serhiy Storchaka wrote: > > 02.05.22 08:03, Chris Angelico пише: > > Let's not go as far as a PEP yet, and figure out a couple of things: > > A PEP is necessary if we add Roman numerals and Cyrillic numerals, and > Babylonian cuneiform numerals to the heap. > I'm

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Chris Angelico
On Mon, 2 May 2022 at 16:37, Simon de Vlieger wrote: > > On Mon, May 2, 2022, at 7:03 AM, Chris Angelico wrote: > > The "alternate alphabet" case can be done by base converting and then > > replacing on the string. It's not the smoothest, so that counts a bit > > of clunkiness; but it's also not

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Serhiy Storchaka
02.05.22 08:03, Chris Angelico пише: Let's not go as far as a PEP yet, and figure out a couple of things: A PEP is necessary if we add Roman numerals and Cyrillic numerals, and Babylonian cuneiform numerals to the heap. ___ Python-ideas mailing

[Python-ideas] Re: int.to_base, int.from_base

2022-05-02 Thread Simon de Vlieger
On Mon, May 2, 2022, at 7:03 AM, Chris Angelico wrote: > The "alternate alphabet" case can be done by base converting and then > replacing on the string. It's not the smoothest, so that counts a bit > of clunkiness; but it's also not all THAT common (I can recall doing > it for SteamGuard 2FA