From e9ac5432d1f1aa061541770b1bd5629b3fdc7484 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Wed, 1 Feb 2023 09:41:45 +0100 Subject: Fix initial issues reported by mypy. --- src/saml2/__init__.py | 19 +++++++++++-------- src/saml2/authn.py | 2 +- src/saml2/entity.py | 2 +- src/saml2/httputil.py | 3 ++- src/saml2/pack.py | 2 +- src/saml2/version.py | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py index 0397a365..01067b4b 100644 --- a/src/saml2/__init__.py +++ b/src/saml2/__init__.py @@ -17,6 +17,9 @@ """ import logging +from typing import Any +from typing import Optional +from typing import Union from xml.etree import ElementTree import defusedxml.ElementTree @@ -433,14 +436,14 @@ class SamlBase(ExtensionContainer): nodes into ExtensionElements. """ - c_children = {} - c_attributes = {} - c_attribute_type = {} - c_child_order = [] - c_cardinality = {} - c_any = None - c_any_attribute = None - c_value_type = None + c_children: Any = {} + c_attributes: Any = {} + c_attribute_type: Any = {} + c_child_order: list[str] = [] + c_cardinality: dict[str, dict[str, int]] = {} + c_any: Optional[dict[str, str]] = None + c_any_attribute: Optional[dict[str, str]] = None + c_value_type: Any = None c_ns_prefix = None def _get_all_c_children_with_order(self): diff --git a/src/saml2/authn.py b/src/saml2/authn.py index dfd0a925..9a2eef51 100644 --- a/src/saml2/authn.py +++ b/src/saml2/authn.py @@ -269,5 +269,5 @@ try: except ImportError: - class LDAPAuthn(UserAuthnMethod): + class LDAPAuthn(UserAuthnMethod): # type: ignore[no-redef] pass diff --git a/src/saml2/entity.py b/src/saml2/entity.py index 8016b481..f167a08a 100644 --- a/src/saml2/entity.py +++ b/src/saml2/entity.py @@ -1583,7 +1583,7 @@ class Entity(HTTPBase): typecode = _art[:2] if typecode != ARTIFACT_TYPECODE: - raise ValueError(f"Invalid artifact typecode '{typecode}' should be {ARTIFACT_TYPECODE}") + raise ValueError(f"Invalid artifact typecode {repr(typecode)} should be {repr(ARTIFACT_TYPECODE)}") try: endpoint_index = str(int(_art[2:4])) diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py index 7217b147..3ad668b7 100644 --- a/src/saml2/httputil.py +++ b/src/saml2/httputil.py @@ -4,6 +4,7 @@ import hmac from http.cookies import SimpleCookie import logging import time +from typing import Optional from urllib.parse import parse_qs from urllib.parse import quote @@ -22,7 +23,7 @@ logger = logging.getLogger(__name__) class Response: - _template = None + _template: Optional[str] = None _status = "200 OK" _content_type = "text/html" _mako_template = None diff --git a/src/saml2/pack.py b/src/saml2/pack.py index 0e6923df..99c32476 100644 --- a/src/saml2/pack.py +++ b/src/saml2/pack.py @@ -13,7 +13,7 @@ import base64 try: import html except Exception: - import cgi as html + import cgi as html # type: ignore[no-redef] import logging from urllib.parse import urlencode diff --git a/src/saml2/version.py b/src/saml2/version.py index fa5670a9..281fab9f 100644 --- a/src/saml2/version.py +++ b/src/saml2/version.py @@ -1,7 +1,7 @@ try: from importlib.metadata import version as _resolve_package_version except ImportError: - from importlib_metadata import version as _resolve_package_version + from importlib_metadata import version as _resolve_package_version # type: ignore[no-redef] def _parse_version(): -- cgit v1.2.1