Skip to content

Commit

Permalink
Merge pull request #2113 from tamakoshi2001/improve_qutip.settings
Browse files Browse the repository at this point in the history
Moved compile at the end and modified its content.
  • Loading branch information
Ericgig committed Mar 15, 2023
2 parents 8cc88af + 639d7ae commit fd89a25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/changes/2113.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve print(qutip.settings) by make it shorter
10 changes: 7 additions & 3 deletions qutip/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ def __setitem__(self, key, value):
# Let the dict catch the KeyError
self.options[key] = value

def __repr__(self):
def __repr__(self, full=True):
out = [f"<{self.__class__.__name__}("]
for key, value in self.options.items():
out += [f" '{key}': {repr(value)},"]
if full or value != self._options[key]:
out += [f" '{key}': {repr(value)},"]
out += [")>"]
return "\n".join(out)
if len(out)-2:
return "\n".join(out)
else:
return "".join(out)

def __enter__(self):
self._backup = getattr(settings, self._settings_name)
Expand Down
3 changes: 2 additions & 1 deletion qutip/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ def colorblind_safe(self, value):
def __str__(self):
lines = ["Qutip settings:"]
for attr in self.__dir__():
if not attr.startswith('_') and attr != "core":
if not attr.startswith('_') and attr not in ["core", "compile"]:
lines.append(f" {attr}: {self.__getattribute__(attr)}")
lines.append(f" compile: {self.compile.__repr__(full=False)}")
return '\n'.join(lines)

def __repr__(self):
Expand Down

0 comments on commit fd89a25

Please sign in to comment.