Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active January 10, 2019 08:49
Show Gist options
  • Save kezabelle/89dc9ec59e63a9772c5ad2a2252cee8a to your computer and use it in GitHub Desktop.
Save kezabelle/89dc9ec59e63a9772c5ad2a2252cee8a to your computer and use it in GitHub Desktop.
bleh, typing is pain.
from typing import Tuple, Dict, List
class M(object):
def __init__(self, x: int):
self.id = x
Models = List[M]
def problem() -> None:
seen = {} # type: Dict[int,Models]
for x in [1, 2]:
result = list_of_other_items(x)
seen[x] = result[0] # error: Incompatible types in assignment (expression has type "M", target has type "List[M]")
return None
def list_of_other_items(i: int) -> Models:
return [M(2)]
@kezabelle
Copy link
Author

Change the definition of M to:

from django.db import models
class M(models.Model):
    pass

and suddenly no errors appear :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment