Skip to content

Add stubs for django-environ #14573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

EmCeeEs
Copy link

@EmCeeEs EmCeeEs commented Aug 13, 2025

Types for django-environ.

This comment has been minimized.

This comment has been minimized.

@donBarbos
Copy link
Contributor

Thanks! I just want to note that the project doesn’t seem to be very actively maintained (the last commit was 7 months ago), so I wouldn’t expect type hints to be added to the library itself anytime soon.

FTR: here’s a recent issue essentially complaining about the lack of type hints: joke2k/django-environ#567, and another one joke2k/django-environ#365 that might give some insight into the maintainer’s stance on adding them.

Copy link
Contributor

@donBarbos donBarbos left a comment

Choose a reason for hiding this comment

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

Looks good! Just few moments:

Copy link
Member

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good overall, see remarks below

Comment on lines 4 to 11
__copyright__: str
__version__: str
__license__: str
__author_email__: str
__maintainer__: str
__maintainer_email__: str
__url__: str
__description__: str
Copy link
Member

Choose a reason for hiding this comment

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

These look like they can be marked as Final

Comment on lines 92 to 100
def db_url_config(cls, url: _Str | ParseResult, engine: _Str | None = None) -> _Dict: ...
@classmethod
def cache_url_config(cls, url: _Str | ParseResult, backend: _Str | None = None) -> _Dict: ...
@classmethod
def email_url_config(cls, url: _Str | ParseResult, backend: _Str | None = None) -> _Dict: ...
@classmethod
def channels_url_config(cls, url: _Str | ParseResult, backend: _Str | None = None) -> _Dict: ...
@classmethod
def search_url_config(cls, url: _Str | ParseResult, engine: _Str | None = None) -> _Dict: ...
Copy link
Member

Choose a reason for hiding this comment

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

These could return TypedDicts since the keys appear to be fixed

class FileAwareEnv(Env):
ENVIRON: FileAwareMapping

class _PathKwargs(TypedDict, total=False):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class _PathKwargs(TypedDict, total=False):
@type_check_only
class _PathKwargs(TypedDict, total=False):

@brianschubert brianschubert changed the title Feature/django environ types Add stubs for django-environ Aug 13, 2025

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@donBarbos
Copy link
Contributor

I noticed that you’ve added quite a few Any types in generics. Just a gentle reminder that the use of Any is usually accompanied by a short comment explaining why it’s needed. If you’re not entirely sure about the type yet, you might consider using Incomplete instead. It could be a more suitable choice in such cases.

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.

3 participants