Is it just me that find that having the un-assigned parameter raise
NameError (or other exception) much more cumbersome than
havign a sentinel-value?

I definitely don't find it clever - for one, a common default parameter -
sentinel or not, can be replaced in  a single line of code by an
expression using "if" or "or", while the Exception raising variant
require a whole try-except block.

So, while I like the idea of simplifying the "sentinel idiom", I don't
find any suggestion here useful so far.

Maybe something to the stlib that would allow something along:

from paramlib import NoDefault, passed

def myfunc(a, b, count=NoDefault):
     if not passed(count):
          ...
     else:
          ...

That would simplify a bit the sentinel pattern, do not pollute the
namespace, and don't  need any new syntax, (and still allow "if"
expressions without a full try/except block)

On 2 March 2017 at 12:04, M.-A. Lemburg <m...@egenix.com> wrote:
> On 02.03.2017 14:08, Serhiy Storchaka wrote:
>> On 02.03.17 12:04, M.-A. Lemburg wrote:
>>> This is not new syntax, nor is it a keyword. It's only a
>>> new singleton and it is well usable outside of function
>>> declarations as well, e.g. for class attributes which are
>>> not yet initialized (and which can accept None as value).
>>
>> If it is not a keyword, it could be used in expressions, e.g. assigned
>> to a variable or passed to a function. It could be monkey-patched or
>> hidden by accident (as True and False in Python 2).
>
> Yes, sure.
>
> My proposal was just to address the problems of
> changing Python syntax and making it possible to define
> positional only arguments in Python functions/methods in
> a backwards compatible way.
>
> The same could be had by adding a C function proxy to Python
> which then takes care of the error handling, since we already
> have the logic for C functions via PyArg_ParseTuple*().
> A decorator could then apply the proxy as needed or ignore this
> for older Python versions without breaking compatibility
> (or a PyPI extension could provide the same proxy logic for
> older versions).
>
> FWIW: I don't think the use case for positional only arguments
> to Python functions is strong enough to warrant breaking
> backwards compatibility by introducing new syntax.
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Experts (#1, Mar 02 2017)
>>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>>> Python Database Interfaces ...           http://products.egenix.com/
>>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
> ________________________________________________________________________
>
> ::: We implement business ideas - efficiently in both time and costs :::
>
>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>            Registered at Amtsgericht Duesseldorf: HRB 46611
>                http://www.egenix.com/company/contact/
>                       http://www.malemburg.com/
>
> _______________________________________________
> 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/

Reply via email to