FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PEP 824: Expand 'How to Teach This' to a mini-tutorial by gvanrossum · Pull Request #5179 · python/peps · GitHub

Repository navigation

PEP 824: Expand 'How to Teach This' to a mini-tutorial - #5179

Open
gvanrossum wants to merge 2 commits into
python:mainfrom
gvanrossum:teach824
Open

gvanrossum wants to merge 2 commits into
python:mainfrom
gvanrossum:teach824

Conversation

Copy link
Copy Markdown
Member

Don't merge until @cdce8p (Marc Mueller, the PEP author) approves!

Copy link
Copy Markdown

Documentation build overview

📚 pep-previews | 🛠️ Build #35253137 | 📁 Comparing 47ac704 against latest (d5d2571)

  🔍 Preview build  

1 file changed
± pep-0824/index.html

willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks @gvanrossum. Chaining and operator precedence sections are very helpful and descriptive. Leaving for the PEP author to weigh in prior to merging.

cdce8p left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Similar to the other PR, it could be nice to add a short note to the (to be created) Change History section.

Comment thread peps/pep-0824.rst
Comment on lines +328 to +335
For example, ``d.get(key) ?? make_default(key)`` is roughly equivalent to
``d.get(key, make_default(key))``, with two differences:

* ``??`` only evaluates ``make_default(key)`` when needed, whereas the
function call used as the default argument to ``dict.get`` is always
evaluated.
* ``??`` also returns the default when ``d[key]`` is ``None``, whereas
``dict.get`` returns ``None`` in that case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I needed to read this section multiple times to fully understand it. While correct, I don't know if it adds much value here. I'd just remove it.

Comment thread peps/pep-0824.rst
Comment on lines +352 to +353
Adding parentheses does not change this: ``(a ?? b) ?? c`` has the same
meaning as ``a ?? (b ?? c)``, since ``??`` is an associative operator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can we mention that or is also an associative operator and the behavior is similar to that?

Comment thread peps/pep-0824.rst
Comment on lines +366 to +371
When to use
-----------

This is useful when you find yourself writing expressions like
``a if a is not None else b`` a lot. The ``??=`` operator is handy for
providing defaults for arguments. For example:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it would make sense if we included an example for just ?? here as well. Maybe something along these lines? Cases where or is used just to filter out None.

def get_user_names(users: list[User] | None = None) -> list[str]:
    return [user.name for user in users or ()]  # `or` -> `??`

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL