django-types icon indicating copy to clipboard operation
django-types copied to clipboard

types-psycopg2 should be optional dependency?

Open anentropic opened this issue 1 year ago • 2 comments

I noticed that adding django-types to my project installed types-psycopg2 too

But I'm not using Postgres db and I don't have psycopg2 installed

In Django that's an optional dependency that has to be installed manually

anentropic avatar Oct 02 '24 12:10 anentropic

I'd be curious what happens when it's not installed and someone tries to use a Django Postgres specific thing, since we depend on the types:

https://github.com/sbdchd/django-types/blob/610f267873cbc2eca8a49434cd0b7a6b323807df/django-stubs/db/backends/utils.pyi#L11

sbdchd avatar Oct 02 '24 23:10 sbdchd

I have this workaround in my pyproject.toml file which avoids types-psycopg2 getting installed when using uv. It seems to work fine, so I'm just confirming that making it an optional dependency should be fine if you're not using Postgres specific things (I don't know what would happen if you do). Maybe make a django-types[psycopg2] optional dependency group?

[tool.uv]
# Remove unused dependencies https://github.com/astral-sh/uv/issues/4422
override-dependencies = [
    "types-psycopg2 ; sys_platform == 'never'",  # unused from django-types
]

collinanderson avatar May 25 '25 20:05 collinanderson