Skip to content

Conversation

@Neutronlul
Copy link
Contributor

Preamble

The following snippet (adapted from the Recipes docs) results in a pylance error on the non-int increment_by arguments passed to seq() (the float and timedelta())

from datetime import date, timedelta
from model_bakery.recipe import Recipe, seq
from shop.models import Customer
from model_bakery import baker

CustomerRecipe = Recipe(
    Customer,
    age=seq(15, increment_by=3),
    height_ft=seq(5.5, increment_by=0.25),
    # assume today's date is 21/07/2014
    appointment=seq(date(2014, 7, 21), timedelta(days=1)),
    name=seq("Custom num: ", increment_by=2, start=5),
)

customer = baker.make_recipe("shop.CustomerRecipe")
customer.age  # 18
customer.height_ft  # 5.75
customer.appointment  # datetime.date(2014, 7, 22)
customer.name  # 'Custom num: 5'

new_customer = baker.make_recipe("shop.CustomerRecipe")
new_customer.age  # 21
new_customer.height_ft  # 6.0
new_customer.appointment  # datetime.date(2014, 7, 23)
customer.name  # 'Custom num: 7'

There seems to be a fair bit of inconsistency between the code and the docs (and other parts of the code) but I'm going with the assumption that the intended behavior is what's been more recently updated. In this case, that is the behavior of seq(), not its docstring.

In other words, the docs and the docstring make it sound like (at least to me) the value argument should be null for datetime types, but the function body expects them to be passed to value.

Describe the change

Add type hints to seq()'s increment_by argument that align with the function's behavior

PR Checklist

  • Change is covered with tests
  • CHANGELOG.md is updated if needed

@Neutronlul Neutronlul marked this pull request as ready for review January 4, 2026 14:06
Copy link
Member

@amureki amureki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems correct to me, thank you for the improvement, @Neutronlul !

One issue is that mypy fails here, but I will try to address it myself.

@amureki amureki merged commit 87b71b1 into model-bakers:main Jan 15, 2026
74 checks passed
amureki added a commit that referenced this pull request Jan 15, 2026
…ators

* origin/main:
  Add type hints to `seq()`'s `increment_by` argument (#560)
  Update seq import from model_bakery.recipe to model_bakery.utils in basic usage docs (#559)
amureki added a commit that referenced this pull request Jan 15, 2026
…t-markers

* origin/main: (52 commits)
  Ref #61 -- Introduce generators for each integer field (#528)
  Add type hints to `seq()`'s `increment_by` argument (#560)
  Update seq import from model_bakery.recipe to model_bakery.utils in basic usage docs (#559)
  Remove mentions of the old project (#558)
  Bump 1.21.0
  Only select valid choices from model field choices (#556)
  Improve numeric generators and drop internal `gen_integer` usage (#557)
  Fix link to Django supported versions document
  Drop Python 3.9 support (reached end of file) (#548)
  Bump actions/checkout from 5 to 6 (#549)
  Bump actions/upload-artifact from 5 to 6 (#553)
  Bump actions/download-artifact from 6 to 7 (#554)
  Standardize licenses to Apache License 2.0 (#552)
  Configure generic foreign key relations respecting Django internals (#544)
  Bump actions/upload-artifact from 4 to 5 (#546)
  Bump actions/download-artifact from 5 to 6 (#545)
  Add Django 6.0 support (#540)
  Add Python 3.14 support (#539)
  Modernize superseded typing features
  Drop Python 3.8 support
  ...
amureki added a commit that referenced this pull request Jan 15, 2026
* origin/main: (210 commits)
  Fix `baker.prepare()` with `GenericForeignKey` to work without database access (#501)
  Ref #61 -- Introduce generators for each integer field (#528)
  Add type hints to `seq()`'s `increment_by` argument (#560)
  Update seq import from model_bakery.recipe to model_bakery.utils in basic usage docs (#559)
  Remove mentions of the old project (#558)
  Bump 1.21.0
  Only select valid choices from model field choices (#556)
  Improve numeric generators and drop internal `gen_integer` usage (#557)
  Fix link to Django supported versions document
  Drop Python 3.9 support (reached end of file) (#548)
  Bump actions/checkout from 5 to 6 (#549)
  Bump actions/upload-artifact from 5 to 6 (#553)
  Bump actions/download-artifact from 6 to 7 (#554)
  Standardize licenses to Apache License 2.0 (#552)
  Configure generic foreign key relations respecting Django internals (#544)
  Bump actions/upload-artifact from 4 to 5 (#546)
  Bump actions/download-artifact from 5 to 6 (#545)
  Add Django 6.0 support (#540)
  Add Python 3.14 support (#539)
  Modernize superseded typing features
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants