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

Fix python2 str(circuits.core.values.Value()) #266

Merged
merged 2 commits into from Jul 1, 2019
Merged

Conversation

spaceone
Copy link
Contributor

@spaceone spaceone commented Jan 24, 2019

I am not sure why Value has a __str__ method at all. But it's broken on
python2. It assumes value is always a unicode-string, while coroutines
can return anything, even lists. This causes various crashes.

>>> str(circuits.core.values.Value())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fbest/git/circuits/circuits/six.py", line 854, in <lambda>
    klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
  File "/home/fbest/git/circuits/circuits/core/values.py", line 78, in __str__
    return self.value.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'

I am not sure why Value has a __str__ method at all. But it's broken on
python2. It assumes value is always a unicode-string, while coroutines
can return anything, even lists. This causes various crashes.

>>> str(circuits.core.values.Value())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fbest/git/circuits/circuits/six.py", line 854, in <lambda>
    klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
  File "/home/fbest/git/circuits/circuits/core/values.py", line 78, in __str__
    return self.value.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'
@prologic
Copy link
Member

It exists mostly for debugability.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@5f3a327). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #266   +/-   ##
=========================================
  Coverage          ?   74.49%           
=========================================
  Files             ?       74           
  Lines             ?     6665           
  Branches          ?        0           
=========================================
  Hits              ?     4965           
  Misses            ?     1700           
  Partials          ?        0
Impacted Files Coverage Δ
circuits/core/values.py 88.15% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f3a327...63ca8a8. Read the comment docs.

@prologic prologic merged commit e7fa27b into master Jul 1, 2019
@spaceone spaceone deleted the fix-str-value branch July 1, 2019 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants