diff --git a/sigtools/_signatures.py b/sigtools/_signatures.py index db53000..dd1441e 100644 --- a/sigtools/_signatures.py +++ b/sigtools/_signatures.py @@ -89,7 +89,8 @@ def _is_co_flag_enabled(obj): if not feature: return False - if feature.mandatory and sys.version_info >= feature.mandatory: + mandatory_release = feature.getMandatoryRelease() + if mandatory_release and sys.version_info >= mandatory_release: return True try: diff --git a/sigtools/tests/test_sphinxext.py b/sigtools/tests/test_sphinxext.py index 6af170b..da18484 100644 --- a/sigtools/tests/test_sphinxext.py +++ b/sigtools/tests/test_sphinxext.py @@ -23,7 +23,7 @@ import unittest -from sigtools.tests import sphinxextfixt +from sigtools.tests import sphinxextfixt, util app = object() @@ -74,6 +74,7 @@ def test_inst_attr(self): None, {}, None, None) self.assertEqual((None, None), r) + @unittest.skipUnless(*util.python_has_optional_future_annotations) def test_attrs_class(self): r = self.sphinxext.process_signature( app, '', 'sigtools.tests.sphinxextfixt.AttrsClass', diff --git a/sigtools/tests/util.py b/sigtools/tests/util.py index d5cc40e..ba6990d 100644 --- a/sigtools/tests/util.py +++ b/sigtools/tests/util.py @@ -23,6 +23,7 @@ import warnings from collections import defaultdict from functools import partial +import __future__ import unittest from repeated_test import tup, WithTestClass, with_options_matrix @@ -175,12 +176,20 @@ def downgrade_param(self, param: funcsigs.Parameter): Fixtures = WithTestClass(SignatureTests) -python_has_future_annotations = (3, 7, 0, "final") <= sys.version_info < (3, 11) -python_has_annotations = (3, 11) <= sys.version_info +python_has_future_annotations = hasattr(__future__, "annotations") +python_has_annotations = ( + python_has_future_annotations + and __future__.annotations.getMandatoryRelease() + and __future__.annotations.getMandatoryRelease() <= sys.version_info +) python_doesnt_have_future_annotations = ( - (sys.version_info < (3, 7, 0, "final")), + not python_has_future_annotations, "Python version does not have __future__.annotations" ) +python_has_optional_future_annotations = ( + python_has_future_annotations and not python_has_annotations, + "Python version does not have optional __future__.annotations" +) def signature_not_using_future_annotations(*args, **kwargs):