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 types #282
Conversation
I've added a chapter with some thoughts: https://structlog--282.org.readthedocs.build/en/282/types.html And a quick workaround if it breaks your CI. |
Co-authored-by: Éric Araujo <merwok@netwok.org>
Co-authored-by: Éric Araujo <merwok@netwok.org>
It seems to work without but who the hell even knows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I time-boxed myself 15 minutes to look at this, so sorry for the incomplete review -- hope some of this is helpful <3 a typing nerd
additionally, you might want to check out flake8-typing-imports:
$ flake8 --min-python-version 3.6.0 src/
src/structlog/testing.py:14:1: TYP001 guard import by `if TYPE_CHECKING:`: NoReturn (not in 3.6.0, 3.6.1)
(notably, NoReturn
doesn't exist in 3.6.0 and 3.6.1 but those are compatible with your python_requires
)
Thank you so much!
This shouldn't be a problem because I depend on typing-extensions on Python < 3.8! I need it for |
you can cheese protocol with (example): if TYPE_CHECKING:
from typing import Protocol
else:
Protocol = object though if you're already committed to |
For everyone following along: I've noticed that the type hints of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great
Co-authored-by: Zac Hatfield-Dodds <Zac-HD@users.noreply.github.com>
Co-authored-by: Zac Hatfield-Dodds <Zac-HD@users.noreply.github.com>
Thanks everyone! If something else comes up, feel free to open new issues. |
The structlog 20.2.0 update added proper type annotations to the package, see hynek/structlog#223, hynek/structlog#282. Updated package, docker, and dev configuration files to ensure structlog 20.2.0 or higher is always installed. Updated `mitre.securingai` source and unit testing code so that all `get_logger()` calls use the `structlog.stdlib` import path and also replaced the `BoundLoggerLazyProxy` type annotation with `structlog.stdlib.BoundLogger` as suggested in the 20.2.0 documentation, see https://www.structlog.org/en/20.2.0/types.html.
So far I've tested it with a bunch of my own projects and it seems to be working great. Not sure if I'm missing something?
The big concession we've had to make is adding a few wrapper methods/functions that only add correct types:
structlog.stdlib.get_logger()
structlog.stdlib.BoundLogger.bind()
(and the whole rest)I think that's tolerable from a performance stance.