[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-07 Thread Peter Ludemann
You can get almost the same result using pattern matching. For example, your "foo:bar;baz".partition(":", ";") can be done by a well-known matching idiom: re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups() ___ Python-ideas mailing list -- python-id

[Python-ideas] Re: Should Python enforce Type-checking in the future?

2021-12-10 Thread Peter Ludemann
Steven D'Aprano wrote: > > That seems to be close to the opinion of Robert C Martin: > http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html > He also has some comments on languages like Koitlin and Swift that have > gone down that path of mandatory static typing: > http://blog.cleancoder

[Python-ideas] Re: extending ast.parse with some lib2to3.pytree features

2021-11-21 Thread Peter Ludemann
Neil Girdhar wrote: > I wish this had gotten more attention! :) I wonder what the various projects are doing to handle the latest version of Python, if they need a parse tree with whitespace information. (The projects I know of are yapf, black, mypy, pytype, kythe -- are there others?) ast.pars

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Peter Ludemann
MRAB wrote: > From a mathematical point of view, x-y is equivalent to x+(-y). >From a mathematical point of view, x+y is equivalent to y+x, but I suppose >that ship has sailed a long long time ago. ("++", "--", etc. would have been >better choices for operators)[*] Anyway, if you're going to a

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Peter Ludemann
David Mertz wrote: > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... Or you can use comprehensions, in which case there's no need for creating an empty collection. s = {f(x) for x in some_list} vs s = set() for x in some_list: s.add(f(x)) __

[Python-ideas] Re: Implicit line continuation for method chaining

2021-03-13 Thread Peter Ludemann
Chris Angelico wrote: > On Sat, Mar 13, 2021 at 1:46 PM Peter Ludemann peter.ludem...@gmail.com wrote: > > It's not clear to me what surprising behaviors there would be. Javascript > > seems to do OK with optional semicolons - presumably its algorithm is > > simi

[Python-ideas] Re: Implicit line continuation for method chaining

2021-03-12 Thread Peter Ludemann
On Fri, 12 Mar 2021 at 18:27, Guido van Rossum wrote: > On Fri, Mar 12, 2021 at 6:23 PM Peter Ludemann > wrote: > >> [I wonder why C didn't adopt BCPL's convention for eliding semi-colons? >> ...] >> > > [Presumably because it caused too many surp

[Python-ideas] Re: Implicit line continuation for method chaining

2021-03-12 Thread Peter Ludemann
Guido van Rossum wrote: > Can we skip ahead to considering how to implement this? I can think of two > approaches: either hack the lexer to special-case a newline followed by a > period (which currently can never start a line), or redesign the syntax to > allow NEWLINE INDENT ‘.’ . NEWLINE

[Python-ideas] Re: Generic NamedTuples

2021-02-10 Thread Peter Ludemann
Ben Avrahami wrote 9 Feb 2021, 03:30: > That's the current alternative, but namedtuples (unlike dataclasses) are > slotted, which makes them more space-efficient and (slightly) faster. When I use @dataclass(frozen=True), I manually add a __slots__ attribute. I presume this makes the resulting

[Python-ideas] Re: Generic NamedTuples

2021-02-08 Thread Peter Ludemann
I use dataclass (with frozen=True) instead of NamedTuple - and I can do mixins. https://docs.python.org/3/library/dataclasses.html ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https

[Python-ideas] Re: Standard tool for iterating over recursive data structures?

2021-01-01 Thread Peter Ludemann
A variant of the problem is the "occurs check", used in theorem proving: https://en.wikipedia.org/wiki/Occurs_check Removing the occurs check reduces the cost of unifying two terms (t1, t2) from *O(size(t1) + size(t2))* to *O(min(size(t1), size(t2)))*, which is why Prolog implementations don't do t

[Python-ideas] extending ast.parse with some lib2to3.pytree features

2020-07-08 Thread Peter Ludemann
With lib2to3 going away (https://bugs.python.org/issue40360), it seems to me that some of its functionality for handling "whitespace" can be fairly easily added to the ast module. (By "whitespace", I mean things like indent, dedent, comments, backslash; and also the ability to manipulate the encode