PEP XXX: None-aware access operators [DRAFT] - #1
Conversation
|
In Motivation / Nested objects
|
|
In Motivation / Other
|
|
I think this should mention what has changed since PEP-505. For instance, the rejected ideas are just copied from PEP-505. So I think you should contact past authors to ask them if you can just C/C their text. |
|
Thanks for the review @Dutcho! I've addressed your comments in 092e36f.
That's absolutely correct and I believe something which contributed to the confusion especially regarding the
Yes, though that is by design. Something I'd like to point out with this section is that these patterns often hide in plain sight and while not identical, using |
Yes, some parts form the rejected ideas sections, are more or less identical to PEP 505. I've chosen to omit mentioning the original authors (e.g. in an His opinion if I understand it correctly, boils down to the Proliferation of None in code bases argument I listed in the The link to his response regarding the status of PEP 505 at EuroPython 2022: https://youtu.be/0m2Cy5X6lcE?t=1521 |
163d0d6 to
d305adf
Compare
|
I've open the PR in the |
|
Hey Marc, There’s one adjacent use case I’ve been thinking about: type narrowing when
state_machine = agent.state_machine
assert state_machine is not None
server_wrapper = state_machine.server_wrapper
assert server_wrapper is not None
server = server_wrapper.server
assert server is not None
address = server.addressI was wondering whether a postfix non-None assertion operator, perhaps address = agent.state_machine!!.server_wrapper!!.server!!.addressThe idea would be that So the distinction would roughly be: x?.y # None is acceptable; propagate it
x!!.y # None is a bug; fail here and narrow the typeI noticed the draft discussion briefly mentioned a possible future not-None assertion operator as out of scope. Have you thought about this use case much? Does it seem like a natural follow-up to you? I have a rough write-up, but wanted to ask you informally before starting another public Ideas discussion. |
|
Hi @KonradStanski, no problem! Yeah, I've thought about that, too since I've come across that exact use case myself. Unfortunately, I'm not sure there is much hope for that being added anytime soon. So far new syntax just for typing was almost always rejected. And if we condense your example a bit, it technically is just for typing. The AssertionError is just on top. Personally I'd recommend to wait and see how the PEP discussion for 823 will go and whether or not it will be accepted before exploring anything else on top of that. I hope that I can start the discussions for the PEPs later this month. Just waiting on a last round of reviews at the moment. On a technical note, I'd drop the double exclamation mark in exchange for just If you want to discuss that further, feel free to message me on https://discuss.python.org. |
Preview: https://cdce8p-python-peps--1.org.readthedocs.build/pep-0999/