Skip to content

Commit

Permalink
Deprecate cidict's strlist functions
Browse files Browse the repository at this point in the history
The functions are undocumented, untested, unused, and can now be trivialy
implemented with set operations.

https://github.com/python-ldap/python-ldap/pull/336

Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and GitHub committed Jun 5, 2020
1 parent f8f10a9 commit 269df17
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Lib/ldap/cidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
See https://www.python-ldap.org/ for details.
"""
import warnings

from ldap import __version__

Expand Down Expand Up @@ -62,6 +63,11 @@ def strlist_minus(a,b):
Return list of all items in a which are not in b (a - b).
a,b are supposed to be lists of case-insensitive strings.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in b:
temp[elt] = elt
Expand All @@ -77,6 +83,11 @@ def strlist_intersection(a,b):
"""
Return intersection of two lists of case-insensitive strings a,b.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in a:
temp[elt] = elt
Expand All @@ -92,6 +103,11 @@ def strlist_union(a,b):
"""
Return union of two lists of case-insensitive strings a,b.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in a:
temp[elt] = elt
Expand Down
14 changes: 14 additions & 0 deletions Tests/t_cidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import unittest
import warnings

# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'
Expand Down Expand Up @@ -48,6 +49,19 @@ def test_cidict(self):
self.assertEqual(cix.has_key("abcdef"), False)
self.assertEqual(cix.has_key("AbCDef"), False)

def test_strlist_deprecated(self):
strlist_funcs = [
ldap.cidict.strlist_intersection,
ldap.cidict.strlist_minus,
ldap.cidict.strlist_union
]
for strlist_func in strlist_funcs:
with warnings.catch_warnings(record=True) as w:
warnings.resetwarnings()
warnings.simplefilter("always", DeprecationWarning)
strlist_func(["a"], ["b"])
self.assertEqual(len(w), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 269df17

Please sign in to comment.