-
-
Notifications
You must be signed in to change notification settings - Fork 945
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
feat(cors): disallow cors_enable
& additional CORSMiddleware
combo
#2201
feat(cors): disallow cors_enable
& additional CORSMiddleware
combo
#2201
Conversation
@@ -461,10 +462,28 @@ def add_middleware(self, middleware: object) -> None: | |||
# the chance that middleware may be None. | |||
if middleware: | |||
try: | |||
self._unprepared_middleware += middleware | |||
middleware = list(middleware) # type: ignore |
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.
Bonus points if anyone knows how type this correctly. Since we optionally allow passing in any object
, mypy
complains:
No overload variant of "list" matches argument type "object" [call-overload]
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 don't think you can. Maybe you can use
try:
if TYPE_CHECKING:
assert isinstance(middleware, Iterable)
...
But I'm not sure it's worth it
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2201 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 62 62
Lines 6876 6880 +4
Branches 1098 1099 +1
=========================================
+ Hits 6876 6880 +4 ☔ View full report in Codecov by Sentry. |
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.
left a could of suggestions, but it looks ok also without applying them
@@ -461,10 +462,28 @@ def add_middleware(self, middleware: object) -> None: | |||
# the chance that middleware may be None. | |||
if middleware: | |||
try: | |||
self._unprepared_middleware += middleware | |||
middleware = list(middleware) # type: ignore |
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 don't think you can. Maybe you can use
try:
if TYPE_CHECKING:
assert isinstance(middleware, Iterable)
...
But I'm not sure it's worth it
Closes #1977.