dbrattli / OSlash

Functors, Applicatives, And Monads in Python
MIT License
708 stars 50 forks source link

Python 3.7 support #16

Closed dunossauro closed 3 years ago

dunossauro commented 5 years ago

Hello @dbrattli, I tried to install oslash on python 3.7 and has some problems in runtime. (see full stacktrace).

I would like to fix that if you want.

These error is related List.__str__.

In [2]: oslash.List([1,2,3])                                                                   
Out[2]: ---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~/.local/share/virtualenvs/tests-mSusHyBX/lib/python3.7/site-packages/oslash/list.py in __iter__(self)
     98             if xs.null():
---> 99                 raise StopIteration
    100 

StopIteration: 

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):
--> 402                             return _repr_pprint(obj, self, cycle)
    403 
    404             return _default_pprint(obj, self, cycle)

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    695     """A pprint that just redirects to the normal repr function."""
    696     # Find newlines and replace them with p.break_()
--> 697     output = repr(obj)
    698     for idx,output_line in enumerate(output.splitlines()):
    699         if idx:

~/.local/share/virtualenvs/tests-mSusHyBX/lib/python3.7/site-packages/oslash/list.py in __repr__(self)
    115         """Return string representation of List.
    116         """
--> 117         return str(self)
    118 
    119     def __eq__(self, other: 'List') -> bool:

~/.local/share/virtualenvs/tests-mSusHyBX/lib/python3.7/site-packages/oslash/list.py in __str__(self)
    110         """Return string representation of List.
    111         """
--> 112         return "[%s]" % ", ".join([str(x) for x in self])
    113 
    114     def __repr__(self) -> str:

~/.local/share/virtualenvs/tests-mSusHyBX/lib/python3.7/site-packages/oslash/list.py in <listcomp>(.0)
    110         """Return string representation of List.
    111         """
--> 112         return "[%s]" % ", ".join([str(x) for x in self])
    113 
    114     def __repr__(self) -> str:

RuntimeError: generator raised StopIteration

Related #4

Technologicat commented 5 years ago

You probably know already, but just commenting here that this seems related to PEP 479 - it's likely the generator should be just using return to shut itself down instead of raising StopIteration.

The "new" behavior - which was introduced already in Python 3.5 - is that if a generator raises StopIteration, that is converted to a RuntimeError, which is exactly what the above stack trace has. This change was made for technical reasons, as it made some things simpler in the async stuff added in Python 3.5. See PEP 492.

tomkp75 commented 4 years ago

14 should get rid of it. It hasn't been pushed to pypi though. You can use this dependency instead:

git+https://github.com/dbrattli/OSlash.git

dbrattli commented 3 years ago

OSlash has now been ported to Python 3.8. Will publish a new release shortly.