Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQLAlchemy with type hints
#2
Just for future reference, what I decided to do was this:

models.py
from typing import Type, Union

TableTypes = Union[Type['M1'], Type['M2'], ..., Type['M20']]


class M1(db.Model):
    ...
class M2(db.Model):
    ...
...
class M20(db.Model):
    ...
Then wherever you need type hints you can use it like:
import models as m
 
def func(table: m.TableTypes) -> bool
    ...
    return True
Now it's more clean and mypy is not screaming anymore! =)
Reply


Messages In This Thread
SQLAlchemy with type hints - by gontajones - Jun-17-2020, 11:39 AM
RE: SQLAlchemy with type hings - by gontajones - Jun-17-2020, 06:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Type hints and style MaxPowers 1 1,865 Feb-19-2020, 06:56 PM
Last Post: micseydel
  Type hinting - return type based on parameter micseydel 2 2,500 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Should a function ever be more permissive than its type hints? Shay 1 1,949 Mar-13-2019, 05:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020