Skip to content

Commit 7ae958a

Browse files
Merge pull request #896 from fredrikt/ft-enable_mypy
Bump Python to 3.9, enable mypy configuration, and fix initial issues reported.
2 parents 13ddd1f + e1a424d commit 7ae958a

File tree

10 files changed

+196
-246
lines changed

10 files changed

+196
-246
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 7.4.0 (2023-XX-XX)
4+
5+
- Add mypy configuration
6+
- Bump Python to 3.9
7+
8+
39
## 7.3.0 (2023-02-14)
410

511
- During metadata generation, render extensions both for EntityDescriptor and IdPSSODescriptor

poetry.lock

Lines changed: 151 additions & 219 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ merge_metadata = "saml2.tools.merge_metadata:main"
3737
parse_xsd2 = "saml2.tools.parse_xsd2:main"
3838

3939
[tool.poetry.dependencies]
40-
python = "^3.6.2"
40+
python = "^3.9"
4141
cryptography = ">=3.1"
4242
defusedxml = "*"
4343
importlib-metadata = {version = ">=1.7.0", python = "<3.8"}
@@ -66,6 +66,13 @@ Flake8-pyproject = "^1.1.0.post0"
6666
flake8-bugbear = "^22.8.23"
6767
flake8-logging-format = "^0.7.5"
6868
ipdb = "^0.13.9"
69+
mypy = "^1.0.0"
70+
types-pyopenssl = "^23.0.0.3"
71+
types-python-dateutil = "^2.8.19.6"
72+
types-pytz = "^2022.7.1.0"
73+
types-setuptools = "^67.2.0.1"
74+
types-six = "^1.16.21.4"
75+
types-requests = "^2.28.11.12"
6976

7077
[tool.poetry.group.test]
7178
optional = true
@@ -225,15 +232,16 @@ src_paths = [
225232
'test',
226233
]
227234

228-
# XXX TODO
229-
#[tool.mypy]
230-
#pretty = true
231-
#check_untyped_defs = true
232-
#ignore_errors = false
233-
#ignore_missing_imports = true
234-
#show_error_codes = true
235-
#strict_optional = true
236-
#warn_unused_ignores = true
237-
#warn_redundant_casts = true
238-
#warn_unused_configs = true
239-
#warn_unreachable = true
235+
[tool.mypy]
236+
pretty = true
237+
check_untyped_defs = false
238+
ignore_errors = false
239+
ignore_missing_imports = true
240+
show_error_codes = true
241+
strict_optional = true
242+
warn_unused_ignores = true
243+
warn_redundant_casts = true
244+
warn_unused_configs = true
245+
warn_unreachable = true
246+
install_types = true
247+
non_interactive = true

src/saml2/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"""
1818

1919
import logging
20+
from typing import Any
21+
from typing import Optional
22+
from typing import Union
2023
from xml.etree import ElementTree
2124

2225
import defusedxml.ElementTree
@@ -433,14 +436,14 @@ class SamlBase(ExtensionContainer):
433436
nodes into ExtensionElements.
434437
"""
435438

436-
c_children = {}
437-
c_attributes = {}
438-
c_attribute_type = {}
439-
c_child_order = []
440-
c_cardinality = {}
441-
c_any = None
442-
c_any_attribute = None
443-
c_value_type = None
439+
c_children: Any = {}
440+
c_attributes: Any = {}
441+
c_attribute_type: Any = {}
442+
c_child_order: list[str] = []
443+
c_cardinality: dict[str, dict[str, int]] = {}
444+
c_any: Optional[dict[str, str]] = None
445+
c_any_attribute: Optional[dict[str, str]] = None
446+
c_value_type: Any = None
444447
c_ns_prefix = None
445448

446449
def _get_all_c_children_with_order(self):

src/saml2/authn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,5 @@ def _verify(self, pwd, user):
269269

270270
except ImportError:
271271

272-
class LDAPAuthn(UserAuthnMethod):
272+
class LDAPAuthn(UserAuthnMethod): # type: ignore[no-redef]
273273
pass

src/saml2/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ def artifact2destination(self, artifact, descriptor):
15831583

15841584
typecode = _art[:2]
15851585
if typecode != ARTIFACT_TYPECODE:
1586-
raise ValueError(f"Invalid artifact typecode '{typecode}' should be {ARTIFACT_TYPECODE}")
1586+
raise ValueError(f"Invalid artifact typecode {repr(typecode)} should be {repr(ARTIFACT_TYPECODE)}")
15871587

15881588
try:
15891589
endpoint_index = str(int(_art[2:4]))

src/saml2/httputil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from http.cookies import SimpleCookie
55
import logging
66
import time
7+
from typing import Optional
78
from urllib.parse import parse_qs
89
from urllib.parse import quote
910

@@ -22,7 +23,7 @@
2223

2324

2425
class Response:
25-
_template = None
26+
_template: Optional[str] = None
2627
_status = "200 OK"
2728
_content_type = "text/html"
2829
_mako_template = None

src/saml2/pack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
try:
1414
import html
1515
except Exception:
16-
import cgi as html
16+
import cgi as html # type: ignore[no-redef]
1717

1818
import logging
1919
from urllib.parse import urlencode

src/saml2/s_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def do_attribute(val, typ, key):
343343
friendly = ""
344344
if name:
345345
attr.name = name
346-
if format:
346+
if nformat:
347347
attr.name_format = nformat
348348
if friendly:
349349
attr.friendly_name = friendly

src/saml2/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
try:
22
from importlib.metadata import version as _resolve_package_version
33
except ImportError:
4-
from importlib_metadata import version as _resolve_package_version
4+
from importlib_metadata import version as _resolve_package_version # type: ignore[no-redef]
55

66

77
def _parse_version():

0 commit comments

Comments
 (0)