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

from __future__ import unicode_literals breaks fysom #31

Open
sjlongland opened this issue Mar 13, 2017 · 4 comments
Open

from __future__ import unicode_literals breaks fysom #31

sjlongland opened this issue Mar 13, 2017 · 4 comments

Comments

@sjlongland
Copy link

The unicode_literals feature is a way to get Python 2.7 code to behave a little more like 3.x code by assuming that string literals are Unicode strings rather than byte strings.

Unfortunately, it breaks fysom:

RC=0 stuartl@rikishi /tmp/fysom $ cat test.py 
from __future__ import unicode_literals
from fysom import Fysom

fysom = Fysom({
            'initial': 'green',
            'events': [
                {'name': 'warn', 'src': 'green', 'dst': 'yellow'},
                {'name': 'panic', 'src': 'yellow', 'dst': 'red'},
                {'name': 'calm', 'src': 'red', 'dst': 'yellow'},
                {'name': 'clear', 'src': 'yellow', 'dst': 'green'},
                {'name': 'warm', 'src': 'green', 'dst': 'blue'}
            ]
        })
RC=0 stuartl@rikishi /tmp/fysom $ python3 test.py 
RC=0 stuartl@rikishi /tmp/fysom $ python2 test.py 
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    {'name': 'warm', 'src': 'green', 'dst': 'blue'}
  File "/usr/lib64/python2.7/site-packages/fysom/__init__.py", line 124, in __init__
    self._apply(cfg)
  File "/usr/lib64/python2.7/site-packages/fysom/__init__.py", line 195, in _apply
    setattr(self, name, self._build_event(name))
  File "/usr/lib64/python2.7/site-packages/fysom/__init__.py", line 261, in _build_event
    fn.__name__ = event
TypeError: __name__ must be set to a string object
@mriehl
Copy link
Owner

mriehl commented Mar 14, 2017 via email

sjlongland pushed a commit to vrtsystems/fysom that referenced this issue Mar 14, 2017
Python 3 is happy to receive `__name__` objects as Unicode or plain
strings, but Python 2 is not.  This bug shows itself when
`unicode_literals` is imported from calling code.

mriehl#31
@sjlongland
Copy link
Author

I've just quickly thrown together a pull request with a possible fix. I'll see if I can put a quick test case in.

@mriehl
Copy link
Owner

mriehl commented Mar 14, 2017

Cool thanks. I'll try to make room for a release tomorrow

@sjlongland
Copy link
Author

sjlongland commented Mar 14, 2017 via email

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

No branches or pull requests

2 participants