From 9f16bf5c25e126200701f6e04330864f4a91a898 Mon Sep 17 00:00:00 2001 From: julien4215 <120588494+julien4215@users.noreply.github.com> Date: Thu, 25 Apr 2024 08:49:38 +0200 Subject: [PATCH] Fix documentation on client address type (#2580) --- docs/requests.md | 3 +-- starlette/requests.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/requests.md b/docs/requests.md index f8d19bb9b..9140bb964 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -60,8 +60,7 @@ For example: `request.path_params['username']` #### Client Address -The client's remote address is exposed as a named two-tuple `request.client`. -Either item in the tuple may be `None`. +The client's remote address is exposed as a named two-tuple `request.client` (or `None`). The hostname or IP address: `request.client.host` diff --git a/starlette/requests.py b/starlette/requests.py index b27e8e1e2..a2fdfd81e 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -145,7 +145,7 @@ def cookies(self) -> dict[str, str]: @property def client(self) -> Address | None: - # client is a 2 item tuple of (host, port), None or missing + # client is a 2 item tuple of (host, port), None if missing host_port = self.scope.get("client") if host_port is not None: return Address(*host_port)