-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-106625 : Add missing code to tutorial 4.6 example #106623
Conversation
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
That example is after the statement "You can use positional parameters with some builtin classes that provide an ordering for their attributes (e.g. dataclasses)." Using dataclass before the statemnt is bit misleading. In your case, following code would work. p = Point()
p.x = 0
p.y = 42
where_is(p) Of course, it is ugly. But the first example should demonstrate that named argument pattern like Instead, I think this makes the first example better. class Point:
def __init__(self, x, y):
self.x = x
self.y = y With this Point class, user will understand that even typehint for attributes are not necessary for |
Reading @methane 's comment after fixing the example as a dataclass, I agree. The example follows "f you are using classes to structure your data you can use the class name followed by an argument list resembling a constructor, but with the ability to capture attributes into variables:". To me also, this implies a regular class with a contructor ( |
Thanks for the review. |
@RustyNail I already made the change. Note that dunder names with double underscores need to be surrounded by backticks to display properly in GitHub comments. Otherwise the underscores are seen as markup. Compare 'init' with bolder 'init' with |
@terryjreedy |
I agree, too. |
Thanks @RustyNail for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…106623) * Added missing import statement. * Update Doc/tutorial/controlflow.rst * Update Doc/tutorial/controlflow.rst * Update controlflow.rst * Make point regular class with __init__. --------- (cherry picked from commit d0b7e18) Co-authored-by: RustyNail <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
GH-106636 is a backport of this pull request to the 3.12 branch. |
…106623) * Added missing import statement. * Update Doc/tutorial/controlflow.rst * Update Doc/tutorial/controlflow.rst * Update controlflow.rst * Make point regular class with __init__. --------- (cherry picked from commit d0b7e18) Co-authored-by: RustyNail <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
GH-106637 is a backport of this pull request to the 3.11 branch. |
… (#106637) (cherry picked from commit d0b7e18) Co-authored-by: RustyNail <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
… (#106636) (cherry picked from commit d0b7e18) Co-authored-by: RustyNail <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
This is a pull request for the sample code in section 4.6.
I ran the following based on the sample code and got an error.
The sample code in the tutorial may be an excerpt of some code.
However, given that we will try "Point(1, var)" immediately following, I believe the user will easily understand that there is a necessary dataclass import statement.
Executed code :
Errors that occurred :
📚 Documentation preview 📚: https://cpython-previews--106623.org.readthedocs.build/