Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[New Concept]: Decorators #2838
[New Concept]: Decorators #2838
Changes from 44 commits
9093c00
bf8e6d2
8398ddc
6e45226
59b9a3c
a05cd9c
935fbc8
3195b1d
f1b475e
fec71c7
3f063cc
2617405
20c603e
38bc6cc
f0ed0b8
2e5a3ce
bb1b05a
b7c51be
dc9d705
066b8fd
9f27365
56d7a6e
961d917
97e06a2
8a26678
155b722
23ad694
5897d62
4cf2503
bea08e9
936193d
bc3d624
99c8662
6721bd4
89e5971
f7d7bd4
844d117
7f7cc5b
324c224
0634ecc
cc93f0a
467d18c
19c4cc6
3a59ddd
26a5434
970ddd5
1dffa4d
a1066e0
fa7101f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? We might want to explain what the problem is being presented to the parser when there is no parenthesis. Or pose it as a "Getting to Deep Dive Python" point…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next commit will include
, as you would in calling any function:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am finding this really hard to follow with all the repeated use of
function
. Could we perhaps disambiguate this a bit by usingdecorating
anddecorated
orwrapping
andwrapped
orinner
andouter
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to change it however you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two sentences seem to repeat whats been said above, so I think they should come out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind them.;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is it?
https://www.youtube.com/watch?v=ED7O4peJ6lw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggests that it either must or may return the original passed in function indirectly. This could be clarified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last line will be changed in the next commit to
The inner_function may or may not return the original, passed-in function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not, for me, clarify the prior sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole paragraph will be rephrased in the next commit to
The inner function returns either
func
or, ifplanet
equalsPluto
, it will print that Pluto is not a planet.It could be coded to raise a
ValueError
instead.So, the inner function wraps
func
, and returns eitherfunc
or does something that substitutes whatfunc
would do.The decorator returns its inner function.
The inner_function may or may not return the original, passed-in function.
Depending on what code conditionally executes in the wrapper function or inner_function,
func
may be returned, an error could be raised, or a value offunc
's return type could be returned.It states and then repeats itself to hopefully be more reinforcing than obfuscatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to add a code example of what this means, so students can see it in action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the next section: Decorators Which Have Their own Parameters.