Skip to content

Commit

Permalink
mypy: Don't use lazy ManyToManyField with implicit app label
Browse files Browse the repository at this point in the history
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] typeddjango/django-stubs#1802 (comment),
[2] typeddjango/django-stubs#1719 (comment)
[3] https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format
  • Loading branch information
dehnert committed Jul 9, 2024
1 parent 58f3f86 commit fea7de9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions squaresdb/membership/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fea7de9

Please sign in to comment.