News for hackers. Stuff that matters.
Re:Show HN: Prisma Python – A fully typed ORM for Python by cabalamat on Monday February 21, 2022 @08:21PM (#30422991)
I have also written a python ORM, Bozen[1]. In Bozen you define a table like this:

    class Book(MonDoc):
        title = StrField()
        yearPublished = IntField()
Is it possible to give run-time types to `title` and `yearPublished`, in a way that works with mypy and the Python typing ecosystem? If so, is there a tutorial on this, as I'd like to add the feature to my ORM.

1: https://github.com/cabalamat/frambozenapp

Re:Show HN: Prisma Python – A fully typed ORM for Python by probablyrobert on Monday February 21, 2022 @08:36PM (#30423074)
The most obvious way would be to simply annotate the fields, e.g.

  class Book(MonDoc):
    title: str = StrField()
    yearPublished: int = IntField()
If this means too much redundant information for you then you could try defining the fields to return the corresponding python type e.g.

  def IntField() -> int:
    ...
Re:Show HN: Prisma Python – A fully typed ORM for Python by cabalamat on Sunday February 27, 2022 @02:09PM (#30491463)
I could certainly annotate the fields like you suggest. But that goes against the spirit of Bozen which is DRY.

When I define something as a `StrField` I'm already saying it's a string, so I shouldn't have to say it again elsewhere. It would be nice if Python has an API such that I can write code within my `StrField` class that tells python that `title` is a `str`, but to the best of my understanding this doesn't exist.