[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Greg Ewing

On 9/04/20 1:37 am, Soni L. wrote:


On 2020-04-08 10:33 a.m., Greg Ewing wrote:


    try:
    first = next(iterator)
    except abdl.exceptions.ValidationError as e: validation_handler(e)
    except StopIteration as e: return stop_handler(e)


... I can do that today, can't I?


Yep!

--
Greg
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WO23EYGCMGKWYG5HUED4QBSMMJE2QVCR/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Soni L.



On 2020-04-08 10:33 a.m., Greg Ewing wrote:

On 9/04/20 1:22 am, Soni L. wrote:

it's hard to reason about it if your eyes just keep jumping into the 
except bodies because they have the same indentation and everything 
as the normal code. I am gonna say my proposal improves 
accessibility, even if it doesn't make a difference to most ppl.


Would you find this easier to read?

    try:
    first = next(iterator)
    except abdl.exceptions.ValidationError as e: validation_handler(e)
    except StopIteration as e: return stop_handler(e)


yeah that'd work

... I can do that today, can't I?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LLFCO2SHGIUQ543XHOIBKEG7ITX3ZFFN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Greg Ewing

On 9/04/20 1:22 am, Soni L. wrote:

it's hard to reason about it if your eyes just keep jumping into the 
except bodies because they have the same indentation and everything as 
the normal code. I am gonna say my proposal improves accessibility, even 
if it doesn't make a difference to most ppl.


Would you find this easier to read?

try:
first = next(iterator)
except abdl.exceptions.ValidationError as e: validation_handler(e)
except StopIteration as e: return stop_handler(e)

--
Greg
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VHYH3WOQZDG56PJ4CISYMH3W6HIT5Y76/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Soni L.



On 2020-04-08 10:22 a.m., Soni L. wrote:



On 2020-04-08 10:12 a.m., Joao S. O. Bueno wrote:



On Tue, 7 Apr 2020 at 23:17, Greg Ewing > wrote:


On 8/04/20 1:14 pm, Soni L. wrote:

>      def get_property_values(self, prop):
>      try:
>      factory = self.get_supported_properties()[prop]
>      except KeyError with keyerror_handler;
>      iterator = factory(self._obj)
>      try:
>      first = next(iterator)
>      except abdl.exceptions.ValidationError with
validation_handler;
>      except StopIteration with stop_handler as return
>      return itertools.chain([first], iterator)

I don't think special syntax is warranted for this. You can write:

     try:
         first = next(iterator)
     except abdl.exceptions.ValidationError as e:
         validation_handler(e)
     except StopIteration as e:
         return stop_handler(e)


I agree -  and this is far more readable than any
of the propositions so far. (Like, for an order of magnitude).

I'd wait for Soni to try to explain why this would not
fit his use case, before proceeding with the
bikeshedding.


have you looked at the syntax highlighting of the thing?

it sees keywords *everywhere* (which is right) it's basically 
unmaintainable. having the exception handlers have an exceptional 
syntax would set them apart from the rest of the code and make the 
whole thing much easier to read and maintain.


it's hard to reason about it if your eyes just keep jumping into the 
except bodies because they have the same indentation and everything as 
the normal code. I am gonna say my proposal improves accessibility, 
even if it doesn't make a difference to most ppl.


(also: I'm a they. forgot to include that in the reply. sorry.)







-- 
Greg

___
Python-ideas mailing list -- python-ideas@python.org

To unsubscribe send an email to python-ideas-le...@python.org

https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at

https://mail.python.org/archives/list/python-ideas@python.org/message/AERIZI4MRPFBJ62YAOIWO4OSXLDSMTRK/
Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-ideas mailing list --python-ideas@python.org
To unsubscribe send an email topython-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived 
athttps://mail.python.org/archives/list/python-ideas@python.org/message/Z5QFJEQVW4TTB54X5MV3HUKE5TEBK63N/
Code of Conduct:http://python.org/psf/codeofconduct/




___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LGSGCMMK73HPWJKQRD7LSX6DJ4UPTU5Y/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Soni L.



On 2020-04-08 10:12 a.m., Joao S. O. Bueno wrote:



On Tue, 7 Apr 2020 at 23:17, Greg Ewing > wrote:


On 8/04/20 1:14 pm, Soni L. wrote:

>      def get_property_values(self, prop):
>      try:
>      factory = self.get_supported_properties()[prop]
>      except KeyError with keyerror_handler;
>      iterator = factory(self._obj)
>      try:
>      first = next(iterator)
>      except abdl.exceptions.ValidationError with
validation_handler;
>      except StopIteration with stop_handler as return
>      return itertools.chain([first], iterator)

I don't think special syntax is warranted for this. You can write:

     try:
         first = next(iterator)
     except abdl.exceptions.ValidationError as e:
         validation_handler(e)
     except StopIteration as e:
         return stop_handler(e)


I agree -  and this is far more readable than any
of the propositions so far. (Like, for an order of magnitude).

I'd wait for Soni to try to explain why this would not
fit his use case, before proceeding with the
bikeshedding.


have you looked at the syntax highlighting of the thing?

it sees keywords *everywhere* (which is right) it's basically 
unmaintainable. having the exception handlers have an exceptional syntax 
would set them apart from the rest of the code and make the whole thing 
much easier to read and maintain.


it's hard to reason about it if your eyes just keep jumping into the 
except bodies because they have the same indentation and everything as 
the normal code. I am gonna say my proposal improves accessibility, even 
if it doesn't make a difference to most ppl.






-- 
Greg

___
Python-ideas mailing list -- python-ideas@python.org

To unsubscribe send an email to python-ideas-le...@python.org

https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at

https://mail.python.org/archives/list/python-ideas@python.org/message/AERIZI4MRPFBJ62YAOIWO4OSXLDSMTRK/
Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/Z5QFJEQVW4TTB54X5MV3HUKE5TEBK63N/
Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MB5DGQCZWFJSEMMS3U4Q2E6LRFJ76WVX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Joao S. O. Bueno
On Tue, 7 Apr 2020 at 23:17, Greg Ewing  wrote:

> On 8/04/20 1:14 pm, Soni L. wrote:
>
> >  def get_property_values(self, prop):
> >  try:
> >  factory = self.get_supported_properties()[prop]
> >  except KeyError with keyerror_handler;
> >  iterator = factory(self._obj)
> >  try:
> >  first = next(iterator)
> >  except abdl.exceptions.ValidationError with validation_handler;
> >  except StopIteration with stop_handler as return
> >  return itertools.chain([first], iterator)
>
> I don't think special syntax is warranted for this. You can write:
>
>  try:
>  first = next(iterator)
>  except abdl.exceptions.ValidationError as e:
>  validation_handler(e)
>  except StopIteration as e:
>  return stop_handler(e)
>
>
I agree -  and this is far more readable than any
of the propositions so far. (Like, for an order of magnitude).

I'd wait for Soni to try to explain why this would not
fit his use case, before proceeding with the
bikeshedding.





> --
> Greg
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/AERIZI4MRPFBJ62YAOIWO4OSXLDSMTRK/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/Z5QFJEQVW4TTB54X5MV3HUKE5TEBK63N/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Stephen J. Turnbull
Andrew Barnert writes:

 > I don’t like the idea either; but I think I like your version even less.
 > 
 > It reads perfectly well, but with the wrong meaning. Even though I
 > know what you’re intending, I can’t make myself read that as result
 > getting bound to what f returns, only as result getting bound to
 > the exception.

No, you don't know what I was intending. ;-)  *I* did intend 'result'
to be bound to the exception (that's *why* I changed the order of
clauses), but I think you're right: *Soni* intended it to bound to the
return of the handler.  We'll have to ask to be sure, though...

 > clearly result is getting bound to something to do with f.

Well, I had in mind that it would be f's *argument* (what else are you
going to pass to the handler?) and have the usual semantics of giving
a name to the exception in case you wanted further processing in the
body.

Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VVXKUS3QKTTQYFMQPHAREHYDCFCRXUHS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-08 Thread Andrew Barnert via Python-ideas
On Apr 7, 2020, at 22:58, Stephen J. Turnbull 
 wrote:
> 
> BTW, although obviously I don't like the idea much, I think
> 
>except BaseException as result with f:
> 
> reads better than the original suggestion:
> 
>except BaseException with f as result:
> 
> in the event this idea gets some takeup.

I don’t like the idea either; but I think I like your version even less.

It reads perfectly well, but with the wrong meaning. Even though I know what 
you’re intending, I can’t make myself read that as result getting bound to what 
f returns, only as result getting bound to the exception.

The original version, by contrast, is weird and confusing as English (and 
unnecessary, since you could do the exact same thing with a normal except 
clause and result=f(esc) instead of pass as the body…) but clearly result is 
getting bound to something to do with f.

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IVQBBVRAJBJSHHI4X5MINYTMWFZVJRMY/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-07 Thread Greg Ewing

On 8/04/20 1:14 pm, Soni L. wrote:


     def get_property_values(self, prop):
     try:
     factory = self.get_supported_properties()[prop]
     except KeyError with keyerror_handler;
     iterator = factory(self._obj)
     try:
     first = next(iterator)
     except abdl.exceptions.ValidationError with validation_handler;
     except StopIteration with stop_handler as return
     return itertools.chain([first], iterator)


I don't think special syntax is warranted for this. You can write:

try:
first = next(iterator)
except abdl.exceptions.ValidationError as e:
validation_handler(e)
except StopIteration as e:
return stop_handler(e)

--
Greg
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/AERIZI4MRPFBJ62YAOIWO4OSXLDSMTRK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: "except BaseException with f as result"

2020-04-07 Thread Soni L.



On 2020-04-07 10:12 p.m., Soni L. wrote:
the fact that exception handlers aren't reusable and composable is 
really bothering me so I would like to propose something to make them 
reusable and composable.


for example, if I have this mess:

    def get_property_values(self, prop):
    try:
    factory = self.get_supported_properties()[prop]
    except KeyError as exc:
    raise PropertyError from exc
    iterator = factory(self._obj)
    try:
    first = next(iterator)
    except StopIteration:
    return (x for x in ())
    except abdl.exceptions.ValidationError as exc:
    raise LookupError from exc
    return itertools.chain([first], iterator)

I get to refactor it into:

    def keyerror_handler(exc):
    raise PropertyError from exc

    def other_handler(exc):
    if isinstance(exc, StopIteration):
    return (x for x in ())
    raise LookupError from exc

    def get_property_values(self, prop):
    try:
    factory = self.get_supported_properties()[prop]
    except KeyError with keyerror_handler:
    pass
    iterator = factory(self._obj)
    try:
    first = next(iterator)
    except (StopIteration, abdl.exceptions.ValidationError) with 
other_handler as result:

    return result
    return itertools.chain([first], iterator)

and the handlers become reusable!

another idea would be to use semicolons:

    def get_property_values(self, prop):
    try:
    factory = self.get_supported_properties()[prop]
    except KeyError with keyerror_handler;
    iterator = factory(self._obj)
    try:
    first = next(iterator)
    except abdl.exceptions.ValidationError with validation_handler;
    except StopIteration:
    return (x for x in ())
    return itertools.chain([first], iterator)

but nobody likes semicolons


I sent too soon. here's also something that would be nice:

    def get_property_values(self, prop):
    try:
    factory = self.get_supported_properties()[prop]
    except KeyError with keyerror_handler;
    iterator = factory(self._obj)
    try:
    first = next(iterator)
    except abdl.exceptions.ValidationError with validation_handler;
    except StopIteration with stop_handler as return
    return itertools.chain([first], iterator)

(using "return" as the result target for the handler. doesn't need 
semicolon, as it can't be ambiguous.)

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4OAFHH4SCLCQCUJVSYOZ5OPQP2SLR3BQ/
Code of Conduct: http://python.org/psf/codeofconduct/