-
Notifications
You must be signed in to change notification settings - Fork 26
Development #22
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
Merged
Merged
Development #22
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
29711e8
Update Python version
gjbex be3d38e
Rerun benchmarks
gjbex a1aa6a9
Add section on default values
gjbex 1ac0374
Fix title
gjbex 23e0b36
Add material requirements
gjbex fcd3d6d
Fix logos
gjbex 1bf89dc
Merge remote-tracking branch 'origin/development' into development
gjbex 28fad82
Add example of a decorator that takes arguments
gjbex bee9797
Improve code foramtting
gjbex 23bf62d
Fix typos
gjbex 38c7836
Merge remote-tracking branch 'origin/development' into development
gjbex f7b0b7f
Fix exception reporting
gjbex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| theme: jekyll-theme-slate | ||
| title: "Python software development" | ||
| theme: jekyll-theme-slate |
Binary file not shown.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import functools | ||
|
|
||
|
|
||
| def check_bounds(min_value, max_value): | ||
| '''Check bounds of a function argument | ||
|
|
||
| Parameters | ||
| ---------- | ||
| min_value: float | ||
| Smallest value allowed for the function's parameter | ||
| max_value: float | ||
| Largest value allowed for the function's parameter | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError: | ||
| If the argument is outside the specified bounds | ||
| ''' | ||
| def check_bounds_wrapper(_func): | ||
| @functools.wraps(_func) | ||
| def wrapper(x): | ||
| if min_value > x or x > max_value: | ||
| raise ValueError(f'argument {x} not in [{min_value}, {max_value}]') | ||
| return _func(x) | ||
| return wrapper | ||
| return check_bounds_wrapper | ||
|
|
||
|
|
||
| @check_bounds(min_value=-1.0, max_value=1.0) | ||
| def silly(x): | ||
| '''Compute a rather uninteresting function | ||
|
|
||
| Parameters | ||
| ---------- | ||
| x: float | ||
| Argument for the function | ||
|
|
||
| Returns | ||
| ------- | ||
| float: | ||
| Value computed by the function | ||
| ''' | ||
| return x**2 - 2.0 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| print(silly(0.5)) | ||
| try: | ||
| print(silly(2.5)) | ||
| except ValueError as e: | ||
| print(f'Exception raised as expected: {e}') | ||
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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.
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.
suggestion: Decorator only supports a single positional argument; consider generalizing to *args/**kwargs or making this constraint explicit.
Currently
check_boundswill throw a genericTypeErrorif used on a function with more than one argument, becausewrapperonly acceptsx. To make this safer, you could definewrapper(*args, **kwargs), forward all arguments to_func, and explicitly check the relevant argument (e.g.,args[0]). If the decorator is intentionally limited to single-argument functions, consider validating_func’s signature up front so incorrect usage fails with a clear error message.