From 86058b7efb1b506edc17cccf4a43529a40a416b0 Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Fri, 9 Aug 2024 14:43:40 -0400 Subject: [PATCH 1/2] Adding py.typed sentinel file to support type checking https://typing.readthedocs.io/en/latest/guides/libraries.html#marking-a-package-as-providing-type-information a sentinel file must be present and distributed in package to signal to type checkers that the library provides type information that can be used; otherwise imports from this library are considered untyped. --- setup.py | 3 ++- xivo/py.typed | 0 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 xivo/py.typed diff --git a/setup.py b/setup.py index a25506b2..763b2e6c 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright 2007-2023 The Wazo Authors (see the AUTHORS file) +# Copyright 2007-2024 The Wazo Authors (see the AUTHORS file) # SPDX-License-Identifier: GPL-3.0-or-later from setuptools import find_packages, setup @@ -12,4 +12,5 @@ author_email='dev@wazo.community', url='http://wazo.community', packages=find_packages(), + package_data={'xivo': ['py.typed']}, ) diff --git a/xivo/py.typed b/xivo/py.typed new file mode 100644 index 00000000..e69de29b From 506906bf36959fdb7fa6b04109522b1f626b06fe Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Fri, 20 Sep 2024 17:10:09 -0400 Subject: [PATCH 2/2] typing: http_helpers: updated function annotation Why: replaced dict type on parameter with MutableMapping be forgiving in what you accept, strict in what you provide existing usages of this function rely on passing e.g. ChainMap and should also work --- xivo/http_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xivo/http_helpers.py b/xivo/http_helpers.py index a21013bd..43cf1d06 100644 --- a/xivo/http_helpers.py +++ b/xivo/http_helpers.py @@ -6,7 +6,7 @@ import json import re import time -from collections.abc import Iterable +from collections.abc import Iterable, MutableMapping from json.decoder import JSONDecodeError from logging import Logger from typing import TYPE_CHECKING, Any @@ -42,7 +42,7 @@ def __call__( return self.app(environ, start_response) -def reverse_proxy_fix_api_spec(api_spec: dict[str, Any]) -> None: +def reverse_proxy_fix_api_spec(api_spec: MutableMapping[str, Any]) -> None: prefix = request.headers.get('X-Script-Name') if prefix: api_spec['schemes'] = ['https']