Commit 596e018f authored by Trond Aasan's avatar Trond Aasan
Browse files

Call repr on self.data

__str__ and __repr__ aren't always the same
parent 50255a3b
Pipeline #87083 passed with stage
in 37 seconds
......@@ -45,9 +45,7 @@ class Tree(Generic[T]):
def __repr__(self):
children = ", ".join(list(map(repr, self.children)))
return (
f"Tree(data={self.data}, id_key={repr(self.id_key)}, children=[{children}])"
)
return f"Tree(data={repr(self.data)}, id_key={repr(self.id_key)}, children=[{children}])"
def __eq__(self, other):
return all(
......
import itertools
from typing import NamedTuple, Optional, List
from typing import Optional, List
import pytest
......@@ -26,10 +25,23 @@ def test_poetry_version():
assert version == __version__
class Node(NamedTuple):
class Node:
id: Optional[int]
parent_id: Optional[int]
def __init__(self, id=None, parent_id=None):
self.id = id
self.parent_id = parent_id
def __repr__(self) -> str:
return f"Node(id={repr(self.id)}, parent_id={repr(self.parent_id)})"
def __eq__(self, o) -> bool:
return o.id == self.id and o.parent_id == self.parent_id
def __str__(self) -> str:
return f"id={self.id} parent_id={self.parent_id}"
def _build_forest(items: List[Node]):
return build_forest(items, "id", "parent_id")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment