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

Add support for MyPy types in data blocks #276

Closed
jonathanplatzer opened this issue Jun 26, 2017 · 2 comments
Closed

Add support for MyPy types in data blocks #276

jonathanplatzer opened this issue Jun 26, 2017 · 2 comments

Comments

@jonathanplatzer
Copy link

jonathanplatzer commented Jun 26, 2017

It would be great if MyPy types would be allowed in data blocks.

If I understand the way that the immutability of the data block is achieved, by using a _coconut.collections.namedtuple, this could be easily implemented by using MyPys own NamedTuple.

So this

data User(uid: int, username: str, friends: List[User])
   ...

could be compiled to this:

from typing import NamedTuple

class User(NamedTuple("User", [('uid', int), 
                               ('username', str), 
                               ('friends', List[User])])):
   ...
@evhub evhub added the feature label Jun 26, 2017
@evhub evhub added this to the v1.3.0 milestone Jun 26, 2017
@evhub
Copy link
Owner

evhub commented Jun 26, 2017

@jonathanplatzer That's a great idea! There is the issue that typing doesn't exist on old Python versions, but I think I can get around that via stub file magic (real _coconut.NamedTuple uses collections.namedtuple, but stub file _coconut.NamedTuple uses typing.NamedTuple).

evhub added a commit that referenced this issue Aug 5, 2017
@evhub evhub added the resolved label Aug 5, 2017
@evhub
Copy link
Owner

evhub commented Aug 5, 2017

@jonathanplatzer This is now live in coconut-develop! Just pip install coconut-develop to test it out.

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

No branches or pull requests

2 participants