[Python-ideas] Re: Abstract dataclasses and dataclass fields

2023-12-22 Thread Eric V. Smith via Python-ideas
On 12/21/2023 4:38 PM, Steve Jorgensen wrote: I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract. As I am typing this, I realize that I could presumably write some code to implement what I'm asking for.

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Eric V. Smith via Python-ideas
On 10/21/2023 8:31 PM, Chris Angelico wrote: On Sun, 22 Oct 2023 at 11:29, MRAB wrote: I think what the OP wants is to have re.match either return a match or raise an exception. Yes, and my point is that simply attempting to access an attribute will do exactly that. It's not a silent failure.

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Eric V. Smith via Python-ideas
On Sep 23, 2023, at 5:37 PM, Dom Grigonis wrote:It seems that my guess was correct. There was a commit, when only the first part was working:https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d23cfc52b5e07e4381aSince I wrote that commit: no one is saying it’s impossible

[Python-ideas] Re: [dataclasses] add a NON_FIELDS sentinel after which all attributes are ignored.

2023-06-23 Thread Eric V. Smith via Python-ideas
On 6/23/2023 11:34 AM, Joao S. O. Bueno wrote: On Fri, Jun 23, 2023 at 12:18 PM Eric V. Smith wrote:  On Jun 23, 2023, at 9:34 AM, Joao S. O. Bueno wrote:  On Fri, Jun 23, 2023 at 2:35 AM Jelle Zijlstra wrote: El jue, 22 jun 2023 a las 8:22, Randolf

[Python-ideas] Re: [dataclasses] add a NON_FIELDS sentinel after which all attributes are ignored.

2023-06-23 Thread Eric V. Smith via Python-ideas
On Jun 23, 2023, at 9:34 AM, Joao S. O. Bueno wrote:On Fri, Jun 23, 2023 at 2:35 AM Jelle Zijlstra wrote:El jue, 22 jun 2023 a las 8:22, Randolf Scholz () escribió:Dataclasses should provide a way to ignore a type hinted attributes, and not

[Python-ideas] Re: Deprecate misleading escapes in strings

2023-02-16 Thread Eric V. Smith via Python-ideas
You should bring this up on https://discuss.python.org/c/ideas/6 , which is where ideas are discussed these days. This mailing list should be retired. I’ll mention that elsewhere. -- Eric > On Feb 16, 2023, at 9:57 AM, Arusekk wrote: > > Hi all! > > I was writing a tutorial on the

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-22 Thread Eric V. Smith via Python-ideas
Jim Baker's draft PEP gives runtime behavior to tagged strings. I agree it would all be pointless if it's just hints to an editor. Sorry, I again don't have a handy link to his PEP. But it's similar in spirit to PEP 501. Eric On 12/22/2022 2:36 PM, Joao S. O. Bueno wrote: I am not

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-17 Thread Eric V. Smith via Python-ideas
Jim Baker has been working on tagged strings, and Guido has a working implementation. See https://github.com/jimbaker/tagstr/issues/1 I thought Jim had a draft PEP on this somewhere, but I can’t find it. -- Eric > On Dec 17, 2022, at 11:14 AM, e...@emilstenstrom.se wrote: > > Hi everyone! >

[Python-ideas] Re: Allow more flexibility for describing bytes objects.

2022-11-23 Thread Eric V. Smith via Python-ideas
On 11/23/2022 3:02 PM, Chris Angelico wrote: On Thu, 24 Nov 2022 at 06:46, Barry Scott wrote: I have written a lot of low level protocol and IOCTL calls that cannot think of a time this would have helped me. struct is often a mean to create blocks of binary data. Long strings of binary data

[Python-ideas] Re: Void type

2022-07-27 Thread Eric V. Smith via Python-ideas
Sorry for top posting: I’m on the road. inspect.signature can help with this. -- Eric > On Jul 27, 2022, at 9:22 AM, Chris Angelico wrote: > > On Wed, 27 Jul 2022 at 22:54, Mathew Elman wrote: >> >> Chris Angelico wrote: Again, I am not pro this idea, just answering the questions

[Python-ideas] Re: Generalized deferred computation in Python

2022-06-22 Thread Eric V. Smith via Python-ideas
> On Jun 22, 2022, at 2:12 PM, Paul Moore wrote: > > On Wed, 22 Jun 2022 at 18:35, David Mertz, Ph.D. > wrote: >> >> Hi Martin, >> >> Short answer: yes, I agree. >> Slightly longer: I would be eternally grateful if you wish to contribute to >> the PEP with any such expansion of the

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-18 Thread Eric V. Smith via Python-ideas
On 6/18/2022 5:34 PM, Paul Moore wrote: After all, it has the advantage of working on older versions of Python (and given that one of your use cases is Textual, I can't imagine anyone would be happy if that required Python 2.12+...) Guido's "no 2.8" shirt apparently didn't stop 2.9 through

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-17 Thread Eric V. Smith via Python-ideas
On 6/17/2022 10:53 AM, Chris Angelico wrote: The only two possible behaviours are: 1) It does the single obvious thing: n defaults to the length of items, and items defaults to an empty tuple. 2) It raises UnboundLocalError if you omit n. ... Would you prefer that I simply mandate that it be

[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Eric V. Smith via Python-ideas
On 6/7/2022 4:59 PM, Chris Angelico wrote: On Wed, 8 Jun 2022 at 00:36, wrote: Hello! Do you know if there has been discussions around why is the default argument is positional only in the dict methods get and pop? I think ``` d.get(key, default=3) ``` way more readable than ```

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread Eric V. Smith via Python-ideas
On 6/5/2022 1:22 PM, Benedict Verhegghe wrote: Op 5/06/2022 om 18:47 schreef David Mertz, Ph.D.: Sure, that's nice enough code and has the same big-O complexity. I suspect set difference is a little faster (by a constant multiple) because it hits C code more, but I haven't benchmarked. The

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-06-01 Thread Eric V. Smith
On 6/1/2022 9:59 AM, Chris Angelico wrote: On Wed, 1 Jun 2022 at 23:55, Serhiy Storchaka wrote: 31.05.22 16:21, Chris Angelico пише: On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas wrote: After getting used to writing async functions, I’ve been wanting use a similar syntax to

[Python-ideas] Re: Improving -x switch on CLI interface

2022-05-15 Thread Eric V. Smith
Hi, Rafael. Can you give a use case where you’d find this helpful? Thanks. -- Eric > On May 14, 2022, at 1:15 PM, Rafael Nunes wrote: > >  > Hi. > What about improving the -x switch by passing the number of lines to ignore? > Ex: -x (default=1 line) > -x n (Python will ignore first n

[Python-ideas] Re: Auto assignment of attributes

2022-05-04 Thread Eric V. Smith
On 5/4/2022 1:19 PM, Paul Moore wrote: Maybe. But really what I want is a way to say "this is what type the attribute is, but don't assume the init argument is the same type". Or just not bother with all this at all. This is where it starts to just become not worth trying to make dataclasses do

[Python-ideas] Re: Auto assignment of attributes

2022-05-03 Thread Eric V. Smith
Autocarrot! -- Eric > On May 3, 2022, at 8:32 PM, Christopher Barker wrote: > >  > > Sorry - auto-correct is not my friend :-( > > -CHB > >> On Tue, May 3, 2022 at 12:07 PM Ethan Furman wrote: >> On 5/2/22 23:21, Christopher Barker wrote: >> >> > But yes, there are many use cases not

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-13 Thread Eric V. Smith
On 4/13/2022 7:22 AM, malmiteria wrote: Eric V. Smith writes: My suggestion is to rework your proposal to not break any existing code I've been doing that already, and i'll keep doing it, i'm very aware of this constraint. What are the biggest breaking change i haven't covered yet, in your

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-12 Thread Eric V. Smith
On 4/12/2022 12:57 PM, malmiteria wrote: So the amount of actual breakings left shouldn't be enough to justify denying this feature IMO. Again, we'll have a clearer view on that once we get experimental data. What's to look for is usage of super in MI cases, since each super call in MI today

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-12 Thread Eric V. Smith
On 4/12/2022 7:43 AM, malmiteria wrote: Brendan Barnwell writes: You seem to be envisioning a system in which multiple inheritance gives a subclass a "menu" of behaviors from which it may explicitly choose, but does not actually combine the superclasses' behaviors into a single, definite

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-04-06 Thread Eric V. Smith
ut I think that should best be in an external library. Eric On Wed, Mar 30, 2022 at 8:14 AM Eric V. Smith wrote: On 3/30/2022 11:02 AM, Adrian Torres Justo wrote: Fair enough, thanks for the explanation ... There are a lot of ways to interpret "convert to bool&qu

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Eric V. Smith
On 3/30/2022 11:02 AM, Adrian Torres Justo wrote: Fair enough, thanks for the explanation ... There are a lot of ways to interpret "convert to bool" - should "yes" and "no" be converted? What about "1" and "0"? Or "001", or "-1"? What should happen to unrecognised values? What if

[Python-ideas] Re: mro and super don't feel so pythonic

2022-03-27 Thread Eric V. Smith
On 3/26/2022 12:57 PM, malmiteria wrote: what i propose is a solution that would follow those rules: The mro alternative, which i called explicit method resolution aka EMR (which is probably not a good name since i apply it, as mro, to all class attributes), follow those rules : ... 4)

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Eric V. Smith
On 3/23/2022 5:03 PM, mich...@michaelgreen.dev wrote: Back in early 2016 there was an idea submitted[1] by Joseph Martinot-Lagarde in regard to anonymous namedtuples. The crux of the submission was the idea of instantiating a namedtuple using only Python's generic tuple syntax plus keyword

[Python-ideas] Re: Proposal to associate thread-local data/context with a faulthandler traceback

2022-03-06 Thread Eric V. Smith
> On Mar 6, 2022, at 5:05 AM, Barry Scott wrote: > >  > >>> On 6 Mar 2022, at 07:19, t...@tomforb.es wrote: >>> >>> For reference, this request comes from running Dask[1] jobs. Dask handles >>> retrying and tracking tasks across machines but if you're dealing with a >>> batch of inputs

[Python-ideas] Re: Regex pattern matching

2022-02-16 Thread Eric V. Smith
See https://bugs.python.org/issue46692. It's not so easy to make match objects mappings or sequences because of the len() problem. Eric On 2/16/2022 9:46 AM, Valentin Berlier wrote: Hi, I've been thinking that it would be nice if regex match objects could be deconstructed with pattern

[Python-ideas] Re: Missing expandvars equivalent in pathlib

2022-02-12 Thread Eric V. Smith
> On Feb 12, 2022, at 10:54 AM, Chris Angelico wrote: > > On Sun, 13 Feb 2022 at 02:45, Eric V. Smith wrote: >> >> >>> On 2/11/2022 2:01 PM, Paul Moore wrote: >>> On Fri, 11 Feb 2022 at 16:37, Christopher Barker >>> wrote: >&g

[Python-ideas] Re: Missing expandvars equivalent in pathlib

2022-02-12 Thread Eric V. Smith
On 2/11/2022 2:01 PM, Paul Moore wrote: On Fri, 11 Feb 2022 at 16:37, Christopher Barker wrote: On Fri, Feb 11, 2022 at 12:28 AM Serhiy Storchaka wrote: expandvars() does not operate on paths, it operates on strings and bytestrings. There is nothing path-specific here. Expanding environment

[Python-ideas] Re: Missing expandvars equivalent in pathlib

2022-02-11 Thread Eric V. Smith
On 2/11/2022 5:33 PM, Ricky Teachey wrote: On Fri, Feb 11, 2022 at 4:58 PM MRAB wrote: On 2022-02-11 20:05, Ricky Teachey wrote: > Just had a thought kernel: what if there were an f-string mini-language > directive to grab environment variables and expand user paths? That >

[Python-ideas] Re: Mapping unpacking assignment

2022-02-07 Thread Eric V. Smith
> On Feb 7, 2022, at 1:55 AM, Chris Angelico wrote: > … > def spam(): >bird = "Norwegian Blue" >volts = 4e6 >return "{volts}V insufficient to voom {bird}".format(**locals()) This is completely off topic, but: the better way to do this is with .format_map(locals()). This public

[Python-ideas] Re: "frozen" operator Re: Revisiting a frozenset display literal

2022-01-20 Thread Eric V. Smith
See also the rejected PEP 351. -- Eric > On Jan 20, 2022, at 7:21 PM, Cameron Simpson wrote: > > Well, I've just waded through this discussion. > > This all feels to me like a special case of "wanting a constant for > bytecode". What is we had a "freeze" operator, eg: > >|foo| > >

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-12 Thread Eric V. Smith
Thank you for this, Carl. This is an excellent point, and well articulated. I agree it's important. I also agree that this should be addressed in the PEP. If nothing else, it needs to be listed in a "Discussion" section, or similar. I think pointing to your email would be a good start. Eric

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-11 Thread Eric V. Smith
On 12/11/2021 12:11 PM, Chris Angelico wrote: On Sun, Dec 12, 2021 at 4:06 AM Christopher Barker wrote: Here’s a new (not well thought out) idea: @dataclasses.dataclass class A: Input_list: list length: int => len(input_list) So length gets set to a “late bound default expression”

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-11 Thread Eric V. Smith
And my response again, although slightly edited. On 12/11/2021 11:28 AM, Christopher Barker wrote: Sorry, accidentally off-list. Here it is again. On Fri, Dec 10, 2021 at 4:50 PM Christopher Barker wrote: Thanks Eric, this is a great example, thanks. It does raise some questions.

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-10 Thread Eric V. Smith
On 12/9/2021 10:32 AM, Eric V. Smith wrote: On 12/6/2021 1:24 AM, Christopher Barker wrote: But I honestly don’t get it. My idea of a deferred object would be quite different that this, would not be a great replacement for this, and could quite happily co-exist with this idea. Clearly I’m

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-10 Thread Eric V. Smith
On 12/6/2021 1:24 AM, Christopher Barker wrote: On Sun, Dec 5, 2021 at 10:38 AM David Mertz, Ph.D. wrote: I first discussed the idea of a "generalized deferred object/type" on this list at least two years ago, probably more than three (I haven't looked through archives lately

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-08 Thread Eric V. Smith
On 12/8/2021 2:40 PM, Brendan Barnwell wrote: On 2021-12-08 09:59, Chris Angelico wrote: On Thu, Dec 9, 2021 at 4:55 AM Stephen J. Turnbull wrote: But the "good idea" of general deferreds is only marginally relevant to our -1s.  It's those -1s that constitute the main issue for Chris, since

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Eric V. Smith
On 12/2/2021 6:36 PM, Chris Angelico wrote: On Fri, Dec 3, 2021 at 7:54 AM Eric V. Smith wrote: Say I have a function with an early-bound default. I can inspect it and I can change it. One reason to inspect it is so that I can call the function with its default values. This is a form

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Eric V. Smith
On 12/2/2021 2:21 PM, Brendan Barnwell wrote: On 2021-12-02 01:35, Steven D'Aprano wrote: > >4) If "no" to question 1, is there some other spelling or other small > >change that WOULD mean you would use it? (Some examples in the PEP.) > >    No.  As I mentioned in the earlier thread, I don't

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-26 Thread Eric V. Smith
On 11/26/2021 7:36 PM, Greg Ewing wrote: On 27/11/21 11:34 am, Eric V. Smith wrote: Would adding something to the Iterator ABC really also add it to my class Foo? ... As a consequence, there is strong pressure to keep the number of required methods to a minimum. It also means that adding

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-26 Thread Eric V. Smith
On 11/26/2021 1:59 PM, Christopher Barker wrote: Just a note here: On Fri, Nov 26, 2021 at 6:37 AM Raimi bin Karim wrote: to improve readability of chaining lazy functions (map, filter, etc.) for iterables. I think there is a slight misperception here. I've seen the term lazy used

[Python-ideas] Re: Adding pep8-casing-compliant aliases for the entire stdlib

2021-11-11 Thread Eric V. Smith
The cost of having two ways to name things for the indefinite future is too high. Not only would you have to maintain it in the various Python implementations, you'd have to explain why code uses "str" or "Str", or both. The costs of migration are also too high. I personally work on a 20 year

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Eric V. Smith
On 10/30/2021 10:08 PM, Christopher Barker wrote: I'm a bit confused as to why folks are making pronouncements about their support for this PEP before it's even finished, but, oh well. I think it's safe to say people are opposed to the PEP as it current stands, not in it's final, as yet unseen,

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-30 Thread Eric V. Smith
On 10/26/2021 7:38 PM, Rob Cliffe via Python-ideas wrote: PS Can I echo Guido's plea that people don't derail this PEP by trying to shoehorn deferred-evaluation-objects (or whatever you want to call them) into it?  As Chris A says, that's a separate idea and should go into a separate PEP. 

[Python-ideas] Re: PEP 671 proof-of-concept: A less invasive implementation

2021-10-30 Thread Eric V. Smith
On 10/30/2021 10:40 AM, Chris Angelico wrote: And, seeing something in help(fn) largely necessitates that the source code be retained. I don't know of any other way to do it. If you say that the default argument is "len(a)", then that's what help() should say. "from __future__ import

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-26 Thread Eric V. Smith
On 10/26/2021 11:19 AM, Chris Angelico wrote: On Wed, Oct 27, 2021 at 2:05 AM Eric V. Smith wrote: Among my objections to this proposal is introspection: how would that work? The PEP mentions that the text of the expression would be available for introspection, but that doesn't seem very

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-26 Thread Eric V. Smith
Among my objections to this proposal is introspection: how would that work? The PEP mentions that the text of the expression would be available for introspection, but that doesn't seem very useful. At the very least, the PEP needs to talk about inspect.Signature objects, and how they would

[Python-ideas] Re: Fwd: Simple curl/wget-like download functionality in urllib (like http offers server)

2021-10-25 Thread Eric V. Smith
On 10/25/2021 11:21 AM, Tom Pohl wrote: Thanks. Not as catchy as I would have hoped, though. ;-) When you respond to a message, could you keep a little of the context that you're replying to? I'm not sure what this refers to. One person except me in favor of this idea. Any other feedback? How

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-25 Thread Eric V. Smith
On 10/25/2021 8:26 AM, Chris Angelico wrote: If it's done with syntax, it can have special behaviour. If it looks like a function call (or class constructor), it doesn't look like it has special behaviour. This has been mentioned before, but I'll say it again: It doesn't need to be syntax in

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Eric V. Smith
> On Oct 17, 2021, at 3:40 AM, Serhiy Storchaka wrote: > > 16.10.21 17:07, Erik Demaine пише: >> (*it for it in its) # tuple with the concatenation of iterables in 'its' > > As others already have said, it should evaluate to a generator, not to a > tuple. > > But other question is occurred

[Python-ideas] Re: dict_items.__getitem__?

2021-10-06 Thread Eric V. Smith
> On Oct 6, 2021, at 10:53 AM, Finn Mason wrote: > >  > I'm not a huge fan. Sure, dicts are ordered now, but I doubt that many people > use that feature. I honestly still think of them as unordered ;) > There’s tons of code that relies on dicts being ordered. Some just don’t know it. For

[Python-ideas] Re: Syntax Sugar for __name__ == "__main__" boilerplate?

2021-10-02 Thread Eric V. Smith
See the rejected PEP 299 for a previous version of this idea: https://www.python.org/dev/peps/pep-0299/ And a discussion on python-dev: https://mail.python.org/pipermail/python-dev/2006-March/062951.html Eric On 10/1/2021 3:38 PM, Paul Bryan wrote: How about the following? def __main__():

[Python-ideas] Re: Allow dataclasses's auto-generated __init__ to optionally accept **kwargs and pass them to __post_init_

2021-09-20 Thread Eric V. Smith
In 3.10 you can specify keyword-only arguments to dataclasses. See https://docs.python.org/3.10/library/dataclasses.html, search for kw_only. This doesn't address Thomas's issue in any way, but I thought I'd mention it. Eric On 9/20/2021 3:36 PM, Paul Bryan wrote: I'm in favour of

[Python-ideas] Re: Allow dataclasses's auto-generated __init__ to optionally accept **kwargs and pass them to __post_init_

2021-09-20 Thread Eric V. Smith
You could write your own decorator to add this functionality for you. Something like: --- from dataclasses import dataclass def add_kw(cls):     original_init = cls.__init__     def new_init(self, x, y, **kwargs):     print('init called with additional

[Python-ideas] Re: os.workdir() context manager

2021-09-15 Thread Eric V. Smith
On 9/15/2021 2:48 PM, Eric Fahlgren wrote: On Wed, Sep 15, 2021 at 12:21 AM Eric V. Smith <mailto:e...@trueblade.com>> wrote: And I'm not crazy about the name "workdir". To me, it sounds like it returns something, not sets and resets something. But I don't have a

[Python-ideas] Re: os.workdir() context manager

2021-09-15 Thread Eric V. Smith
> On Sep 15, 2021, at 4:11 AM, Christian Heimes wrote: > > On 15/09/2021 09.21, Eric V. Smith wrote: >>> On 9/15/2021 3:02 AM, Christian Heimes wrote: >>> On 15/09/2021 01.55, Guido van Rossum wrote: >>>> I know where I'd file a bug. :-) >>>

[Python-ideas] Re: os.workdir() context manager

2021-09-15 Thread Eric V. Smith
On 9/15/2021 3:02 AM, Christian Heimes wrote: On 15/09/2021 01.55, Guido van Rossum wrote: I know where I'd file a bug. :-) "Bug magnet" is an extremely subjective pejorative term. When the *better* way to do things (os.workdir()) is harder than the *easy* way to do (os.chdir()), which is the

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-29 Thread Eric V. Smith
Good point. -- Eric > On Jul 29, 2021, at 3:18 AM, Thomas Grainger wrote: > >  > But heterogeneous iteration would require typing changes > >> On Thu, 29 Jul 2021, 02:18 Eric V. Smith, wrote: >> In dataclasses, support for __slots__ is being added in 3.10.

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Eric V. Smith
In dataclasses, support for __slots__ is being added in 3.10. Adding optional support for iteration would be easy. -- Eric V. Smith > On Jul 28, 2021, at 7:29 PM, Paul Bryan wrote: > >  > I'm with you; since dataclasses were introduced, namedtuple has not see any > use from

[Python-ideas] Re: writelines2?

2021-07-13 Thread Eric V. Smith
Ignore me on this, I wasn't focusing on the function at hand. Eric On 7/13/2021 10:18 AM, Eric V. Smith wrote: On 7/13/2021 9:52 AM, Thomas Güttler wrote: Am Di., 13. Juli 2021 um 15:02 Uhr schrieb <mailto:sandhoners...@gmail.com>>: Right now, writelines is a very big misnome

[Python-ideas] Re: writelines2?

2021-07-13 Thread Eric V. Smith
On 7/13/2021 7:15 AM, sandhoners...@gmail.com wrote: Right now, writelines is a very big misnomer to many python developers, especially beginners who would expect writelines to put new lines at the end of every element in the list My suggestion is to have either a writelines2 or a newline

[Python-ideas] Re: writelines2?

2021-07-13 Thread Eric V. Smith
On 7/13/2021 9:52 AM, Thomas Güttler wrote: Am Di., 13. Juli 2021 um 15:02 Uhr schrieb >: Right now, writelines is a very big misnomer to many python developers, especially beginners who would expect writelines to put new lines at the end of every

[Python-ideas] Re: disallow assignment to unknown ssl.SSLContext attributes

2021-06-26 Thread Eric V. Smith
> On Jun 26, 2021, at 3:35 PM, Ethan Furman wrote: > > [oops, hit Send too soon] > > On 6/25/21 5:20 PM, Eric V. Smith wrote: > > > It seems like many of the suggestions are SSLContext specific. I don't > > think we should be adding > > __slots__ o

[Python-ideas] Re: disallow assignment to unknown ssl.SSLContext attributes

2021-06-25 Thread Eric V. Smith
On 6/25/2021 8:09 PM, Steven D'Aprano wrote: Hi Thomas, On Fri, Jun 25, 2021 at 09:06:58AM -, Thomas Grainger wrote: I'd like invalid attribute assignment to be prevented at runtime Are you making a specific request for ssl context objects, or a general language-wide request that applies

[Python-ideas] Re: Pre PEP: Python Literals (was custom strings before)

2021-06-13 Thread Eric V. Smith
On 6/13/2021 7:24 PM, Chris Angelico wrote: On Mon, Jun 14, 2021 at 8:58 AM Jim Baker wrote: * Logging strings which don't have to format their expressions - so similar to current logging when not using f-strings, but with the easy interface of f-strings, including desired formatting of

[Python-ideas] Re: Decorators on variables

2021-05-26 Thread Eric V. Smith
On 5/26/2021 7:07 AM, Chris Angelico wrote: Either way, it would be a string. The difference is that string literals can be placed adjacent to each other: "{1}" f' - {1+2=} - ' '{2}' '{1} - 1+2=3 - {2}' Which goes to show, btw, that an f-string is still a literal, even though it's not a

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-21 Thread Eric V. Smith
On 5/20/2021 5:41 PM, Stephen J. Turnbull wrote: Matt del Valle writes: > Fully agreed on the sentiment that we shouldn't treat compile-time > literals differently from runtime operations. But as you just pointed out, we do. Literals are evaluated at compile time, operations at runtime.

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-14 Thread Eric V. Smith
On 5/14/2021 5:29 PM, Ethan Furman wrote: On 5/14/21 5:12 AM, Martin Teichmann wrote: > In order to showcase how that would look like, let me give an example session: > >  >>> 5/6-4/15 >  17/30 >  >>> a=22/7 >  >>> f"{a}" >  '22/7' >  >>> f"{a:f}" >  '3.142857' >   

[Python-ideas] Re: Comprehensions within f-strings

2021-05-02 Thread Eric V. Smith
types isn't the only format spec language around, and indeed it's not the only used by built-in types. -- Eric V. Smith ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https

[Python-ideas] Re: Support more conversions in format string

2021-04-23 Thread Eric V. Smith
On 4/23/2021 5:22 AM, Stephen J. Turnbull wrote: But we could change int.__format__ to allow 's' as a format code[1], automagically calling str(), just as 'efg' are allowed and automagically call float(). ... [1] I recognize this may imply many changes, since some (all?) of the builtin types

[Python-ideas] Re: Change the exception type and message raised when _curses is not found

2021-04-05 Thread Eric V. Smith
> On Apr 5, 2021, at 4:43 AM, Shreyan Avigyan wrote: > > Yes you are right. But isn't informing people about a change the work of > PEP? I mean this is kind of a major change because we're trying to change the > error message and/or the type. If the type is not changed then no PEP is >

[Python-ideas] Re: self documenting kwarg passing in functions similar to f-strings in python3.8

2021-03-18 Thread Eric V. Smith
/ Code of Conduct: http://python.org/psf/codeofconduct/ -- Eric V. Smith ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ M

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-17 Thread Eric V. Smith
I've created https://bugs.python.org/issue43532 for this. PR is https://github.com/python/cpython/pull/24909. I still need to add a few more tests and update the documentation. Eric On 3/15/2021 5:18 PM, Eric V. Smith wrote: [I'm sort of loose with the terms field, parameter, and argument

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-17 Thread Eric V. Smith
On 3/17/2021 8:07 AM, Laurie O wrote: A suggestion for ease of extension in the future: replace `field` parameter `kw_only` with `init_type`. As `field` is expected to be used less than `_: dataclasses.KW_ONLY` and `dataclass(kw_only=True)`, it can afford to be more verbose. On top of that,

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
you'd probably just write `case C(a, c)` -- that's about the same as `case C(a, c, b=_, d=_)` except it doesn't even care whether b and d are set at all. On Tue, Mar 16, 2021 at 1:36 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: And now I have a question for you, Guido. I'

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
. Eric On 3/15/2021 7:45 PM, Guido van Rossum wrote: Good proposal! I have a few questions. On Mon, Mar 15, 2021 at 2:22 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: [I'm sort of loose with the terms field, parameter, and argument here. Forgive me: I think i

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 12:16 PM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 11:59 AM Eric V. Smith <mailto:e...@trueblade.com>> wrote: On 3/16/2021 10:06 AM, Ricky Teachey wrote: ... I think I prefer it, too. But what about using something like `mark=dataclasses.KW_ONLY` ra

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
__init__(self, x, y, z, x2, /, a, a2, a3, *, b=0, c='foo', d, e=0.0, f, g=(), h='bar', i=3+4j, j=10, k, b2, b3=9): All arguments are ordered from the super super class until the subclass all in their respective path or group of arguments. Abdulla On 16 Mar 2021, at 1:18 AM, Eric V. Smith

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 10:06 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 10:03 AM Eric V. Smith <mailto:e...@trueblade.com>> wrote: On 3/16/2021 9:48 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith mailto:e...@trueblade.com>> wrote: On 3/

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 9:48 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith <mailto:e...@trueblade.com>> wrote: On 3/16/2021 7:01 AM, Simão Afonso @ Powertools Tech wrote: >> The problem is that if you have 1 normal parameter and 10 keyword-only

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/W7VT6KBZETMVBBCU722VTZWP6777SFX4/ Code of Conduct: http://python.org/psf/codeofconduct/ -- Eric V. Smith ___ Python-ideas

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-15 Thread Eric V. Smith
On 3/15/2021 7:45 PM, Guido van Rossum wrote: Good proposal! I have a few questions. Thanks for the feedback. On Mon, Mar 15, 2021 at 2:22 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: [I'm sort of loose with the terms field, parameter, and argument here. Forg

[Python-ideas] dataclasses keyword-only fields, take 2

2021-03-15 Thread Eric V. Smith
[I'm sort of loose with the terms field, parameter, and argument here. Forgive me: I think it's still understandable. Also I'm not specifying types here, I'm using Any everywhere. Use your imagination and substitute real types if it helps you.] Here's version 2 of my proposal: There have

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-14 Thread Eric V. Smith
at 3:14 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: The thing is, even without being able to switch back and forth within a single dataclass, you could achieve the same thing with inheritance: ... In both cases, you'd get re-ordered fields in __init__, and

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
3:14 PM, Eric V. Smith wrote: On 3/13/2021 2:51 PM, Abdulla Al Kathiri wrote: I don’t like the idea of going back and fourth for positional and keyword arguments. The positional arguments have to stay at the top of some variable (be it anything, e.g, __pos: Any). The mixed stays in between

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
ri, Mar 12, 2021, 11:55 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: There have been many requests to add keyword-only fields to dataclasses. These fields would result in __init__ parameters that are keyword-only. As long as I'm doing this, I'd like to add positional-only fields a

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
u can play all sorts of games with inheritance to get same effect. It's just not very user friendly. Eric El sáb, 13 mar 2021 a las 7:17, Eric V. Smith (<mailto:e...@trueblade.com>>) escribió: On 3/13/2021 9:33 AM, Ricky Teachey wrote: Fwiw I read Eric's entire proposal (I like

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
python.org/archives/list/python-ideas@python.org/message/FYDLY5CY7XTJ6TME3RCDHL53VX4AQ3WB/ Code of Conduct: http://python.org/psf/codeofconduct/ -- Eric V. Smith ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
Come to think of it, this would make certain declarative constructs like those found in SQLAlchemy much cleaner as well, but that's a proposal for a different thread :p On Sat, Mar 13, 2021 at 9:50 AM Eric V. Smith <mailto:e...@trueblade.com>> wrote: Sorry, Matt: I meant to credit y

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
On 3/13/2021 6:41 AM, Matt Wozniski wrote: On Fri, Mar 12, 2021, 11:55 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: There have been many requests to add keyword-only fields to dataclasses. These fields would result in __init__ parameters that are key

[Python-ideas] Re: dataclasses: position-only and keyword-only fields

2021-03-13 Thread Eric V. Smith
"I'd like focus this thread" has ever worked in the history of python-ideas. Eric On 3/13/2021 2:40 AM, Matt Wozniski wrote: On Fri, Mar 12, 2021, 11:55 PM Eric V. Smith <mailto:e...@trueblade.com>> wrote: I should mention another idea that showed up on python-ideas, at

[Python-ideas] dataclasses: position-only and keyword-only fields

2021-03-12 Thread Eric V. Smith
[I'm sort of loose with the terms field, parameter, and argument here. Forgive me: I think it's still understandable. Also I'm not specifying types here, I'm using Any everywhere. Use your imagination and substitute real types if it helps you.] There have been many requests to add

[Python-ideas] Re: allow initial comma

2021-03-12 Thread Eric V. Smith
On 3/12/2021 4:42 PM, Paul Bryan wrote: Using your example (thanks, seeing a concrete example is helpful) it appears you can do it the SQL way in Python too: x = (1 ,2 ,3 ) Right. It's just that no one would want to! Eric On Fri, 2021-03-12 at 16:35 -0500, Eric V. Smith wrote: On 3/12

[Python-ideas] Re: allow initial comma

2021-03-12 Thread Eric V. Smith
On 3/12/2021 3:37 PM, Greg Ewing wrote: On 13/03/21 5:02 am, Ned Batchelder wrote: I think the only reason anyone ever used leading commas to begin with was because of languages that didn't allow a final trailing comma.  In those worlds, to keep the editing smooth, people moved the commas to

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Eric V. Smith
1 at 10:45 -0800, Ethan Furman wrote: On 3/10/21 9:47 PM, Eric V. Smith wrote: I'm not sure of the best way to achieve this. Using flags to field() doesn't sound awesome, but could be made to work. Or maybe special field names or types? I'm not crazy about that, but using special types would

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Eric V. Smith
On 3/11/2021 10:23 AM, Ricky Teachey wrote: On Thu, Mar 11, 2021 at 10:20 AM Paul Bryan > wrote: Given that @dataclass is a decorator, and otherwise you're just defining a class, some concerns: 1. Such proposed syntax would require a change to the language

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Eric V. Smith
full range of argument types to be available. This is especially true as dataclasses are used for more and more things (at least that's what happens in my code). Eric On Thu, 2021-03-11 at 00:47 -0500, Eric V. Smith wrote: As I've said before, I'm not opposed to the feature of keyword-only argument

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Eric V. Smith
cially and the field doesn't become a __init__ argument. There are also issues with inheritance that would need to be thought through. This idea could also be extended for positional-only. I'm open to other suggestions. Eric On 3/10/2021 10:22 AM, Guido van Rossum wrote: I've seen commen

  1   2   3   4   >