Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sagemaker-core/src/sagemaker/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def pascal_to_snake(pascal_str):


def is_not_primitive(obj):
return not isinstance(obj, (int, float, str, bool, datetime.datetime))
return not isinstance(obj, (int, float, str, bool, bytes, datetime.datetime))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor: there are now two consecutive blank lines after the function body (the added blank line plus the existing one). PEP 8 expects exactly two blank lines between top-level definitions, so this results in three blank lines total. CI formatting checks (black/flake8) should catch this, but worth fixing proactively.

Same issue applies at line 290 (is_primitive_class).




def is_not_str_dict(obj):
Expand All @@ -285,7 +286,8 @@ def is_primitive_list(obj):


def is_primitive_class(cls):
return cls in (str, int, bool, float, datetime.datetime)
return cls in (str, int, bool, float, bytes, datetime.datetime)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same extra blank line issue here — three blank lines between is_primitive_class and class Unassigned.




class Unassigned:
Expand Down
25 changes: 25 additions & 0 deletions sagemaker-core/tests/unit/generated/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,31 @@ def test_serialize_method_nested_shape():
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: There's an extra blank line here (two blank lines between test functions inside the same module is fine per PEP 8 for top-level definitions, but the rest of this test file uses single blank lines between test functions). Minor, but worth keeping consistent with the existing file style.



def test_serialize_with_bytes_value_returns_bytes():
result = serialize({"body": b"1"})
assert result == {"body": b"1"}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test, but the comment describes an implementation detail (walrus operator in _serialize_dict) that could become stale if the implementation changes. Consider rephrasing to describe the behavior rather than the implementation:

Suggested change
# Empty bytes is falsy, so serialize omits it from the result
result = serialize({"body": b""})
assert result == {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The comment here is helpful for understanding the behavior, but it's worth noting that this test documents a potentially surprising behavior — users might expect b"" to be preserved in the output (similar to how 0 or False might be treated). If the _serialize_dict walrus operator skips all falsy values, that could also affect 0, False, "", etc. This isn't a problem with your PR, but worth flagging as a pre-existing behavior that may warrant a follow-up discussion.

def test_serialize_with_empty_bytes_returns_empty_dict():
# Empty bytes is falsy, so the walrus operator in _serialize_dict skips it
result = serialize({"body": b""})
assert result == {}


def test_serialize_with_bytes_in_list():
result = serialize([b"hello", b"world"])
assert result == [b"hello", b"world"]


def test_is_not_primitive_with_bytes_returns_false():
assert is_not_primitive(b"test") is False


def test_is_primitive_class_with_bytes_returns_true():
assert is_primitive_class(bytes) is True


class TestUnassignedBehavior:
"""Test Unassigned class methods for proper behavior.

Expand Down
Loading