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

2022-12-19 Thread Stephen J. Turnbull
Brendan Barnwell writes: > What it means for me for something to "be an HTML string" (or more > precisely, to be an instance of HTMLString or whatever the class name > is) is for it to be a string that has an extra tag attached to the > object that means "this is HTML". I don't like t

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

2022-12-19 Thread Chris Angelico
On Tue, 20 Dec 2022 at 13:56, Brendan Barnwell wrote: > > On 2022-12-19 13:59, Chris Angelico wrote: > > On Tue, 20 Dec 2022 at 07:13, Brendan Barnwell > > wrote: > >> > See my example regarding a StrEnum and tell me whether that would be > >> > more irritating. > >> > >> I can't ru

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

2022-12-19 Thread Brendan Barnwell
On 2022-12-19 13:59, Chris Angelico wrote: On Tue, 20 Dec 2022 at 07:13, Brendan Barnwell wrote: > See my example regarding a StrEnum and tell me whether that would be > more irritating. I can't run that example myself as I don't have Python 3.11 set up. The enum module was adde

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

2022-12-19 Thread Chris Angelico
On Tue, 20 Dec 2022 at 12:55, Ethan Furman wrote: > > On 12/19/22 13:59, Chris Angelico wrote: > > > The way things are, a StrEnum or an HTML string will behave *exactly > > as a string does*. The alternative is that, if any new operations are > > added to strings in the future, they have to be

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

2022-12-19 Thread Ethan Furman
On 12/19/22 13:59, Chris Angelico wrote: > The way things are, a StrEnum or an HTML string will behave *exactly > as a string does*. The alternative is that, if any new operations are > added to strings in the future, they have to be explicitly blocked by > StrEnum or else they will randomly and

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

2022-12-19 Thread Chris Angelico
On Tue, 20 Dec 2022 at 11:16, Steven D'Aprano wrote: > Speaking of dicts, the dict.fromkeys method cooperates with subclasses. > That proves that it can be done from a builtin. True, it is a > classmethod rather than an instance method, but any instance method can > find out its own class by calli

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

2022-12-19 Thread Steven D'Aprano
On Mon, Dec 19, 2022 at 03:48:01PM -0800, Christopher Barker wrote: > On Mon, Dec 19, 2022 at 3:39 AM Steven D'Aprano wrote > > > In any case, I was making a larger point that this same issue applies to > > other builtins like float, int and more. > > > Actually, I think the issue is with immut

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

2022-12-19 Thread Chris Angelico
On Tue, 20 Dec 2022 at 07:13, Brendan Barnwell wrote: > > See my example regarding a StrEnum and tell me whether that would be > > more irritating. > > I can't run that example myself as I don't have Python 3.11 set up. The enum module was added in Python 3.4. Nonetheless, a StrEnum is

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

2022-12-19 Thread Brendan Barnwell
Sorry, accidentally replied off-list. . . On 2022-12-19 11:36, Chris Angelico wrote: On Tue, 20 Dec 2022 at 06:29, Brendan Barnwell wrote: On 2022-12-19 03:45, Chris Angelico wrote: On Mon, 19 Dec 2022 at 22:37, Steven D'Aprano wrote: But this much (say with a better validator) gets you st

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

2022-12-19 Thread Chris Angelico
On Mon, 19 Dec 2022 at 22:37, Steven D'Aprano wrote: > > But this much (say with a better validator) gets you static type checking, > > syntax highlighting, and inherent documentation of intent. > > Any half-way decent static type-checker will immediately fail as soon as > you call a method on thi

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

2022-12-19 Thread Steven D'Aprano
On Mon, Dec 19, 2022 at 01:02:02AM -0600, Shantanu Jain wrote: > collections.UserString can take away a lot of this boilerplate pain from > user defined str subclasses. At what performance cost? Also: >>> s = collections.UserString('spam and eggs') >>> isinstance(s, str) False which pretty muc

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

2022-12-19 Thread Steven D'Aprano
On Sun, Dec 18, 2022 at 10:23:18PM -0500, David Mertz, Ph.D. wrote: > I'd agree to "limited", but not "hostile." Look at the suggestions I > mentioned: validate, canoncialize, security check. All of those are > perfectly fine in `.__new__()`. No, they aren't perfectly fine, because as soon as y