python-tutorial icon indicating copy to clipboard operation
python-tutorial copied to clipboard

Errors found in the `object-oriented` notebook

Open despadam opened this issue 1 year ago • 1 comments

despadam avatar May 08 '24 07:05 despadam

more of a general comment, not section-specific: we do not reveal the solution when the syntax is incorrect

despadam avatar May 08 '24 09:05 despadam

Will add a few simpler exercises

despadam avatar Oct 22 '24 10:10 despadam

more of a general comment, not section-specific: we do not reveal the solution when the syntax is incorrect

Should we?

edoardob90 avatar Nov 08 '24 17:11 edoardob90

more of a general comment, not section-specific: we do not reveal the solution when the syntax is incorrect

Should we?

@edoardob90 I think not. A more intuitive message for syntax errors would be very useful in these cases, but I think that providing the full solution at that stage would be counter-productive.

despadam avatar Nov 11 '24 08:11 despadam

Damn it, I noticed this now while testing AI against the new notebook:

class Person:
        def __init__(self, first_name, last_name, age):
            self.first_name = first_name
            self.last_name = last_name
            self.age = age

a = Person("Pippo", "Balestra", 45)
b = Person("Pippo", "Balestra", 45)

a == b # Always False, because without __eq__ Python compares objects' id

@despadam Do we want to fix it or let it be?

edoardob90 avatar Nov 15 '24 18:11 edoardob90

Damn it, I noticed this now while testing AI against the new notebook:

class Person:
        def __init__(self, first_name, last_name, age):
            self.first_name = first_name
            self.last_name = last_name
            self.age = age

a = Person("Pippo", "Balestra", 45)
b = Person("Pippo", "Balestra", 45)

a == b # Always False, because without __eq__ Python compares objects' id

@despadam Do we want to fix it or let it be?

I deliberately do not make the a == b comparison when testing for this reason, it is doomed to fail. For example, if you look at Example 4 and Exercise 3, I am only testing that the results of the comparisons are the same. If this error is just a result of experimenting then I think it is okay to leave it as is. In the theoretical part about comparisons we explain why this fails. So then they are free to play around and get more answers from the AI tools if they wish.

despadam avatar Nov 15 '24 19:11 despadam

Or add:

# Validate __eq__ is implemented
    assert (
        "__eq__" in solution_result_a.__class__.__dict__
    ), "Person class must implement __eq__ method for proper equality comparison"

But I'll let you decide since you are covering this material in the tutorial.

edoardob90 avatar Nov 15 '24 19:11 edoardob90

assert hasattr(
        solution_result.__eq__, "__closure__"
    ), "Make sure that the class is properly implementing the __eq__() method."

I validate the comparison methods like this for Exercise 3, but you are right I don't do it for Example 4. I will add it there, but leave the rest of the examples and exercises without this validation. Since the rest of them do not touch the topic of comparison, the users are free to experiment as they wish.

despadam avatar Nov 15 '24 21:11 despadam