Skip to content

Commit

Permalink
Merge pull request #2 from gramaziokohler/fix-getattr
Browse files Browse the repository at this point in the history
Fixed bug failing to get a `str` representation of `Message` on `ipy`
  • Loading branch information
gonzalocasas authored Sep 5, 2023
2 parents 82b1ba0 + b6e2b78 commit 8398bfe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Fixed bug failing to get a `str` representation of `Message` on `ipy`

### Removed


Expand Down
5 changes: 4 additions & 1 deletion src/compas_eve/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ class Message(UserDict):
A message is fundamentally a dictionary and behaves as one."""

def __str__(self):
return str(self.data)

def __getattr__(self, name):
return self.data[name]
return self.__dict__["data"][name]

@classmethod
def parse(cls, value):
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ def callback(msg):
assert received, "Message not received"
assert result["value"].name == "Jazz"
assert result["value"].hello_name == "Hello Jazz"


def test_message_str():
msg = Message(a=3)
assert str(msg) == "{'a': 3}"

0 comments on commit 8398bfe

Please sign in to comment.