From fea7de9d64a876bd97c49f4864b57d6ccd2d5ee1 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Mon, 8 Jul 2024 01:48:28 -0400 Subject: [PATCH] mypy: Don't use lazy ManyToManyField with implicit app label In newer mypy[1][2], `ManyToManyField`s with lazy (string) models but no app label don't work. For the `to` model, we can just use `Person` directly (and do on the line above), so do that. For the `through` model, add the app label -- Django doesn't care, and it makes mypy happy. Also, in mypy, well-structured wildcard patterns match without a submodule too, so simplify some config. [1] https://github.com/typeddjango/django-stubs/issues/1802#issuecomment-1781423719, [2] https://github.com/typeddjango/django-stubs/pull/1719#issuecomment-1738691940 [3] https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format --- mypy.ini | 2 +- squaresdb/membership/models.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mypy.ini b/mypy.ini index 2d07fc0..d062e12 100644 --- a/mypy.ini +++ b/mypy.ini @@ -9,5 +9,5 @@ ignore_missing_imports = True [mypy-social_core.*] ignore_missing_imports = True -[mypy-social_django,social_django.*] +[mypy-social_django.*] ignore_missing_imports = True diff --git a/squaresdb/membership/models.py b/squaresdb/membership/models.py index 8e2ff1f..ff44b40 100644 --- a/squaresdb/membership/models.py +++ b/squaresdb/membership/models.py @@ -235,9 +235,9 @@ class TSClass(models.Model): label = models.CharField(max_length=20) coordinator = models.ForeignKey(Person, on_delete=models.PROTECT, related_name='class_coord') - assistants = models.ManyToManyField('Person', through='TSClassAssist', + assistants = models.ManyToManyField(Person, through='membership.TSClassAssist', related_name='class_assist') - students = models.ManyToManyField('Person', through='TSClassMember', + students = models.ManyToManyField(Person, through='membership.TSClassMember', related_name='classes') start_date = models.DateField(null=True, blank=True) end_date = models.DateField(null=True, blank=True)