Skip to content

Fix/silence doctest warnings #94001

Description

@ezio-melotti

I noticed a few warnings triggered during the Doctest workflows. These should be either fixed by updating/removing the examples, or possibly silenced.

These are the (collapsed) outputs on main/3.11/3.10:

main

From https://github.com/python/cpython/runs/6946479177?check_suite_focus=true

make: Entering directory '/home/runner/work/cpython/cpython/Doc'
make[1]: Entering directory '/home/runner/work/cpython/cpython/Doc'
mkdir -p build
Building NEWS from Misc/NEWS.d with blurb
PATH=./venv/bin:$PATH sphinx-build -b doctest -d build/doctrees  -j auto -q -W --keep-going . build/doctest 
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/babel/messages/catalog.py:13: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
  from cgi import parse_header
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/sphinx/util/images.py:4: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
  import imghdr
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/certifi/core.py:36: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
  _CACERT_CTX = get_path("certifi", "cacert.pem")
<doctest default[0]>:1: DeprecationWarning: 'nntplib' is deprecated and slated for removal in Python 3.13
  from nntplib import NNTP
/home/runner/work/cpython/cpython/Lib/socket.py:777: ResourceWarning: unclosed <socket.socket fd=4, family=2, type=1, proto=6, laddr=('10.1.0.37', 45010), raddr=('116.202.254.214', 119)>
  self._sock = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback
<doctest default[0]>:1: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
  import imp
<doctest default[3]>:1: DeprecationWarning: 'turtle.RawTurtle.settiltangle()' is deprecated since Python 3.1 and scheduled for removal in Python 3.13. Use tiltangle() instead.
  turtle.settiltangle(45)
3.11

From https://github.com/python/cpython/runs/6954035375?check_suite_focus=true

make: Entering directory '/home/runner/work/cpython/cpython/Doc'
make[1]: Entering directory '/home/runner/work/cpython/cpython/Doc'
mkdir -p build
Building NEWS from Misc/NEWS.d with blurb
PATH=./venv/bin:$PATH sphinx-build -b doctest -d build/doctrees  -j auto -q -W --keep-going . build/doctest 
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.11/site-packages/babel/messages/catalog.py:13: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
  from cgi import parse_header
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.11/site-packages/sphinx/util/images.py:4: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
  import imghdr
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.11/site-packages/certifi/core.py:36: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
  _CACERT_CTX = get_path("certifi", "cacert.pem")
<doctest default[0]>:1: DeprecationWarning: 'nntplib' is deprecated and slated for removal in Python 3.13
  from nntplib import NNTP
/home/runner/work/cpython/cpython/Lib/socket.py:776: ResourceWarning: unclosed <socket.socket fd=4, family=2, type=1, proto=6, laddr=('10.1.0.43', 48872), raddr=('116.202.254.214', 119)>
  self._sock = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback
<doctest default[3]>:1: DeprecationWarning: 'turtle.RawTurtle.settiltangle()' is deprecated since Python 3.1 and scheduled for removal in Python 3.13. Use tiltangle() instead.
  turtle.settiltangle(45)
<doctest default[0]>:1: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
  import imp
3.10

From https://github.com/python/cpython/runs/6954044919?check_suite_focus=true

make: Entering directory '/home/runner/work/cpython/cpython/Doc'
make[1]: Entering directory '/home/runner/work/cpython/cpython/Doc'
mkdir -p build
Building NEWS from Misc/NEWS.d with blurb
PATH=./venv/bin:$PATH sphinx-build -b doctest -d build/doctrees  -j auto -q -W --keep-going . build/doctest 
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.10/site-packages/sphinx/util/docutils.py:45: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  __version_info__ = tuple(LooseVersion(docutils.__version__).version)
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.10/site-packages/sphinx/util/rst.py:56: DeprecationWarning: 'environmentfilter' is renamed to 'pass_environment', the old name will be removed in Jinja 3.1.
  def heading(env: Environment, text: str, level: int = 1) -> str:
/home/runner/work/cpython/cpython/Doc/venv/lib/python3.10/site-packages/sphinx/jinja2glue.py:106: DeprecationWarning: 'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.
  def warning(context: Dict, message: str, *args: Any, **kwargs: Any) -> str:
<doctest default[0]>:1: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
  import imp
/home/runner/work/cpython/cpython/Lib/socket.py:776: ResourceWarning: unclosed <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('10.1.1.51', 47304), raddr=('116.202.254.214', 119)>
  self._sock = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback
<doctest default[2]>:1: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
  formatargspec(*getfullargspec(f))

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    3.11only security fixes
    3.12only security fixes
    on Jun 19, 2022
  2. CAM-Gerlach commented on Jun 19, 2022

    @CAM-Gerlach
    Member

    The stdlib's tests use the _ignore_deprecated_imports context manager; if a doctest example is for the deprecated module itself, that could be used in a hidden block, if it involves another module using the deprecated module, the example/doctest should be updated to use a replacement (or removed, if not possible).

    It seems several warnings are for third party projects (Sphinx, etc) using stdlib modules that are deprecated; in that case, those projects should be updated.

    In 3.10, the warnings look to be due to Sphinx 3.x using names deprecated in Jinja 3.x. Either it should be upgrade to use Sphinx 4, or jinja should be upper capped at <3.

  3. hugovk commented on Jun 26, 2022

    @hugovk
    Member

    It seems several warnings are for third party projects (Sphinx, etc) using stdlib modules that are deprecated; in that case, those projects should be updated.

    Third-party deprecation warnings in main and 3.11:

    /home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/babel/messages/catalog.py:13: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13

    Fixed in python-babel/babel#876, pending release.

    Edit: ✅ Released in Babel 2.11.0!

    /home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/sphinx/util/images.py:4: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13

    Pending issue: sphinx-doc/sphinx#10440

    Edit: ✅ Released in Sphinx 6.2.0!

    /home/runner/work/cpython/cpython/Doc/venv/lib/python3.12/site-packages/certifi/core.py:36: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.

    PR pending merge: certifi/python-certifi#193

    Edit: ✅ Merged via certifi/python-certifi#199 and released in Certifi 2022.06.15.1!

  4. arhadthedev commented on May 25, 2023

    @arhadthedev
    Member

    Current status (from https://github.com/python/cpython/actions/runs/5075730602/jobs/9117235935):

    Run xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest
    make: Entering directory '/home/runner/work/cpython/cpython/Doc'
    make[1]: Entering directory '/home/runner/work/cpython/cpython/Doc'
    mkdir -p build
    Building NEWS from Misc/NEWS.d with blurb
    PATH=./venv/bin:$PATH sphinx-build -b doctest -d build/doctrees  -j auto  -W --keep-going . build/doctest 
    Running Sphinx v[4](https://github.com/python/cpython/actions/runs/5075730602/jobs/9117235935#step:9:5).[5](https://github.com/python/cpython/actions/runs/5075730602/jobs/9117235935#step:9:6).0
    /home/runner/work/cpython/cpython/Doc/venv/lib/python3.13/site-packages/sphinx/util/images.py:4: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
      import imghdr
    /home/runner/work/cpython/cpython/Doc/venv/lib/python3.13/site-packages/sphinx/builders/gettext.py:1[6](https://github.com/python/cpython/actions/runs/5075730602/jobs/9117235935#step:9:7)4: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).
      datetime.utcfromtimestamp(timestamp)
    

    imghdr deprecation is addressed by gh-104818

    However, I cannot find if datetime.utcfromtimestamp deprecation is addressed so I cannot close this issue since the originally reported warnings are fixed.

  5. added
    pendingThe issue will be closed if no feedback is provided
    on May 25, 2023
  6. hugovk commented on May 25, 2023

    @hugovk
    Member

    However, I cannot find if datetime.utcfromtimestamp deprecation is addressed so I cannot close this issue since the originally reported warnings are fixed.

    The warning is new in 3.12 and first needs fixing in Sphinx:

    https://github.com/search?q=repo%3Asphinx-doc%2Fsphinx%20datetime.utcfromtimestamp&type=code

    Would you like to open an issue over there? cc @AA-Turner

  7. arhadthedev commented on May 25, 2023

    @arhadthedev
    Member

    Would you like to open an issue over there?

    I'll do it later this day if nobody else gets ahead of me.

    Btw, https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp seems to not have the deprecation note.

  8. added
    3.13only security fixes
    and removed on Oct 6, 2023
  9. AA-Turner commented on Oct 6, 2023

    @AA-Turner
    Member

    These have all been fixed (pending updating the Sphinx version).

    A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixespendingThe issue will be closed if no feedback is providedtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions