Errors found in the `object-oriented` notebook
more of a general comment, not section-specific: we do not reveal the solution when the syntax is incorrect
Will add a few simpler exercises
more of a general comment, not section-specific: we do not reveal the solution when the syntax is incorrect
Should we?
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.
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?
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.
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.
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.