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

feat(typing): type request module #2271

Merged
merged 22 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from datetime import datetime
from collections import OrderedDict
import configparser
from datetime import datetime
import multiprocessing
import sys
import os
import sys

sys.path.insert(0, os.path.abspath('..'))

Expand Down
1 change: 0 additions & 1 deletion docs/ext/rfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import re


RFC_PATTERN = re.compile(r'RFC (\d{4}), Section ([\d\.]+)')


Expand Down
14 changes: 10 additions & 4 deletions falcon/asgi/_request_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

from typing import Any, Optional, TYPE_CHECKING

def header_property(header_name):
if TYPE_CHECKING:
from falcon.asgi import Request


def header_property(header_name: str) -> Any:
"""Create a read-only header property.

Args:
Expand All @@ -25,14 +31,14 @@

"""

header_name = header_name.lower().encode()
header_bytes = header_name.lower().encode()

def fget(self):
def fget(self: Request) -> Optional[str]:
try:
# NOTE(vytas): Supporting ISO-8859-1 for historical reasons as per
# RFC 7230, Section 3.2.4; and to strive for maximum
# compatibility with WSGI.
return self._asgi_headers[header_name].decode('latin1') or None
return self._asgi_headers[header_bytes].decode('latin1') or None

Check warning on line 41 in falcon/asgi/_request_helpers.py

View check run for this annotation

Codecov / codecov/patch

falcon/asgi/_request_helpers.py#L41

Added line #L41 was not covered by tests
except KeyError:
return None

Expand Down
4 changes: 2 additions & 2 deletions falcon/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@
if resp._registered_callbacks:
self._schedule_callbacks(resp)

handler, _, _ = self.resp_options.media_handlers._resolve(
sse_handler, _, _ = self.resp_options.media_handlers._resolve(

Check warning on line 570 in falcon/asgi/app.py

View check run for this annotation

Codecov / codecov/patch

falcon/asgi/app.py#L570

Added line #L570 was not covered by tests
MEDIA_JSON, MEDIA_JSON, raise_not_found=False
)

Expand All @@ -583,7 +583,7 @@
await send(
{
'type': EventType.HTTP_RESPONSE_BODY,
'body': event.serialize(handler),
'body': event.serialize(sse_handler),
'more_body': True,
}
)
Expand Down
Loading