Almost all Python classes implement __repr__ incorrectly, preventing normal use of help or printing of nested structures.

Description

Python __repr__ function should not print anything to the console, it should just return an internal representation of the instance, that can ideally be processed.
https://docs.python.org/3/reference/datamodel.html#object.__repr__

In the same way, __str__ should not call print either, just return the string that's is going to be printed when user calls print on the object!
https://docs.python.org/3/reference/datamodel.html#object.__str__

Many objects in h2o, also implement show: this methods is used to print complex objects.
Although, it seems to serve the same goal as print(obj).
We can keep it for backwards compatibility but the printable string of an instance should be the result of __str__ implementation, so that:

 

Among the side effects of this:

  • in IPython/Jupyter instance details are printed when inspecting method using inst.method?, inst.method??.

  • for debugging, for example when printing request results, we don't have the choice between printing repr() or str() (default), so that it prints some of its nested values BEFORE its keys... making this unreadable, non-parsable...

 

As a default implementation for __repr__ in H2O classes, I would suggest something like:

 

Status

Assignee

New H2O Bugs

Fix versions

Reporter

Sebastien Poirier

Support ticket URL

None

Labels

None

Affected Spark version

None

Customer Request Type

None

Task progress

None

CustomerVisible

No

Components

Priority

Major
Configure