-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add supporting code for Python Optional Arguments tutorial #702
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
Conversation
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.
Pull Request Overview
This PR adds supporting code files for a Real Python tutorial on Python optional arguments. The code demonstrates various patterns for working with optional parameters, including proper handling of mutable defaults and the use of *args and **kwargs.
- Provides working examples of safe optional parameter patterns using None defaults
- Demonstrates the mutable default bug and how to avoid it
- Includes examples of variadic functions using *args and **kwargs
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Provides overview and instructions for the tutorial code |
| optional_params.py | Main examples showing proper optional parameter patterns |
| optional_params_mutable_default_bug.py | Demonstrates the dangerous mutable default antipattern |
| optional_params_unpacking_demo.py | Simple demonstration of argument unpacking with * operator |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
|
@bzaczynski Copilot suggested to add quantity checks to the two functions that add to the shopping list via IMO the tutorial focuses the code on the essential aspect (how do |
| def add_item(item_name, quantity, shopping_list=None): | ||
| """Add (or increment) an item in a list using the safe 'None' default.""" | ||
| if shopping_list is None: | ||
| shopping_list = {} |
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.
🔧 Technical Recommendation
The name shopping_list may imply Python's list data structure, while we actually use the variable to store a Python dictionary. How about renaming this variable to shopping_items or item_quantities instead?
bzaczynski
left a comment
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.
@martin-martin This looks good to me. I'd only consider renaming some of the variables for better clarity, but it's not a big deal at all!
Where to put new files:
my-awesome-articleHow to merge your changes: