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

Python Type Hints #3

Open
chuck-adaptive opened this issue May 4, 2023 · 0 comments
Open

Python Type Hints #3

chuck-adaptive opened this issue May 4, 2023 · 0 comments

Comments

@chuck-adaptive
Copy link
Collaborator

Python is an interpreted language - but they've recently added type hint support

Type the functions we've created and potentially provide some out of the box Python types

There are some libraries that do this automatically

https://pypi.org/project/ts2python/

But I haven't fully evaluated them

The key thing here is to make a best effort to encapsulate the Typescript types in Python.

in my research, I liked this comparison

// Typescript

interface Icon {
  src: string;
  size?: string;
  type?: string;
}
# Python

class Icon(dict):
  def __init__(self, src: string, size: str = None, type: str = None):
    super().__init__(src=src, size=size, type=type)

  @property
  def src(self) -> str:
    return self['src']

  @property
  def size(self) -> str:
    return self.get('size', '') # maybe this should be None?

  ...

Ultimate Goal - a build pipeline that consume the latest Typescript definitions and creates Python types. I say that only to say, if we see a means for automating this, that is very exciting

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

1 participant