Skip to content

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
merged 2 commits into from
Nov 18, 2024

Conversation

despadam
Copy link
Contributor

Closes #239
Plus fixes some cosmetic changes.

@despadam despadam linked an issue Nov 16, 2024 that may be closed by this pull request
@despadam despadam requested a review from edoardob90 November 16, 2024 14:01
@despadam despadam self-assigned this Nov 16, 2024
@despadam despadam added the upcoming tutorial Stuff to work on/fix before the next tutorial label Nov 16, 2024
@despadam despadam changed the title Object-oriented: add _eq__ validation in Example 4 Object-oriented: add __eq__ validation in Example 4 Nov 16, 2024
Copy link
Member

@edoardob90 edoardob90 left a 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

Copy link
Member

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 edoardob90 merged commit 656d3d2 into main Nov 18, 2024
1 check passed
@edoardob90 edoardob90 deleted the 239-fix/errors-found-in-the-object-oriented-notebook branch November 18, 2024 11:27
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
Labels
upcoming tutorial Stuff to work on/fix before the next tutorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors found in the object-oriented notebook
2 participants