diff --git a/envelope/address.py b/envelope/address.py index c74de42..5cf6a71 100644 --- a/envelope/address.py +++ b/envelope/address.py @@ -2,6 +2,7 @@ import logging from os import environ import re +import inspect import sys from .utils import assure_list @@ -14,21 +15,29 @@ def _getaddresses(*args): # NOTE Python finally changed the old way of parsing wrong addresses. + # README should reflect that. + # # We might start using strict=True (default) in the future. - # if sys.version_info < (3, 12, 3): - if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3): - return getaddresses(*args) - return getaddresses(*args, strict=False) + # The difficult version check is due to #45. Docs show that the parameter was added at 3.13, + # however older docs show it was at 3.12.6. Mine 3.12.3 has it too. And according to tests, + # it seems some 3.11.N have it too. It seems to be backported randomly. + # Remove the check as of Python3.13 being the minimum version. + # if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3): + signature = inspect.signature(getaddresses) + parameters = signature.parameters + + if 'strict' in parameters: + return getaddresses(*args, strict=False) + return getaddresses(*args) def _parseaddr(*args): - # NOTE Python finally changed the old way of parsing wrong addresses. - # We might start using strict=True (default) in the future. - # README should reflect that. - # if sys.version_info < (3, 12, 3): - if sys.version_info <= (3, 11) or sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 3): - return parseaddr(*args) - return parseaddr(*args, strict=False) + # See the comment _getaddresses. + signature = inspect.signature(getaddresses) + parameters = signature.parameters + if 'strict' in parameters: + return parseaddr(*args, strict=False) + return parseaddr(*args) class Address(str):