NoneType is just another type, and in type checking scenarios should be expressed with `Optional[type]` or more preferably in the future `type | None`; `None` is not a non-value. Assuming what I just wrote is true, I don't get what the basis of this thread is; what am I missing?
On Mon, 18 Oct 2021 at 19:29, Guido van Rossum <gu...@python.org> wrote:
> y = None # Default
> if config is not None:
> handler = config.get("handler")
> if handler is not None:
> parameters = handler.get("parameters")
> if parameters is not None:
> y = parameters.get("y")
For this particular usage, I'd much rather have a functional API, like
y = get_config(config, "handler", "parameters", "y")
_______________________________________________ Python-Dev mailing list -- pytho...@python.org To unsubscribe send an email to python-d...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/GKOYEMS7RFHTRPDJ23RAHBBNTFDXKGFJ/
In case it saves anyone a couple clicks: https://www.python.org/dev/peps/pep-0463/
I also prefer more syntactic help with exceptions, rather than more syntax emphasizing None's uniqueness.
None and its ilk often conflate too many qualities. For example, is it missing because it doesn't exist, it never existed, or because we never received a value, despite knowing it must exist?
The languages SAS and R support at least 27 varieties of NA, allowing un-tagged, and tagged with the letters A-Z to help someone create distinctions between different kinds of nothingness. IEEE-754 allows about 16 million possible NaNs, which I believe was intended to allow floating point instructions to pass error messages along.
If the motivation for this operator is chained lookups, how about adding a feature to the operator module, first? It seems natural to add a keyword-only argument to `attrgetter`, and it's a lighter touch than implementing a new operator. If use becomes widespread, that gives more weight to PEP 505.
def attrgetter(*attrs, none_aware=False)
https://docs.python.org/3/library/operator.html#operator.attrgetterApologies if attrgetter has already been discussed. I didn't see mention of it in PEP 505.
_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
On Wed, Oct 20, 2021 at 2:33 AM Michael Selik <mi...@quantami.com> wrote:In case it saves anyone a couple clicks: https://www.python.org/dev/peps/pep-0463/
I also prefer more syntactic help with exceptions, rather than more syntax emphasizing None's uniqueness.Me too, but could you provide me an example where try-except approach is more readable when trying to chain attribute lookups (like in the database book-publisher-owner example I have provided before).
If the motivation for this operator is chained lookups, how about adding a feature to the operator module, first? It seems natural to add a keyword-only argument to `attrgetter`, and it's a lighter touch than implementing a new operator. If use becomes widespread, that gives more weight to PEP 505.
def attrgetter(*attrs, none_aware=False)
https://docs.python.org/3/library/operator.html#operator.attrgetter
I remember using inhouse solution like this at a certain workplace - a method accepting list of string arguments and an object, returning the value being the result of chained attribute access. And it worked all right. The problem I have with such approaches is that the name of the attrs are passed as strings.
On Wed, Oct 20, 2021 at 1:16 AM Piotr Waszkiewicz <wasz...@gmail.com> wrote:On Wed, Oct 20, 2021 at 2:33 AM Michael Selik <mi...@quantami.com> wrote:In case it saves anyone a couple clicks: https://www.python.org/dev/peps/pep-0463/
I also prefer more syntactic help with exceptions, rather than more syntax emphasizing None's uniqueness.Me too, but could you provide me an example where try-except approach is more readable when trying to chain attribute lookups (like in the database book-publisher-owner example I have provided before).I'd echo the others' examples, taking inspiration from PEP 463.
If the motivation for this operator is chained lookups, how about adding a feature to the operator module, first? It seems natural to add a keyword-only argument to `attrgetter`, and it's a lighter touch than implementing a new operator. If use becomes widespread, that gives more weight to PEP 505.
def attrgetter(*attrs, none_aware=False)
https://docs.python.org/3/library/operator.html#operator.attrgetterI remember using inhouse solution like this at a certain workplace - a method accepting list of string arguments and an object, returning the value being the result of chained attribute access. And it worked all right. The problem I have with such approaches is that the name of the attrs are passed as strings.I understand the preference for attributes over strings, but many of the none-aware examples use keys and indices. If JSON is the main culprit for deeply nested structures, then you're already using strings and not attributes. Adding features to `operator` wouldn't preclude accepting PEP 505, so why not get started with a less controversial change that provides much of the value?
If PEP 505 is accepted, it would need support in the `operator` module. Might as well design that aspect of the implementation now.
Do you think about something along those lines?```phone = book.publisher.owner.phone except AttributeError: None```
I don't mind this syntax but it would have to be supported by static type checkers and IDEs. And currently something like this is not:```try:phone = book.publisher.owner.phoneexcept AttributeError:phone = None```mypy complains:```error: Item "None" of "Optional[Publisher]" has no attribute "owner"
```
If PEP 505 is accepted, it would need support in the `operator` module. Might as well design that aspect of the implementation now.I'm sorry but I don't know if I understand that sentence correctly. You mean we would have to add an "explicit" function that behaves like a maybe-dot operator? Is it actually a requirement when adding new operators?
On Wed, Oct 20, 2021 at 9:18 AM Piotr Waszkiewicz <wasz...@gmail.com> wrote:Do you think about something along those lines?```phone = book.publisher.owner.phone except AttributeError: None```Yes, that seems reasonable.
I don't mind this syntax but it would have to be supported by static type checkers and IDEs. And currently something like this is not:```try:phone = book.publisher.owner.phoneexcept AttributeError:phone = None```mypy complains:```error: Item "None" of "Optional[Publisher]" has no attribute "owner"
```That sounds like a feature request for mypy. Would creating a new operator make it easier to implement analysis of that situation would mypy? My guess is not. Checking the AST to see if there's a try/except AttributeError sounds comparable to checking for the use of a none-aware operator. I'm completely ignorant of how mypy does its analysis, so that's just a wild guess.
If PEP 505 is accepted, it would need support in the `operator` module. Might as well design that aspect of the implementation now.I'm sorry but I don't know if I understand that sentence correctly. You mean we would have to add an "explicit" function that behaves like a maybe-dot operator? Is it actually a requirement when adding new operators?The documentation of the `operator` module says, "The operator module exports a set of efficient functions corresponding to the intrinsic operators of Python." It feels like there's an implicit "all" in there. The table of correspondences looks exhaustive. I haven't noticed any exceptions.
On Tue, Oct 19, 2021 at 05:09:42PM -0700, Michael Selik wrote:
> None and its ilk often conflate too many qualities. For example, is it
> missing because it doesn't exist, it never existed, or because we never
> received a value, despite knowing it must exist?
30+ years later, and we cannot easily, reliably or portably use NAN
payloads. Most people don't care. If we offerred them a dozen or a
thousand distinct sentinels for all the various kinds of missing data,
how many people would use them and how many would just stick to plain
old None?
I've moved this to python-ideas where it is more appropriate, as Chris notesOn Thu, Oct 21, 2021, 8:42 PM Chris Angelico <ros...@gmail.com> wrote:On Fri, Oct 22, 2021 at 3:23 AM David Mertz, Ph.D.
<david...@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 2:52 AM Steven D'Aprano <st...@pearwood.info> wrote:
>>
>> On Tue, Oct 19, 2021 at 05:09:42PM -0700, Michael Selik wrote:
>> > None and its ilk often conflate too many qualities. For example, is it
>> > missing because it doesn't exist, it never existed, or because we never
>> > received a value, despite knowing it must exist?
>
>
>>
>> 30+ years later, and we cannot easily, reliably or portably use NAN
>> payloads. Most people don't care. If we offerred them a dozen or a
>> thousand distinct sentinels for all the various kinds of missing data,
>> how many people would use them and how many would just stick to plain
>> old None?
>
>
> In data science, I have been frustrated by the sparsity of ways of spelling "missing value."
Might be worth redirecting this to -ideas.
> Besides the distinction Michael points out, and that Steven did in relation to NaNs with payloads, I encounter missingness of various other sorts as well. Crucially, an important kind of missing data is data where the value I received seems unreliable and I have decided to *impute* missingness rather than accept a value I believe is unreliable.
>
> But there is also something akin to what Michael points out (maybe it's just an example). For example, "middle name" is something that some people simply do not have, other people choose not to provide on a survey, and others still we just don't know anything beyond "it's not there."
>