Skip to content

Commit aa91df6

Browse files
committed
improved is_pangram and is_palindrome
1 parent 625d960 commit aa91df6

File tree

13 files changed

+49
-22
lines changed

13 files changed

+49
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Python String Utils Changelog
22

3+
## v0.4.1
4+
5+
### Changed:
6+
- is_palindrome and is_pangram now return False if the given object is not a string instead of raising an exception
7+
8+
39
## v0.4.0
410

511
### Added:
-75 Bytes
Binary file not shown.

docs/_build/doctrees/index.doctree

1.55 KB
Binary file not shown.

docs/_build/html/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 76a6be5326d21a1075be87b1431e2261
3+
config: 570d49f719075ab443795a1c37a0913b
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/_build/html/genindex.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1111

12-
<title>Index &mdash; Python String Utils 0.4.0 documentation</title>
12+
<title>Index &mdash; Python String Utils 0.4.1 documentation</title>
1313

1414

1515

@@ -34,7 +34,7 @@
3434
<link rel="index" title="Index"
3535
href="#"/>
3636
<link rel="search" title="Search" href="search.html"/>
37-
<link rel="top" title="Python String Utils 0.4.0 documentation" href="index.html"/>
37+
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
3838

3939

4040
<script src="_static/js/modernizr.min.js"></script>
@@ -62,7 +62,7 @@
6262

6363

6464
<div class="version">
65-
0.4.0
65+
0.4.1
6666
</div>
6767

6868

@@ -303,7 +303,7 @@ <h2 id="W">W</h2>
303303
<script type="text/javascript">
304304
var DOCUMENTATION_OPTIONS = {
305305
URL_ROOT:'./',
306-
VERSION:'0.4.0',
306+
VERSION:'0.4.1',
307307
COLLAPSE_INDEX:false,
308308
FILE_SUFFIX:'.html',
309309
HAS_SOURCE: true

docs/_build/html/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Welcome to Python String Utils’s documentation! &mdash; Python String Utils 0.4.0 documentation</title>
11+
<title>Welcome to Python String Utils’s documentation! &mdash; Python String Utils 0.4.1 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="search.html"/>
36-
<link rel="top" title="Python String Utils 0.4.0 documentation" href="#"/>
36+
<link rel="top" title="Python String Utils 0.4.1 documentation" href="#"/>
3737

3838

3939
<script src="_static/js/modernizr.min.js"></script>
@@ -61,7 +61,7 @@
6161

6262

6363
<div class="version">
64-
0.4.0
64+
0.4.1
6565
</div>
6666

6767

@@ -628,7 +628,7 @@ <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Pe
628628
<script type="text/javascript">
629629
var DOCUMENTATION_OPTIONS = {
630630
URL_ROOT:'./',
631-
VERSION:'0.4.0',
631+
VERSION:'0.4.1',
632632
COLLAPSE_INDEX:false,
633633
FILE_SUFFIX:'.html',
634634
HAS_SOURCE: true

docs/_build/html/objects.inv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sphinx inventory version 2
22
# Project: Python String Utils
3-
# Version: 0.4.0
3+
# Version: 0.4.1
44
# The remainder of this file is compressed using zlib.
55
xڝ��N! ���M<�ƽ�x0�dc<:3(_�E����;FcRo�����d�$3�".t� ��>v39{�l���;��w�r`�$�^�B=b�~ ��o�IO�x���� �K`&�@*`�<�2�M��_��XDT�(Rp������A�����m�crb�:g�yИ�Ȍ I��uw��8Z�U�:Nk�s貉�Yb�=$]�(dOS��"�����r�~/��U'�벻�t�h�x;�� � �%Щu�c��EA����,���O�5.��ю}h_\����0'���O�Tt��M݊

docs/_build/html/py-modindex.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Python Module Index &mdash; Python String Utils 0.4.0 documentation</title>
11+
<title>Python Module Index &mdash; Python String Utils 0.4.1 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="search.html"/>
36-
<link rel="top" title="Python String Utils 0.4.0 documentation" href="index.html"/>
36+
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
3737

3838

3939
<script type="text/javascript">
@@ -68,7 +68,7 @@
6868

6969

7070
<div class="version">
71-
0.4.0
71+
0.4.1
7272
</div>
7373

7474

@@ -181,7 +181,7 @@ <h1>Python Module Index</h1>
181181
<script type="text/javascript">
182182
var DOCUMENTATION_OPTIONS = {
183183
URL_ROOT:'./',
184-
VERSION:'0.4.0',
184+
VERSION:'0.4.1',
185185
COLLAPSE_INDEX:false,
186186
FILE_SUFFIX:'.html',
187187
HAS_SOURCE: true

docs/_build/html/search.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Search &mdash; Python String Utils 0.4.0 documentation</title>
11+
<title>Search &mdash; Python String Utils 0.4.1 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="#"/>
36-
<link rel="top" title="Python String Utils 0.4.0 documentation" href="index.html"/>
36+
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
3737

3838

3939
<script src="_static/js/modernizr.min.js"></script>
@@ -61,7 +61,7 @@
6161

6262

6363
<div class="version">
64-
0.4.0
64+
0.4.1
6565
</div>
6666

6767

@@ -167,7 +167,7 @@
167167
<script type="text/javascript">
168168
var DOCUMENTATION_OPTIONS = {
169169
URL_ROOT:'./',
170-
VERSION:'0.4.0',
170+
VERSION:'0.4.1',
171171
COLLAPSE_INDEX:false,
172172
FILE_SUFFIX:'.html',
173173
HAS_SOURCE: true

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
# built documents.
5959
#
6060
# The short X.Y version.
61-
version = '0.4.0'
61+
version = '0.4.1'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '0.4.0'
63+
release = '0.4.1'
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='python-string-utils',
8-
version='0.4.0',
8+
version='0.4.1',
99
description='Utility functions for strings checking and manipulation.',
1010
long_description=long_description,
1111
author='Davide Zanotti',

string_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ def is_palindrome(string, strict=True):
353353
:return: True if the string is a palindrome (like "otto", or "i topi non avevano nipoti" if strict=False),
354354
False otherwise
355355
"""
356+
if not is_string(string):
357+
return False
356358
if strict:
357359
return reverse(string) == string
358360
return is_palindrome(SPACES_RE.sub('', string))
@@ -365,7 +367,10 @@ def is_pangram(string):
365367
:param string: String to check.
366368
:return: True if the string is a pangram, False otherwise.
367369
"""
368-
return set(SPACES_RE.sub('', string)).issuperset(letters_set)
370+
try:
371+
return set(SPACES_RE.sub('', string)).issuperset(letters_set)
372+
except TypeError:
373+
return False
369374

370375

371376
def words_count(string):

tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,14 @@ def test_should_work_as_expected_for_multiple_lines_string(self):
12041204

12051205
class IsPalindromeTestCase(TestCase):
12061206

1207+
def test_non_string_objects_return_false(self):
1208+
self.assertFalse(is_palindrome(1))
1209+
self.assertFalse(is_palindrome(['xx']))
1210+
self.assertFalse(is_palindrome({}))
1211+
self.assertFalse(is_palindrome(False))
1212+
self.assertFalse(is_palindrome((1, 2, 3)))
1213+
self.assertFalse(is_palindrome(object()))
1214+
12071215
def test_strict_checking(self):
12081216
self.assertFalse(is_palindrome('nope!'))
12091217
self.assertFalse(is_palindrome('i topi non avevano nipoti'))
@@ -1216,6 +1224,14 @@ def test_no_strict_mode(self):
12161224

12171225

12181226
class IsPangramTestCase(TestCase):
1227+
def test_non_string_objects_return_false(self):
1228+
self.assertFalse(is_pangram(1))
1229+
self.assertFalse(is_pangram(['xx']))
1230+
self.assertFalse(is_pangram({}))
1231+
self.assertFalse(is_pangram(False))
1232+
self.assertFalse(is_pangram((1, 2, 3)))
1233+
self.assertFalse(is_pangram(object()))
1234+
12191235
def test_is_pangram_returns_expected_bool(self):
12201236
self.assertFalse(is_pangram('hello world'))
12211237
self.assertTrue(is_pangram('The quick brown fox jumps over the lazy dog'))

0 commit comments

Comments
 (0)