[Python-ideas] Re: SimpleNamespace vs object

2021-02-17 Thread Daniel Moisset
If we're bike shedding, I'd go for "mutableobject". It's not terribly short, but it is built on familiar python terminology and does exactly what it says in the box: like object() but mutable On Wed, 17 Feb 2021, 23:01 Chris Angelico, wrote: > On Thu, Feb 18, 2021 at 8:53 AM Brendan Barnwell >

[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Daniel Moisset
I'm not sure if you're reading the right document, but PEP 634 refers to 636 in its second paragraph On Tue, 4 May 2021, 19:56 Shreyan Avigyan, wrote: > Ok. Now I'm able to understand. PEP 634 should have a reference to PEP 636 > or else it's pretty hard to understand because the syntax section

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-20 Thread Daniel Moisset
ns that if you want to restart discussion, reviving >> PEP 316 is likely the best approach. >> >> Paul >> ___ >> Python-ideas mailing list >> Python-ideas@python.org >> https://mail.python.org/mailman/lis

Re: [Python-ideas] Are we supposed to be able to have our own class dictionary in python 3?

2018-11-03 Thread Daniel Moisset
Sorry, should have replied to the list too On Sat, 3 Nov 2018, 23:55 Daniel Moisset If I understood correctly what you want, it's possible with a metaclass. > Check the __prepare__ method at > https://docs.python.org/3/reference/datamodel.html#preparing-the-class-namespace > and P

Re: [Python-ideas] Are we supposed to be able to have our own class dictionary in python 3?

2018-11-04 Thread Daniel Moisset
urn result > > """ > > With: > > """ > def __new__(cls, name, bases, classdict): > > result = type.__new__(cls, name, bases, classdict) > result.member_names = classdict.member_names > return result > > """ > > Rem

[Python-ideas] Re: Argumenting in favor of first()

2019-12-11 Thread Daniel Moisset
I think a solution nobody has proposed in this thread is relaxing the next builtin, so it calls iter() on the argument when it doesn't implement the iterator protocol. That would make next([1, 2]) == 1, and also make next([], "missing") == "missing". After that all that is needed is educating the u

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-26 Thread Daniel Moisset
This idea is something I could have used many times. I agree with many people here that the strict=True API is at least "unusual" in Python. I was thinking of 2 different API approaches that could be used for this and I think no one has mentioned: - we could add a callable filler_factory keywo

[Python-ideas] Re: Dict unpacking assignment

2020-10-24 Thread Daniel Moisset
If you find PEP-634 a bit dry, you might give a try to PEP-636 (written in an explanatory style rather than a hard-spec style). You can always go back to PEP-634 for the precise details. On Fri, 23 Oct 2020 at 13:48, Ricky Teachey wrote: > Fwiw, although I see how PEP 634 has the potential to be

[Python-ideas] Re: Make for/while loops nameable.

2020-12-07 Thread Daniel Moisset
For the likely rare situation where I'd want to do this rather than refactoring into a function, I might try with something like this without requiring changes to the language: from contextlib import contextmanager @contextmanager def breakable(): class Break(Exception): pass def breaker(

Re: [Python-ideas] Fwd: Null coalescing operator

2016-09-11 Thread Daniel Moisset
Both this discussion, PEP 505, and the one a year ago, tend to mix up 2 related but separate proposals: w (A) Add a None-coalescing operator (like C# a ?? b, what you would write in Python as "a or b" if it didn't have the falsy gotcha) (B) Add some None-aware navigation operators ( The "?.", "?()"

Re: [Python-ideas] if-statement in for-loop

2016-10-04 Thread Daniel Moisset
Something else that may look confusing can be a break statement; in a for i in range(5) for j in range(5) for k in range(5): ... break does it break the inner "k" loop, going to the next "j" (as it would happen with 3 nested loops), or does it end the whole for statement? Similar question w

Re: [Python-ideas] Fwd: Fwd: Fwd: unpacking generalisations for list comprehension

2016-10-18 Thread Daniel Moisset
On 17 October 2016 at 21:22, Random832 wrote: > > No, it's not. > > For a more concrete example: > > [*range(x) for x in range(4)] > [*(),*(0,),*(0,1),*(0,1,2)] > [0, 0, 1, 0, 1, 2] > > There is simply no way to get there by using flatten(range(4)). the equivalent flatten for that is: flatten(r

Re: [Python-ideas] Proposal: Tuple of str with w'list of words'

2016-11-15 Thread Daniel Moisset
On 12 November 2016 at 17:01, Gary Godfrey wrote: > Hi, > > This is a little more readable, but still a bit ugly. What I'm proposing > here is: > > mydf = df[ w'field1 field2 field3' ] > > This would be identical in all ways (compile-time) to: > > mydf = df[ ('field1', 'field2', 'field3') ] >

Re: [Python-ideas] New function to add into the "random" module

2017-02-02 Thread Daniel Moisset
Hi Terry, the functionality you have provided is already covered by the random.uniform function On 2 February 2017 at 12:01, wrote: > Hi, my name is Terry, and I’d like to propose a small function that could > be added into the Python’s “random” module. > > > > This function is for generating a

Re: [Python-ideas] if in for-loop statement

2017-02-23 Thread Daniel Moisset
Just as a reference, I think the most recent reincarnation of this thread was: https://mail.python.org/pipermail/python-ideas/2016-September/042270.html On 23 February 2017 at 13:46, Paul Moore wrote: > On 23 February 2017 at 13:37, Henk-Jaap Wagenaar > wrote: > > Note that this has been sugges

Re: [Python-ideas] Way to repeat other than "for _ in range(x)"

2017-03-30 Thread Daniel Moisset
That's not the same, in the OP example you can assert d[0] is not d[1], while in your code that assertion fails (the list comprehension evaluates the expression each time creating a new list, your code makes 10 references to a single 5 element list) On 30 March 2017 at 14:51, Mark E. Haase wrote

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-25 Thread Daniel Moisset
I actually saw a decorator like that last week, https://twitter.com/judy2k/status/854330478068977664 On 25 April 2017 at 08:56, Paul Moore wrote: > On 25 April 2017 at 03:53, Steven D'Aprano wrote: > > On Tue, Apr 25, 2017 at 02:08:05AM +0100, Erik wrote: > > > >> I often find myself writing __

Re: [Python-ideas] Dollar operator suggestion

2017-10-26 Thread Daniel Moisset
Expanding on the comments of the OP (to give more information, not necessarily to support or be against it): The "$" operator in Haskell is not a composition operator, it's essentially the same as python's apply builtin (the python2 builtin, removed for python 3), but with an operator syntax; the

Re: [Python-ideas] How assignment should work with generators?

2017-11-27 Thread Daniel Moisset
On 27 November 2017 at 06:40, Chris Angelico wrote: > Here are a few syntaxes that I believe have been proposed at various > times: > > x, y = islice(iter, 2) # status quo > x, y = iter # your proposal > x, y, = iter # omit last destination > Just to clear the list, this one (trailing comma) wou

Re: [Python-ideas] Add a dict with the attribute access capability

2017-11-29 Thread Daniel Moisset
As reference of prior art, there is https://pypi.python.org/pypi/munch in PyPI On 29 November 2017 at 05:52, Serhiy Storchaka wrote: > In 3.7 I have removed an old-deprecated plistlib.Dict. [1] Actually it > already was deprecated when the plistlib module was added to the regular > stdlib in Pyt

Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-09 Thread Daniel Moisset
In which way would this be different to {**mapping1, **mapping2, **mapping3} ? On 8 April 2018 at 22:18, Andrés Delfino wrote: > Hi! > > I thought that maybe dict could accept several mappings as positional > arguments, like this: > > class Dict4(dict): >> def __init__(self, *args, **kwargs)

Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-09 Thread Daniel Moisset
I didn't know that kwargs unpacking in dictionaries displays don't > raise a TypeError exception. > > On Mon, Apr 9, 2018 at 8:23 AM, Daniel Moisset > wrote: > >> In which way would this be different to {**mapping1, **mapping2, >> **mapping3} ? >> >> O

Re: [Python-ideas] Move optional data out of pyc files

2018-04-10 Thread Daniel Moisset
I'm not sure I understand the benefit of this, perhaps you can clarify. What I see is two scenarios Scenario A) External files are present In this case, the data is loaded from the pyc and then from external file, so there are no savings in memory, startup time, disk space, or network load time,

Re: [Python-ideas] Move optional data out of pyc files

2018-04-12 Thread Daniel Moisset
One implementation difficulty specifically related to annotations, is that they are quite hard to find/extract from the code objects. Both docstrings and lnotab are within specific fields of the code object for their function/class/module; annotations are spread as individual constants (assuming PE

Re: [Python-ideas] Move optional data out of pyc files

2018-04-12 Thread Daniel Moisset
n the singleton that cpython normally uses for "1", although most duplicates are some small strings, tuples with argument names, or . Something that could be interesting to write is a "pyc optimizer" that removes duplicates, this should be a gain at a minimal preprocessing cost. On

Re: [Python-ideas] Pattern Matching Syntax

2018-05-04 Thread Daniel Moisset
Note that most languages that you mentioned as references are functional (so they don't have a statement/expression distinction like Python has), and those that are not, have matching statements. The only exception is Javascript, but in Javascript the distinction is not that hard given that it has

Re: [Python-ideas] Pattern Matching Syntax

2018-05-04 Thread Daniel Moisset
This email from Steve has some good questions, let me try to help organize ideas: On 4 May 2018 at 13:11, Steven D'Aprano wrote: > I'll make a start, and you can correct me if I get any of it wrong. > > (1) Pattern matching takes a value, and compares it to a series of > *patterns* until the fir

[Python-ideas] Syntax idea: escaping names to avoid keyword ambiguity

2018-05-14 Thread Daniel Moisset
rsal way to solve name clashes between python keywords and libraries that use some external concept that overlaps with python (from https://pythonhosted.org/pyquery/attributes.html ): >>> *import* pyquery *as* pq >>> p = pq(*''*)(*'p'*) >>> p.attr(id=*'hello&

Re: [Python-ideas] Syntax idea: escaping names to avoid keyword ambiguity

2018-05-14 Thread Daniel Moisset
On 14 May 2018 at 15:02, Clint Hepner wrote: > > > On 2018 May 14 , at 6:47 a, Daniel Moisset > wrote: > > > > Following up some of the discussions about the problems of adding > keywords and Guido's proposal of making tokenization context-dependent, I > wante

Re: [Python-ideas] Syntax idea: escaping names to avoid keyword ambiguity

2018-05-14 Thread Daniel Moisset
On 14 May 2018 at 15:02, Clint Hepner wrote: > > > On 2018 May 14 , at 6:47 a, Daniel Moisset > wrote: > > > > Following up some of the discussions about the problems of adding > keywords and Guido's proposal of making tokenization context-dependent, I > wante

Re: [Python-ideas] Modern language design survey for "assign and compare" statements

2018-05-21 Thread Daniel Moisset
ax won't give me. > > That use case should be covered by for v in iter(get_something, INCOVENIENT_SENTINEL): do_something(v) -- <https://www.machinalis.co.uk> Daniel Moisset UK COUNTRY MANAGER A: 1 Fore Street, EC2Y 9DT London <https://goo.gl/maps/pH9BBLgE8dG2>

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Daniel Moisset
ore ideas? > > ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- <https://www.machinalis.com/> Daniel Moi