Re: [Python-ideas] New PEP proposal -- Pathlib Module Should Contain All File Operations

2018-03-16 Thread Joonas Liik
If there it is desireable to have pathlib used to represent paths that do
not map directly to the filesystem..

then it might be an acceptable compromise to have yet another... package
that just imports os, pathlib, shutil etc and re-exports all relevant
functions.
i mean we are talking about convenience here anyway not new functionality
and this would enable 1-import convenience that gives you
all-you-would-ever-want
but at the cost of maybe a bit more startup time if you only needed 1 of
the 3 modules that do actual work. and avoid polluting pathlib with things
that are... too useful in the real world :P
___
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] Null coalescing operator

2016-10-27 Thread Joonas Liik
perhaps just having a utility function can get us some of the way there..

#may error
r = a.b.x.z

# will default to None
r = a?.b?.x?.z
r = get_null_aware(a, "b.x.z") # long but no new syntax, can be
implemented today.
___
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] from __pip__ import

2016-09-19 Thread Joonas Liik
On 19 September 2016 at 19:55, אלעזר  wrote:
> A library in PyPi  still requires installing it, which undermine many of the
> benefits. It won't help me with my gist/activestate recipe, code that I send
> to a friend, etc. I want to lower the barrier of inexperienced users.
>
> As a documentation of dependencies it will suffice indeed.
>
> Elazar
>
> On Mon, Sep 19, 2016 at 7:38 PM Ethan Furman  wrote:
>>
>> On 09/19/2016 09:25 AM, אלעזר wrote:
>>
>> > Many proposals to add something to stdlib are rejected here with the
>> > suggestion to add such library to pypi first. As noted by someone, pypi is
>> > not as reachable as stdlib, and one should install that package first, 
>> > which
>> > many people don't know how. Additionally, there is no natural distinction
>> > between 3rd party dependencies and in-project imports (at least in tiny
>> > projects).
>> >
>> > This can be made easier if the first line of the program will declare
>> > the required library, and executing it will try to download and install 
>> > that
>> > library if it is not installed yet. Additionally, the 3rd party 
>> > dependencies
>> > will be more explicit, and editors can then allow you to search for them as
>> > you type.
>> >
>> > Of course it is *not* an alternative for real dependency management, but
>> > it will ease the burden on small scripts and tiny projects - which today
>> > simply break with errors that many users does not understand, instead of
>> > simply asking permission to install the dependency.
>>
>> This should start out as a library on PyPI.  (Sorry, couldn't resist. ;)
>>
>> Actually, it should.  Perhaps a name of "import_pip" would make sense?
>> Any hurdles faced by this library would be (mostly) the same as a stdlib
>> version.
>>
>> --
>> ~Ethan~
>> ___
>> 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/

using pip from within python is not that difficult already.
as can be seen with a glance to:
http://stackoverflow.com/questions/12332975/installing-python-module-within-code
___
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] Extending expressions using ellipsis

2016-09-01 Thread Joonas Liik
On 1 September 2016 at 11:10, Sjoerd Job Postmus
 wrote:
> On Thu, Sep 01, 2016 at 10:43:17AM +0300, Joonas Liik wrote:
>> Not sure if this is a good idea but it might also make some sense to
>> in stead have an operator at the beginning of the line
>>
>> for example some languages have a chainging operator for method calls:
>>
>> my_object.m1()
>> ..m2()
>> being equivalent to
>> my_object.m1()
>> my_object.m2()
>>
>> It could also be possible to have a special
>> swallow-the-preceding-newline operator or something of that effect.
>>
>> side note: the chainging operator does not work on the return value of
>> the method thus the method no longer has to choose between returning
>> useful info or `this` for chaining convenience.
>
> Not sure if I would appreciate this. Most of the cases where I do
> chaining method calls, it's the return value that's being chained on. Of
> course that is logical, because that's what's currently possible. Also,
> would it be called 'call forking' instead of 'call chaining'...?
>
> But also, what does this mean:
>
> my_object.value.m1()
> ..m2()
>
> is that
>
> my_object.value.m1()
> my_object.value.m2()
>
> or
>
> my_object.value.m1()
> my_object.m2()
>
>
> I do think the syntax you suggest is readable, I just think the
> semantics is confusing and ambiguous in non-trivial examples. And the
> extra '.' to signify it is chaining is not really a syntactical
> necessity I think.
>
> What I think might be a neat idea is to do the following:
>
> if:
> - we have an 'unexpected indent', and
> - the line starts with a '.'
>
> then:
> - interpret the physical line as continuation of the previous line.
>
>
> In any current Python version this is a syntax error. In a new Python
> version it could be *the* obvious way to do method chaining.
>
> inactive_admins = User.objects
>   .filter(is_staff=True)
>   .exclude(last_login__gt=three_weeks_ago)
>
> In current versions of Python, you have to add a `\` to the end, in a
> possible future version of Python, you could leave out the `\`.
>
> To be fair, I think this only makes sense for when the next line starts
> with a `.`.
>
> In PEP8 we could add a rule about 'aligning the . with the last dot on
> the previous line' (or an indent of 4 if the previous line has no dot).
>
> Even though I think it would make for a good enhancement to the Python
> language, I can not currently estimate how much of a change to the
> Python parser this would need to be. Is it a three-hour straight-forward
> job, or a three-month bug-prone assignment?
>
> Regards,
> Sjoerd Job

its just some syntax i've come across in some other language (can't
recall which one unfortunately), the semantics being ..

#you have this
r = a.b()..c()..d()

#is equivalent to
t=a
a.b()
a.c()
r=a.d()

of yourse if you want to maintain readability you want most calls to
be on separate lines so
r = a.b()
..c()
..d() # the return value of the last function is the value of the
entire expression

with some some names that are actually descriptive this could quite
nicely represent a sequence of transformations to something for
example (is this why jQuery has so much method chaining?)

anyway with method chaing you sometimes (often? rarely?) have an issue
where you have a meaningful return value so you have to chooze if you
want to return meaningful output or return self/this to enable
chaining.
if you need the return value then you obviously need to capture it but
sometimes you just want the side effect (mutating state of `self`) and
don't care about what the method returns.

if you have this you probably want method chaining to be usable in
expressions tho, having subsets of language usable in different
contexts rly gets annoying mmighty fast.
___
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] Extending expressions using ellipsis

2016-09-01 Thread Joonas Liik
On 1 September 2016 at 09:40, Greg Ewing  wrote:
> Guido van Rossum wrote:
>>
>> Would this be enforced in the grammar or by the lexer? Since you say
>> you expect the indentation to be enforced, that suggests it would be
>> done by the grammar,
>
>
> I think it could be done by having the lexer enter a mode
> where it swallows a newline that is followed by an indentation
> to a level greater than the starting level of the construct.
> Then no change would be needed to the grammar.
>
> --
> Greg
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

Not sure if this is a good idea but it might also make some sense to
in stead have an operator at the beginning of the line

for example some languages have a chainging operator for method calls:

my_object.m1()
..m2()
being equivalent to
my_object.m1()
my_object.m2()

It could also be possible to have a special
swallow-the-preceding-newline operator or something of that effect.

side note: the chainging operator does not work on the return value of
the method thus the method no longer has to choose between returning
useful info or `this` for chaining convenience.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/