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

MicroPython implementation and tests #96

Open
bskinn opened this issue Sep 20, 2019 · 4 comments
Open

MicroPython implementation and tests #96

bskinn opened this issue Sep 20, 2019 · 4 comments
Labels
needs tests Tests are absent or incomplete for this todo Definitely needs doing for a near-term release
Milestone

Comments

@bskinn
Copy link
Owner

bskinn commented Sep 20, 2019

MicroPython types appear not to implement .mro(), in either the Python 2 or Python 3 forms:

>>> str.__bases__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'str' has no attribute '__bases__'
>>> import io
>>> io.StringIO.__bases__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'StringIO' has no attribute '__bases__'
>>> io.StringIO.__mro__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'StringIO' has no attribute '__mro__'
>>> dir(io.StringIO)
['__class__', '__enter__', '__exit__', '__name__', 'close', 'read', 'readinto', 'readline', 'write', 'flush', 'getvalue', 'seek']

Is there a way to introspect the inheritance hierarchy in MP?

Also: Yikes, the MRO itself is not CPython-compliant.

Adapted from original post by @bskinn in #81 (comment)

@bskinn
Copy link
Owner Author

bskinn commented Sep 20, 2019

MicroPython implements a significantly reduced class hierarchy in its io module. Presumably the sys.stdfoo also live on this reduced hierarchy?

At the very least, despite being uio.TextIOWrapper, they appear to have no concept of an internal buffer than can be detached, in addition to a much reduced set of attributes:

$ micropython 
MicroPython v1.11-303-gc8c37ca40 on 2019-09-10; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import sys
>>> type(sys.stdout)
<class 'TextIOWrapper'>
>>> dir(sys.stdout)
['__class__', '__enter__', '__exit__', '__next__', 'close', 'read', 'readinto', 'readline', 'write', 'fileno', 'flush', 'readlines', 'seek', 'tell']

$ python3.7
Python 3.7.4 (default, Sep 12 2019, 13:06:26) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> dir(sys.stdout)
['_CHUNK_SIZE', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_finalizing', 'buffer', 'close', 'closed', 'detach', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'line_buffering', 'mode', 'name', 'newlines', 'read', 'readable', 'readline', 'readlines', 'reconfigure', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'write_through', 'writelines']

@bskinn
Copy link
Owner Author

bskinn commented Sep 28, 2019

Might be worth just testing MP at stdio-mgr v1.0.1, modded to remove attrs.

@bskinn bskinn added needs tests Tests are absent or incomplete for this todo Definitely needs doing for a near-term release labels Sep 28, 2019
@bskinn bskinn added this to the v2.0 milestone Sep 28, 2019
@bskinn
Copy link
Owner Author

bskinn commented Sep 30, 2019

MicroPython appears to have crippled sys, not allowing its members to be set. Other modules are not crippled in this way:

>>> import io
>>> io.foo = "bar"
>>> io
<module 'io' from '/home/pydev/.micropython/lib/io.py'>
>>> dir(io)
['__class__', '__name__', 'open', '__file__', 'BytesIO', 'FileIO', 'IOBase', 'StringIO', 'TextIOWrapper', 'SEEK_SET', 'SEEK_CUR', 'SEEK_END', 'foo']
>>> import sys
>>> sys.foo = "bar"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'foo'
>>> import unittest
>>> unittest.foo = "bar"
>>> dir(unittest)
['__class__', '__name__', 'main', '__file__', 'sys', 'skip', 'foo', 'SkipTest', 'AssertRaisesContext', 'TestCase', 'skipIf', 'skipUnless', 'TestSuite', 'TestRunner', 'TestResult', 'run_class']

@bskinn
Copy link
Owner Author

bskinn commented Oct 1, 2019

Given the above, @jayvdb, I'm at a loss as to how to implement even basic stream wraps/mocks. I think MicroPython may be a nonstarter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Tests are absent or incomplete for this todo Definitely needs doing for a near-term release
Projects
None yet
Development

No branches or pull requests

1 participant