backports — Python Backports#

This module contains backports to support older Python versions.

class backports.nullcontext(enter_result=None)[source]#

Bases: object

Context manager that does no additional processing.

See also

contextlib.nullcontext, backported from Python 3.7.

Parameters:

enter_result (Any) –

backports.pairwise(iterable)[source]#

Return successive overlapping pairs taken from the input iterable.

See also

itertools.pairwise, backported from Python 3.10.

New in version 7.6.

backports.removeprefix(string, prefix)[source]#

Remove prefix from a string or return a copy otherwise.

>>> removeprefix('TestHook', 'Test')
'Hook'
>>> removeprefix('BaseTestCase', 'Test')
'BaseTestCase'

See also

str.removeprefix, backported from Python 3.9.

New in version 5.4.

Parameters:
  • string (str) –

  • prefix (str) –

Return type:

str

backports.removesuffix(string, suffix)[source]#

Remove suffix from a string or return a copy otherwise.

>>> removesuffix('MiscTests', 'Tests')
'Misc'
>>> removesuffix('TmpDirMixin', 'Tests')
'TmpDirMixin'

See also

str.removesuffix, backported from Python 3.9.

New in version 5.4.

Parameters:
  • string (str) –

  • suffix (str) –

Return type:

str