chore: typing fixes for factory-boy 3.3.3 (#8501)

* chore: typing fixes for factory-boy 3.3.3

* chore: more comments
This commit is contained in:
Jennifer Richards 2025-02-05 16:31:35 -04:00 committed by GitHub
parent 373623da42
commit 1fbedd7df1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View file

@ -7,7 +7,7 @@ import factory
import factory.fuzzy
import datetime
from typing import Optional # pyflakes:ignore
from typing import Any # pyflakes:ignore
from django.conf import settings
from django.utils import timezone
@ -37,13 +37,16 @@ class BaseDocumentFactory(factory.django.DjangoModelFactory):
model = Document
skip_postgeneration_save = True
# n.b., a few attributes are typed as Any so mypy won't complain when we override in subclasses
title = factory.Faker('sentence',nb_words=5)
abstract = factory.Faker('paragraph', nb_sentences=5)
abstract: Any = factory.Faker('paragraph', nb_sentences=5)
rev = '00'
std_level_id = None # type: Optional[str]
std_level_id: Any = None
intended_std_level_id = None
time = timezone.now()
expires = factory.LazyAttribute(lambda o: o.time+datetime.timedelta(days=settings.INTERNET_DRAFT_DAYS_TO_EXPIRE))
expires: Any = factory.LazyAttribute(
lambda o: o.time+datetime.timedelta(days=settings.INTERNET_DRAFT_DAYS_TO_EXPIRE)
)
pages = factory.fuzzy.FuzzyInteger(2,400)
@ -282,7 +285,7 @@ class DocEventFactory(factory.django.DjangoModelFactory):
type = 'added_comment'
by = factory.SubFactory('ietf.person.factories.PersonFactory')
doc = factory.SubFactory(DocumentFactory)
doc: Any = factory.SubFactory(DocumentFactory) # `Any` to appease mypy when a subclass overrides doc
desc = factory.Faker('sentence',nb_words=6)
@factory.lazy_attribute

View file

@ -726,7 +726,7 @@ I would like to revoke this declaration.
self.assertIn(f'{settings.IDTRACKER_BASE_URL}{urlreverse("ietf.ipr.views.showlist")}', get_payload_text(outbox[1]).replace('\n',' '))
def send_ipr_email_helper(self) -> tuple[str, IprEvent, HolderIprDisclosure]:
ipr = HolderIprDisclosureFactory()
ipr = HolderIprDisclosureFactory.create() # call create() explicitly so mypy sees correct type
url = urlreverse('ietf.ipr.views.email',kwargs={ "id": ipr.id })
self.client.login(username="secretary", password="secretary+password")
yesterday = date_today() - datetime.timedelta(1)

View file

@ -2124,7 +2124,8 @@ class EditTimeslotsTests(TestCase):
@staticmethod
def create_bare_meeting(number=120) -> Meeting:
"""Create a basic IETF meeting"""
return MeetingFactory(
# Call create() explicitly so mypy sees the correct type
return MeetingFactory.create(
type_id='ietf',
number=number,
date=date_today() + datetime.timedelta(days=10),