[IDEA] Alternate model syntax
See original GitHub issueIn 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:
- Created 5 years ago
- Reactions:13
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 forStuff
val isIntfield
and a class variable. But due to the metaclass rewriting the class,Stuff
val isint
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 😁
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.