-
Notifications
You must be signed in to change notification settings - Fork 30
Object-oriented
: add __eq__
validation in Example 4
#262
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
edoardob90
merged 2 commits into
main
from
239-fix/errors-found-in-the-object-oriented-notebook
Nov 18, 2024
Merged
Object-oriented
: add __eq__
validation in Example 4
#262
edoardob90
merged 2 commits into
main
from
239-fix/errors-found-in-the-object-oriented-notebook
Nov 18, 2024
Conversation
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
Object-oriented
: add _eq__
validation in Example 4Object-oriented
: add __eq__
validation in Example 4
edoardob90
approved these changes
Nov 18, 2024
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.
Ship it! 🚢
Comment on lines
+16
to
+26
# NOTE: | ||
# When testing the classes returned by the solutions function in the Examples 1-4 | ||
# we often need to check if a class method is implemented and it's using the right attributes. | ||
# One way to check both is to check if the class's method has the __closure__ attribute. | ||
# Why? | ||
# 1. If __method__ is not implemented, Python will fetch object.__method__ instead, which obviously is not a closure | ||
# `hasattr(solution_result.__method__, "__closure__")` will return False. | ||
# 2. If __method__ is implemented, but it's not using the class attributes, it will be a closure | ||
# `solution_result.__method__.__closure__ is None` will return False. | ||
# Reference: https://github.com/empa-scientific-it/python-tutorial/pull/249#discussion_r1836867387 | ||
|
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 just added this comment to our future-selves to understand why we're using __closure__
in some test.
edoardob90
added a commit
that referenced
this pull request
Nov 20, 2024
* UI revamp WIP * `Object-oriented`: Add simpler examples, update quiz and exercises (#249) * add 2 new examples * finish new examples * finish new examples pt2 * update new examples with docstrings and improved tests * add docstrings * finish docstrings * make sure that class methods are only using the class attributes to produce their results * test that the return value is an instance of a custom class * use closure to check for usage of class attributes * update property section and quiz * Expand docstring description of Exercise 4 * finish updating the exercises * Minor changes * Stupid metadata fix of the ipython notebook * Fixing * Replacing variable l: E741 Ambiguous variable name: `l` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: edoardob90 <edoardob90@gmail.com> Co-authored-by: Snowwpanda <pascal.su@empa.ch> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Revamp UI of AI widgets * Resolve flake8 errors * Fix more UI inconsistencies * Fix test in Object-Oriented Example 4 (#262) * Add __eq__ validation in Example 4 * Add a comment to explain the rationale behind __closure__ testing --------- Co-authored-by: edoardob90 <edoardob90@gmail.com> * Fix errors found in the `input_output` notebook (#258) * Fixing some issues with the input_output notebook and changing some exercies a bit. * Added an exercise to input_output notebook * Added Docstrings to exercises * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Changes for pre-commit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Variable naming consistent in tests. * Reformulation program execution Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> * Review from despina fixes * Resetting inputfiles after exercises (after writing to file is explained) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * to_bytes function needs byteorder --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> * Move quizzes to dedicated folder (#263) * move quizes to folder * Rename: quizes -> quiz --------- Co-authored-by: edoardob90 <edoardob90@gmail.com> --------- Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> Co-authored-by: Snowwpanda <pascal.su@empa.ch> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #239
Plus fixes some cosmetic changes.