question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[IDEA] Alternate model syntax

See original GitHub issue

In trying to solve the DB → python type mapping, and the advent of typing, a possible solution is to define types that then get evaluated into both Python and DB types:

This also raises the question of a cleaner (more modern) model definition, by defining the type:

Since py3.6 we have the typed variables:

class Author(Model):
    name: str[255]
    books: reverse_fk[Book]

class Book(Model):
    title: str[255]
    author: Author
    published: datetime
    logo: bytes = None
    pages: int
    extra: JSONField = {}
    price: Decimal[18,5]
    created_at: datetime[auto_now_add]

Which is already standard in Py3.7 @dataclass

We could extend type definitions so we can build model definitions off of types. e.g. str[100] = 'some default'CharField(max_length=100, default='some default') The syntax is not comprehensive, but we could probably use type declarations for a large portion of use cases.

This would require Py3.6+ to function, so dropping Py3.5 & PyPy.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:13
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
grigicommented, Jul 5, 2019

Yes, all valid points. This is feeling more like something that we may not want to do as is in my proposal.

Technically the problem is as follows: Lets say I define a class Stuff withval=IntField() It appears that for Stuff val is Intfield and a class variable. But due to the metaclass rewriting the class, Stuff val is int and an instance variable.

In the name of being succinct (and use metaclasses as a solution) we will end up confusing anything that tries to do Type determinism.

I added a PyLint plugin so that it can stop complaining about everything, but at that time Mypy didn’t have plugins yet.

I’d love a Mypy plugin 😁

0reactions
antonagestamcommented, Jul 5, 2019

Cool! I think mypy support really would be a great feature.

The plugins for attrs and dataclasses that are shipped with mypy are probably good places to look for inspiration, and they should probably give a somewhat good indication of the amount of work that’s required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File type associations | IntelliJ IDEA Documentation - JetBrains
Press Ctrl+Alt+S to open the IDE settings and select Editor | File Types. , specify the name of the new type, and provide...
Read more >
Teaching syntax or procedures to use in methodologies as ...
This page includes summaries of different teaching syntax or procedures to use in different models as strategies for teaching and learning.
Read more >
Syntax alternatives for modules - open-std.org
Syntax alternatives for modules. Bjarne Stroustrup. Abstract. This note examines eight approaches to the problem of the “module” keyword ...
Read more >
From Meaning to Form: an Alternative Model of Functional ...
From Meaning to Form: an Alternative Model of Functional Syntax ... Syntax (Bondarko 1983, 1984, 2001), a number of shared ideas are evident;...
Read more >
SKOS Simple Knowledge Organization System Reference
SKOS concepts can be mapped to other SKOS concepts in different concept schemes. The SKOS data model provides support for four basic types...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found