[issue44123] make function parameter sentinel value true singletons

2021-05-15 Thread Tal Einat
Tal Einat added the comment: > And what you need is just to not pass to the wrapped function arguments which > were not passed to wrapper. *args and **kwargs do not contain arguments which > were not passed. It's common for wrapper functions to mirror the defaults of the wrapped functions a

[issue44123] make function parameter sentinel value true singletons

2021-05-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Parameters are not passed to a function. Arguments are passed. And what you need is just to not pass to the wrapped function arguments which were not passed to wrapper. *args and **kwargs do not contain arguments which were not passed. I understand that i

[issue44123] make function parameter sentinel value true singletons

2021-05-14 Thread Tal Einat
Tal Einat added the comment: > I do not understand the problem with pickling sentinel values used as default > values for function parameters. Could you please show an example? A category of relevant uses I can think of is when wrapping a function and storing the parameters it was called wit

[issue44123] make function parameter sentinel value true singletons

2021-05-14 Thread STINNER Victor
STINNER Victor added the comment: Tal: "This is also being discussed on python-dev." https://mail.python.org/archives/list/python-...@python.org/thread/ZLVPD2OISI7M4POMTR2FCQTE6TPMPTO3/ -- nosy: +vstinner ___ Python tracker

[issue44123] make function parameter sentinel value true singletons

2021-05-14 Thread Tal Einat
Tal Einat added the comment: > This needs a good deal more discussion before sweeping through the code and > change a long standing Python idiom that has stood the test of time. I agree this should be discussed, which is why I created this issue about it, as place for that discussion to take

[issue44123] make function parameter sentinel value true singletons

2021-05-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I do not understand the problem with pickling sentinel values used as default values for function parameters. Could you please show an example? -- nosy: +serhiy.storchaka ___ Python tracker

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: This needs a good deal more discussion before sweeping through the code and change a long standing Python idiom that has stood the test of time. Until now, no one has claimed that this is broken. You "recently noticing this" doesn't mean that it is wron

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Tal Einat
Tal Einat added the comment: ... and they can be given excellent reprs by using a meta-class: class Sentinel(type): @classmethod def __prepare__(cls, name, bases, **kwds): d = super().__prepare__(name, bases, **kwds) def __new__(cls_, *args, **kwargs): raise

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Tal Einat
Tal Einat added the comment: Alternatively, sentinels can simply be classes: class Sentinel: def __new__(cls, *args, **kwargs): raise TypeError(f'{cls.__qualname__} cannot be instantiated') class MISSING(Sentinel): pass -- ___ Pyth

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Tal Einat
Tal Einat added the comment: Here is what I suggest working with sentinels would look like: >>> from dataclasses import MISSING >>> MISSING dataclasses.MISSING >>> M2 = pickle.loads(pickle.dumps(MISSING)) >>> M2 dataclasses.MISSING >>> M2 is MISSING True Here's an implementation which ensur

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.p

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Zachary Ware
Zachary Ware added the comment: FWIW, at work we've been using `...` as a handy not-None singleton. -- nosy: +zach.ware ___ Python tracker ___

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Tal Einat
Tal Einat added the comment: Additional examples of such sentinel values in the stdlib are those in the dataclasses module, e.g. dataclasses.MISSING. -- ___ Python tracker __

[issue44123] make function parameter sentinel value true singletons

2021-05-13 Thread Tal Einat
New submission from Tal Einat : I recently noticed that some functions use sentinel values to differentiate between not having been passed any value vs. None. One example of this is traceback.print_exception(), hence I'm adding Irit to the nosy list. However, using e.g. `sentinel = object()`