-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
Replace type hints for Sequence CORSMiddleware class init parameters to Iterable. #2724
Replace type hints for Sequence CORSMiddleware class init parameters to Iterable. #2724
Conversation
Please revert those changes. |
Please revert. People can add that option if they prefer when running |
Didn't you want to add |
Hello, do you mean all of them or some? In the second case, which ones should be reverted? |
I tried it first time and mypy emitted complains, e.g. I presume that we are talking about incoming parameters, which are "perfectly" fine to be iterable objects because we can iterate over them and gather their items. Moreover, these type hints cover generators (which are iterators, which are iterable objects) as well which explains the rationale over converting the arguments into sets with collateral deduplication. When these incliming Conclusion: just because we use some attributes as containers so far, it should not restrict corresponding attributes to the same type. |
The option |
@stankudrow There are too many changes here. The discussion that motivated this PR just mentions that we can change a type hint to become |
Instead of |
https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection - I am not sure the "sized" property is something to impose because iterability is quite enough for current and, I guess, future preprocessing which has not changed so much. Also, I am perfectly fine with " |
Not as much as it appears: just one module and all about mostly refactoring with collateral deduplication. I see the work done, but I still don't understand what exactly should be reverted concerning the IMHO, I didn't see any chance for a mere type hint switch towards |
@Kludex , rebased. |
@stankudrow There are too many unrelated changes here. |
Summary
Provide more suitable type hints for CORSMiddleware class on the trail of the discussion #2722 .
@roy-work proposed
typing.Container[str]
forallow_
parameters in the CORSMiddleware class constructor. I guess thattyping.Iterable[str]
may be more suitable because of some preprocessing within the__init__()
method, so mereContainer
s cannot be used and mypy will complain about it.Also the conversion to
set
data structure for changed parameters is added due to possibly given generators, which are iterable as well and can be exhausted. Moreover, sets are nice against possible duplicates.And, as the final touch, I gather that adding
--maxfail=1
option for pytest seems nice: no need in waiting for all tests to be executed, but I can remove this option if the community explain me the reasons (please).UPD: docs are updated including markdown linting complaints addressed.
Checklist