Re: [Python-ideas] Verbatim names (allowing keywords as names)

2018-05-16 Thread Andrés Delfino
IMHO, it would be much easier to learn and understand if keywords can only
be used by escaping them, instead of depending where they occur.

On Wed, May 16, 2018 at 9:13 AM, Wolfgang Maier <
wolfgang.ma...@biologie.uni-freiburg.de> wrote:

> On 16.05.2018 02:41, Steven D'Aprano wrote:
>
>>
>> Some examples:
>>
>>  result = \except + 1
>>
>>  result = something.\except
>>
>>  result = \except.\finally
>>
>>
> Maybe that could get combined with Guido's original suggestion by making
> the \ optional after a .?
>
> Example:
>
> class A ():
> \global = 'Hello'
> def __init__(self):
> self.except = 0
>
> def \finally(self):
> return 'bye'
>
> print(A.global)
> a = A()
> a.except += 1
> print(a.finally())
>
> or with a module, in my_module.py:
>
> \except = 0
>
> elsewhere:
>
> import my_module
> print(my_module.except)
>
> or
>
> from my_module import \except
> print(\except)
>
> Best,
> Wolfgang
>
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Fwd: Pattern Matching Syntax

2018-05-12 Thread Andrés Delfino
I find it weird for case statements to be "inside" match statements.
There's isn't a statement "group" that works this way right now, AFAIK.

This would also be weird:

match X:
case Y:
...

I thought a form based on try would make more coherent:

match:
suite
case x:
suite1
else:
suite2

suite would be executed, and the last expression would be checked against
each case. If no matching case is found, suite2 would be executed.

Does it make sense?

On Sat, May 12, 2018 at 8:51 AM, Steven Heidel  wrote:

> Great! Also emailed you with logistics.
>
> On Sat, May 12, 2018, 01:43 Jelle Zijlstra 
> wrote:
>
>> 2018-05-11 22:01 GMT-04:00 Robert Roskam :
>>
>>> Hey Steven,
>>>
>>> I'm also at PyCon. Shall we take this off list and attempt to meet up
>>> and discuss?
>>>
>>> I'm also at PyCon and interested in meeting about this. I just wrote up
>> a basic and incomplete implementation for pattern-matching yesterday
>> between and after: talks: https://github.com/JelleZijlstra/cpython/blob/
>> matchcase/Lib/test/test_matching.py. It's nowhere near complete, but an
>> implementation like this can help inform what the syntax should look like.
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "python-ideas" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/
>> topic/python-ideas/nqW2_-kKrNg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> python-ideas+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>> ___
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "python-ideas" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/
>> topic/python-ideas/nqW2_-kKrNg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> python-ideas+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


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

2018-04-12 Thread Andrés Delfino
There's a long thread about the subject:
https://mail.python.org/pipermail/python-ideas/2015-February/031748.html

I suggest to avoid the matter altogether :)

On Thu, Apr 12, 2018 at 4:15 PM, Mike Miller <python-id...@mgmiller.net>
wrote:

> While we're on the subject, I've tried to add dicts a few times over the
> years to get a new one but it doesn't work:
>
> d3 = d1 + d2  # TypeError
>
> Thinking a bit, set union is probably a better analogue, but it doesn't
> work either:
>
> d3 = d1 | d2  # TypeError
>
> Where the last value of any duplicate keys should win.
>
> -Mike
>
>
>
> On 2018-04-12 06:46, Andrés Delfino wrote:
>
>> Extending the original idea, IMHO it would make sense for the dict
>> constructor to create a new dictionary not only from several mappings, but
>> mixing mappings and iterables too.
>>
>> Consider this example:
>>
>> x = [(1, 'one')]
>> y = {2: 'two'}
>>
>> Now: {**dict(x), **y}
>> Proposed: dict(x, y)
>>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


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

2018-04-12 Thread Andrés Delfino
Extending the original idea, IMHO it would make sense for the dict
constructor to create a new dictionary not only from several mappings, but
mixing mappings and iterables too.

Consider this example:

x = [(1, 'one')]
y = {2: 'two'}

Now: {**dict(x), **y}
Proposed: dict(x, y)

I think this extension makes the call ostensibly easier to read and grep. I
believe we are safe regarding compatibility issues, right?

What do you guys think?

On Wed, Apr 11, 2018 at 4:44 AM, Mike Miller 
wrote:

> Ok, we can haggle the finer details and I admit once you learn the syntax
> it isn't substantially harder.  Simply, I've found the dict() a bit easier
> to mentally parse at a glance.  Also, to add I've always expected multiple
> args to work with it, and am always surprised when it doesn't.
>
> Would never have thought of this unpacking syntax if I didn't know that's
> the way its done now, but often have to think about it for a second or two.
>
>
> On 2018-04-10 22:22, Chris Angelico wrote:
>
>> On Wed, Apr 11, 2018 at 2:44 PM, Steven D'Aprano 
>> wrote:
>>
>>> On Wed, Apr 11, 2018 at 02:22:08PM +1000, Chris Angelico wrote:
>>>
>>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


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

2018-04-09 Thread Andrés Delfino
Sorry, 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 <dmois...@machinalis.com>
wrote:

> In which way would this be different to {**mapping1, **mapping2,
> **mapping3} ?
>
> On 8 April 2018 at 22:18, Andrés Delfino <adelf...@gmail.com> wrote:
>
>> Hi!
>>
>> I thought that maybe dict could accept several mappings as positional
>> arguments, like this:
>>
>> class Dict4(dict):
>>> def __init__(self, *args, **kwargs):
>>> if len(args) > 1:
>>> if not all([isinstance(arg, dict) for arg in args]):
>>> raise TypeError('Dict4 expected instances of dict since
>>> multiple positional arguments were passed')
>>>
>>> temp = args[0].copy()
>>>
>>> for arg in args[1:]:
>>> temp.update(arg)
>>>
>>> super().__init__(temp, **kwargs)
>>> else:
>>> super().__init__(*args, **kwargs)
>>>
>>
>> AFAIK, this wouldn't create compatibility problems, since you can't pass
>> two positional arguments now anyways.
>>
>> It would be useful to solve the "sum/union dicts" discussion, for
>> example: requests.get(url, params=dict(params, {'foo': bar})
>>
>> Whar are your thoughts?
>>
>> ___
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>>
>
>
> --
> Daniel F. Moisset - UK Country Manager - Machinalis Limited
> www.machinalis.co.uk <http://www.machinalis.com>
> Skype: @dmoisset T: + 44 7398 827139
>
> 1 Fore St, London, EC2Y 9DT
> <https://maps.google.com/?q=1+Fore+St,+London,+EC2Y+9DT=gmail=g>
>
> Machinalis Limited is a company registered in England and Wales.
> Registered number: 10574987.
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


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

2018-04-08 Thread Andrés Delfino
 Hi!

I thought that maybe dict could accept several mappings as positional
arguments, like this:

class Dict4(dict):
> def __init__(self, *args, **kwargs):
> if len(args) > 1:
> if not all([isinstance(arg, dict) for arg in args]):
> raise TypeError('Dict4 expected instances of dict since
> multiple positional arguments were passed')
>
> temp = args[0].copy()
>
> for arg in args[1:]:
> temp.update(arg)
>
> super().__init__(temp, **kwargs)
> else:
> super().__init__(*args, **kwargs)
>

AFAIK, this wouldn't create compatibility problems, since you can't pass
two positional arguments now anyways.

It would be useful to solve the "sum/union dicts" discussion, for example:
requests.get(url, params=dict(params, {'foo': bar})

Whar are your thoughts?
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Split, slice, join and return "syntax" for str

2018-03-04 Thread Andrés Delfino
Hi!

I was thinking: perhaps it would be nice to be able to quicky split a
string, do some slicing, and then obtaining the joined string back.

Say we have the string: "docs.python.org", and we want to change "docs" to
"wiki". Of course, there are a ton of simpler ways to solve this particular
need, but perhaps str could have something like this:

spam = "docs.python.org"
eggs = "wiki." + spam['.'][1:]
print(eggs) #wiki.python.org

A quick implementation to get the idea and try it:

class Mystr(str):
def __getitem__(self, item):
if isinstance(item, str):
return Mystr_helper(self, item)
else:
return super().__getitem__(item)

class Mystr_helper:
def __init__(self, obj, sep):
self.obj = obj
self.sep = sep
def __getitem__(self, item):
return self.sep.join(self.obj.split(self.sep)[item])

What are your thoughts?

Greetings from Argentina.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/