diff options
author | Jens Vagelpohl <jens@plyp.com> | 2023-01-02 20:18:33 +0100 |
---|---|---|
committer | Jens Vagelpohl <jens@plyp.com> | 2023-01-02 20:18:33 +0100 |
commit | 761b186921b024b91273b15e0f6a3ac1f85656bf (patch) | |
tree | 773240b736f3c2f8b85dae38ad2d843a71a01382 | |
parent | ae8bb4cfa8b89b1d42fedb1ab391cc292d94c365 (diff) | |
download | zope-component-761b186921b024b91273b15e0f6a3ac1f85656bf.tar.gz |
- Fix crash when the environment variable `PYTHONOPTIMIZED` is set to `2`
-rw-r--r-- | .github/workflows/tests.yml | 1 | ||||
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | src/zope/component/interfaces.py | 6 | ||||
-rw-r--r-- | src/zope/component/tests/test_interface.py | 8 | ||||
-rw-r--r-- | tox.ini | 1 |
5 files changed, 20 insertions, 0 deletions
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4f292f0..fa64e1a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,6 +24,7 @@ jobs: - ["3.8", "py38"] - ["3.9", "py39"] - ["3.10", "py310"] + - ["3.10", "py310-optimized"] - ["3.11", "py311"] - ["pypy-2.7", "pypy"] - ["pypy-3.7", "pypy3"] diff --git a/CHANGES.rst b/CHANGES.rst index 479509c..40bf792 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,10 @@ 5.1.0 (unreleased) ================== +- Fix crash when the environment variable `PYTHONOPTIMIZED` is set to `2` + and docstrings are set to `None` by the interpreter. + (`#67 <https://github.com/zopefoundation/zope.component/issues/67>`_) + - Add support for Python 3.10 and 3.11. diff --git a/src/zope/component/interfaces.py b/src/zope/component/interfaces.py index 068c625..0029a59 100644 --- a/src/zope/component/interfaces.py +++ b/src/zope/component/interfaces.py @@ -364,6 +364,12 @@ class IFactory(Interface): def _inherits_docs(func, iface): doc = iface[func.__name__].__doc__ + + # doc can be None if the interpreter drops all docstrings when the + # environment variable PYTHONOPTIMIZE is set 2. + if not doc: + return func + # By adding the ..seealso:: we get a link from our overview page # to the specific narrative place where the function is described, because # our overview page uses :noindex: diff --git a/src/zope/component/tests/test_interface.py b/src/zope/component/tests/test_interface.py index f7d266a..ab56160 100644 --- a/src/zope/component/tests/test_interface.py +++ b/src/zope/component/tests/test_interface.py @@ -13,8 +13,14 @@ ############################################################################## """Tests for z.c.interface """ +import os import unittest + +DOCSTRINGS_REMOVED = False +if str(os.environ.get('PYTHONOPTIMIZE')) == '2': + DOCSTRINGS_REMOVED = True + # pylint:disable=inherit-non-class,blacklisted-name class Test_provideInterface(unittest.TestCase): @@ -346,6 +352,8 @@ class Test_searchInterfaceUtilities(unittest.TestCase): self.assertEqual(self._callFUT(object(), base=IFoo), [('foo', IFoo)]) +@unittest.skipIf(DOCSTRINGS_REMOVED, + 'Skipping tests, docstrings are optimized away') class Test_getInterfaceAllDocs(unittest.TestCase): def _callFUT(self, *args, **kw): @@ -35,6 +35,7 @@ commands = setenv = ZOPE_INTERFACE_STRICT_IRO = 1 pure: PURE_PYTHON = 1 + optimized: PYTHONOPTIMIZE = 2 [testenv:docs] basepython = |