Giter Site home page Giter Site logo

py-ts-interfaces's People

Contributors

aadamz5 avatar cs-cordero avatar davidszotten avatar gjulianm avatar laike9m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

py-ts-interfaces's Issues

Why no support for datetime

This utility is exactly what I was looking for, but --

Why is there no support for transpility Python datetime to Javscript Date not supported? Both objects support the same string and binary representations.

I would hate to give up my Python datetime properties. Is there a suggested workaround?

Support exporting interfaces generated

Thanks for this awesome work, but I found that the interfaces generated may not be exported from single ts file. So is it possible to add a new configure parameter to control export this interface or not? Thanks!

Support for inheritance?

Hey - quick question: does the module support inheritance?

If I have

from dataclasses import dataclass
from py_ts_interfaces import Interface
from typing import get_type_hints as gth

@dataclass
class Simple(Interface):
    x: int
    y: str

@dataclass
class Simple2(Simple, Interface):
    z: str

print(gth(Simple2))

then I should have Simple2 have elements x, y and z. That's confirmed by get_type_hints, which returns

{'x': <class 'int'>, 'y': <class 'str'>, 'z': <class 'str'>}

But when I run py-ts on this I get an interface of:

interface Simple {
    x: number;
    y: string;
}

interface Simple2 {
    z: string;
}

...so Simple2 is missing the members x and y it should inherit from Simple.

Support for Dicts?

Hi all,

great module, and perfect for what we need.

However I'm wondering about support for Dict types. I checked the docs and it doesn't make any mention of support for them - either planned, or will not support.

We've got a set of composed and inherited dataclasses, where for a couple we have elements that are Dict's. These are defined in a library module used by a set of multiple separate 'test' applications within a common framework type design.
So the interfaces are defined in a library to ensure consistency between them - however each test will generate some slight variations in some output data, and so we use Dict in the interface to handle the variations of each specific test.

In the example below, I have a MaterialData concrete class that has a Dict of Material - but this will fail with py-ts-interface because Dict are not supported:

@dataclass
class Material(Interface):
    mean: float
    stddev: float

@dataclass
class TestData(Interface):
    # abstract class
    pass

@dataclass
class MaterialData(TestData, Interface):
    values: Optional[Dict[str, Material]] = None

The use case here is that we have different tests generating the data above, but different tests will have different materials in them, and so there isn't (at a high level) a pre-defined list of material types, so we can't do something like:

@dataclass
class MaterialData(TestData, Interface):
    concrete: Material
    sand: Material
    water: Material
    ....

We could remove the need to use Dict by sub-classing MaterialData for each test, and in the child class defining the list of materials required for that test.
However, in this case we would no longer have a generic common library level interface for all our specific 'tests', but instead would need to create the TS interface on each test separately.

thanks for your thoughts!
Richard

Add Support for Python 3.8+

it says those are supported, but i'm having trouble getting it to work. I am primarily a TS developer and not experienced with python just as FYI, I may be missing something silly.

from dataclasses import dataclass
from py_ts_interfaces import Interface
from typings import Optional, Union

@dataclass
class Thing(Interface):
    show: bool
    value: float
    optional_field: Union[str, None] = None
from dataclasses import dataclass
from py_ts_interfaces import Interface
from typings import Optional, Union

@dataclass
class Thing(Interface):
    show: bool
    value: float
    optional_field: Optional[str] = None

first example gets me this:

AttributeError: 'ClassDef' object has no attribute 'value'

second attempt gets me this:

AttributeError: 'Name' object has no attribute 'value'

what am I missing?

Support for datetime

Hey, would be great to add support for datetime.datetime.

Example:

from dataclasses import dataclass
from datetime import datetime
from py_ts_interfaces import Interface

@dataclass 
class Foo(Interface):
     bar: datetime

would give us

interface Foo{
     bar: Date;
}

[Feature Request] ts-py-interfaces wanted

Hi,

I'm a TypeScript fan and your project is fantastic.

Currently, I'm working on a project that translates a medium-size TypeScript project into Python.

There are lots of interfaces defined in the TypeScript. So it would be a huge help if your project can translate the basic TypeScript Interfaces into Python Data Class.

Do you have any plan to support the basic types from TS to PY, or do you know any project can do this job?

Thank you very much, and I hope you have a nice day!

Huan.

Support for nested data classes

I'm trying to nest one data class in another:

@dataclass
@dataclass_json
class A(Interface):
  member: int

@dataclass
@dataclass_json
class B(Interface):
  inner_list: List[A]

This fails with

File "project/lib/python3.7/site-packages/py_ts_interfaces/parser.py", line 102, in helper
type_value = TYPE_MAP[node.name]
KeyError: 'A'

Are nested classes supported or it is not supposed to work?

Error when trying to get interface for nested inner dataclasses

Hi there,
I've got a dataclass which is a composition of basic types and dataclasses. Rather than have to define all the dataclasses at the top level, I'm trying to make them into nested definition.

That's confusing, here is what I mean:

Flat top-level definitions:

@dataclass
class Meta(Interface):
    color: str 
    size: float

@dataclass
class Point(Interface):
    x: float
    y: float
    meta: Meta

point1 = Point(x=1, y=2,
               meta=Meta(color='red', size=5.5))

Nested definition - where I'm using inner classes:

@dataclass
class Point(Interface):

    @dataclass
    class Meta(Interface):
        color: str 
        size: float

    x: float
    y: float
    meta: Meta

point1 = Point(x=1, y=2,
               meta=Point.Meta(color='red', size=5.5))

The nested inner class approach works fine, and mypy has no problems with it.

But while the first case will get an interface when using py-ts-interfaces, the second (nested) case wont. I get an error saying:

RuntimeError: Invalid nested Interface reference 'Meta' found for interface Point!
Does 'Meta' exist and is it an Interface?

I've tried this both when Meta is inherited from Interface, or not. In both cases it throws an exception

Any thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.