Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Fix handling of bytes #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion boundary_layer/builders/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def format_value(value):

return '{{ {items} }}'.format(items=','.join(pairs))

if isinstance(value, (int, float, type(None))):
if isinstance(value, (int, float, type(None), bytes)):
Copy link
Contributor

@vchiapaikeo vchiapaikeo Jul 22, 2021

Choose a reason for hiding this comment

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

If we want to support bytes, we should just return the bytes and not pass it through the str function. e.g.,

if isinstance(value, bytes):
    return value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vchiapaikeo I considered that, however since this function is returning exclusively strs apart from this, I wanted to keep the return type uniform. I understand that now with jinja this is not causing problems. However, what if someone decorated this method call with more logic thinking they were getting a str and instead got bytes? Maybe this is not a problem and i am overthinking

return str(value)

if isinstance(value, (datetime.datetime, datetime.timedelta, GenericNamedParameterPasser)):
Expand Down
2 changes: 2 additions & 0 deletions test/builders/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def test_format_value():

assert util.format_value(None) == 'None'

assert util.format_value(b'hello world') == "b'hello world'"

with pytest.raises(Exception):
assert util.format_value(set(10))

Expand Down