Skip to content
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

Add type hinting and a py.typed marker file #696

Closed
j00bar opened this issue Nov 15, 2024 · 7 comments · Fixed by #697
Closed

Add type hinting and a py.typed marker file #696

j00bar opened this issue Nov 15, 2024 · 7 comments · Fixed by #697
Labels
enhancement New feature or request

Comments

@j00bar
Copy link

j00bar commented Nov 15, 2024

It would be awesome to be able to use this library in projects that are type checked by mypy without having to add it to the ignores.

To do that, for the installable code, you'd need to type hint the arguments and return for each function and then touch a py.typed file in the module to alert mypy it's safe to use the annotations on the code itself.

@jrobichaud jrobichaud added the enhancement New feature or request label Nov 15, 2024
@jrobichaud
Copy link
Owner

jrobichaud commented Nov 15, 2024

I have a stash on my computer where I started to work on the type definitions.

I'll complete it now that someone asks for it.

@jrobichaud
Copy link
Owner

jrobichaud commented Nov 16, 2024

@j00bar, or anyone.
I find a lot of reference/blog posts on how to integrate type definitions in a project, but not much anything about integrating it in a third party library like django-structlog.

do you know:

  • a good third party library that has type definition?
  • any library that does it wrong and why?
  • since django-structlog requires django and optionally celery. Should a third party library like django-structlog avoid using stubs like django-stubs[compatible-mypy] or celery-types respectively?
  • any other recommendations?

@jrobichaud
Copy link
Owner

jrobichaud commented Nov 16, 2024

Good to know, some type definitions change depending of python's version, we have to support compatibility from 3.9 to 3.13:

https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html#useful-built-in-types

Can be resolved with:

[tool.mypy]
python_version=3.9

@jrobichaud
Copy link
Owner

@j00bar, please take a look at #697

@jrobichaud
Copy link
Owner

@j00bar you can try it with a pre-release 9.0.0.dev1 version I made

https://pypi.org/project/django-structlog/9.0.0.dev1/

@jrobichaud
Copy link
Owner

@j00bar make sure to use precisely 9.0.0.dev1, I used dev2 to test another pull request.

@jrobichaud
Copy link
Owner

9.0.0 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants