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

Allow write() to print non-string objects #34

Closed
sebageek opened this issue Apr 18, 2019 · 4 comments · Fixed by #111
Closed

Allow write() to print non-string objects #34

sebageek opened this issue Apr 18, 2019 · 4 comments · Fixed by #111

Comments

@sebageek
Copy link
Contributor

As I have to use write() in a yaspin context instead of print() I tend to use it in a similar way. This often includes printing non-string objects. print() calls repr() automatically on anything that is not a string, whereas yaspin runs into an assertion.

Would you be open to replace that assertion with something just calling repr() on the given text? This coud also be implemented for the spinner text itself. I'd also volunteer to bring up a PR for this.

@pavdmyt
Copy link
Owner

pavdmyt commented Apr 22, 2019

@sebageek feel free to open the PR.

sebageek added a commit to sebageek/yaspin that referenced this issue Jun 4, 2019
write() now supports printing multiple args, e.g. write("foo", "bar")
and also converts objects that are not a string to their string
representation.

Fixes pavdmyt#34
@sebageek
Copy link
Contributor Author

As #37 was rejected are there still ambitions to implement this feature? If the problem is that #37 was implementing too much of the print() logic (i.e. the multiple arguments) I can implement this by just calling str() on the one argument we get. If not this bug can probably just be closed.

@pavdmyt
Copy link
Owner

pavdmyt commented Aug 17, 2019

It seems that I don't completely understand the issue. Let's try to sort out the details.

print() calls repr() automatically on anything that is not a string, whereas yaspin runs into an assertion

I agree that calling repr on non-string objects makes sense for write method. #37 was focused on implementing *args logic and missed repr for non-string objects. I declined it mostly because of composing strings from *args which I think should be better handled outside of yaspin.

I'm still open for PR which allows to use non-string objects as arguments to write. However, it seems that there is no point in putting non-string object into write as just a single argument. Probably, most of the times user wants to mix string with non-string (which should be handled by user).

sebageek added a commit to sebageek/yaspin that referenced this issue Feb 8, 2021
Allow write() to print anything that is not a string by converting it
via str(), just like the builtin print() does.

Fixes pavdmyt#34
sebageek added a commit to sebageek/yaspin that referenced this issue Feb 9, 2021
Allow write() to print anything that is not a string by converting it
via str(), just like the builtin print() does.

Fixes pavdmyt#34
sebageek added a commit to sebageek/yaspin that referenced this issue Feb 18, 2021
Allow write() to print anything that is not a string by converting it
via str(), just like the builtin print() does.

Fixes pavdmyt#34
@pavdmyt
Copy link
Owner

pavdmyt commented Feb 21, 2021

Included in yaspin v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants