-
-
Notifications
You must be signed in to change notification settings - Fork 957
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 hints in test_base.py
#2445
Conversation
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.
Looks great, thank you!
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.
Besides this, looks good. Thanks! 🙏
starlette/types.py
Outdated
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.
The types only used on the test suite shouldn't be added here. You can add them in the test_base.py
itself for now, and if reused on multiple files, we can have them added in a module on the tests/
directory.
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.
Thank you for the review and the guidance!
I've noticed that certain types, such as TestClientFactory
, are indeed reused across multiple test files (e.g., test_routing.py
, test_applications.py
, test_background.py
, etc.). To confirm my understanding and plan of action:
-
Create a New Module for Shared Test Types: I will create a new module within the tests/ directory to house these shared types. I'm considering naming it
tests.test_types.types
. Does this naming convention work for you, or would you suggest a different structure? -
Revert Changes to
starlette.types
: I understand that thestarlette.types
module is intended for application-level types. Therefore, I'll move the test-specific types that I have added out of this module and into the newly created module for shared test types. -
Handling Types Used in a Single File: For types that are currently only used in one test file, I plan to keep them within their respective files to maintain simplicity. However, now that we'll have a dedicated module for shared test types (
test_types.types
), would you prefer moving all test-specific types there for consistency, or should they remain in their individual test files until needed elsewhere?
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.
No. For now, just the test_base.py
. Create the types you need there. We'll talk if they are needed or not individually, and if we should move them somewhere.
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.
Let's go step by step. 👍
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.
Got it. Thank you!
I have done the requested changes, you can check.
…tte into improve-types/test-base
tests/middleware/test_base.py
Outdated
BytesGenerator = Generator[bytes, None, None] | ||
AwaitableGenerator = Generator[Any, None, None] | ||
TestClientFactory = Callable[[ASGIApp], TestClient] | ||
MiddlewareClass = Type[_MiddlewareClass[Any]] |
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.
Can you instead not create those aliases, please? You can leave the TestClientFactory
here, but the ones that are used only once, I'd prefer to avoid.
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.
Sure, deleted them.
Thanks! :) |
* added type annotations to test-base.py * deleted unused imports * fixed import order * conditional import * conditional import TestClient on types.py * using string literals when importing in types * added missing imports * deleted starlette/types, refactored test_base types * deleted types --------- Co-authored-by: Scirlat Danut <[email protected]> Co-authored-by: Marcelo Trylesinski <[email protected]>
Summary
This is part of a bigger Task. The idea is to remove those flags on mypy check command on:
scripts/check
.Before
${PREFIX}mypy starlette
${PREFIX}mypy tests --disable-error-code no-untyped-def --disable-error-code no-untyped-call
After
${PREFIX}mypy starlette tests
In order to do that, we need to fix all issues after deleting those flags. After deleting those, there are more than 730 issues, in 34 files. I will make separate PRs for each file in order to have atomic changes.
Things done in this PR:
NOTES:
Checklist