Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples from Python 3.13: Cool New Features #587

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

gahjelle
Copy link
Contributor

Where to put new files:

  • New files should go into a top-level subfolder, named after the article slug. For example: my-awesome-article

How to merge your changes:

  1. Make sure the CI code style tests all pass (+ run the automatic code formatter if necessary).
  2. Find an RP Team member on Slack and ask them to review & approve your PR.
  3. Once the PR has one positive ("approved") review, GitHub lets you merge the PR.
  4. 🎉

Copy link
Contributor

@bzaczynski bzaczynski left a comment

Choose a reason for hiding this comment

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

@gahjelle Looks good to me. I left a few comments/questions, but otherwise, approved!

Use PyLance in VS Code by setting Python › Analysis: Type Checking Mode or run
the Pyright CLI:

$ python -m pip install pyright $ pyright --pythonversion 3.13 .
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these two commands be on separate lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, yes, definitely. It seems that the automatic comment formatter I ran is a bit eager.

python-313/typing/readonly.py Show resolved Hide resolved
Comment on lines 47 to 48
# Only allowed to use PythonVersion instead of Version if the fields are ReadOnly
print(get_version_info(py313))
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this counter-intuitive since the Version and PythonVersion classes specify separate types that don't belong to the same type hierarchy. They share the same structure, so they're essentially the same type by means of static duck typing, but they don't explicitly define a protocol. I guess, both are dicts with the same set of key-value pairs, so that should be enough for the type checker to treat them as equals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I believe that TypedDict is all about structural typing. The PEP talks a bit about how the capabilities of ReadOnly can be done with some complicated use of protocols instead.

I haven't quite internalized the rules for when one TypedDict can pass as the other, but everytime I sit down and think for a while, it seems to add up 🙈

Use PyLance in VS Code by setting Python › Analysis: Type Checking Mode or run
the Pyright CLI:

$ python -m pip install pyright $ pyright --pythonversion 3.13 .
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these two commands be on separate lines?

Comment on lines +72 to +79
concatenate("three", "thirteen")
add(3, 13)
VersionType(3, 13)

version = Version(3, 13)
version.increase("patch")
print(version)
print(version.bugfix)
Copy link
Contributor

Choose a reason for hiding this comment

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

PyCharm is smart enough to recognize the new decorator and uses strike-through formatting:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. Yes, that looks quite similar to VS Code. I'll add PyCharm to the top comment.

image

@gahjelle
Copy link
Contributor Author

Thanks for the review @bzaczynski I've done a few updates to the extra typing files!

@brendaweles brendaweles merged commit 9407c12 into master Sep 27, 2024
1 check passed
@brendaweles brendaweles deleted the python-313-examples branch September 27, 2024 18:17
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