Skip to content

Commit dde38ff

Browse files
committed
Remove obsolete Python 2 compatibility code
The changes are mostly related to unicode and conditional imports.
1 parent 8a98b37 commit dde38ff

8 files changed

Lines changed: 18 additions & 24 deletions

File tree

docs/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Nameparser documentation build configuration file, created by
43
# sphinx-quickstart on Fri May 16 01:29:58 2014.
@@ -49,8 +48,8 @@
4948
master_doc = 'index'
5049

5150
# General information about the project.
52-
project = u'Nameparser'
53-
copyright = u'{:%Y}, Derek Gulbranson'.format(date.today())
51+
project = 'Nameparser'
52+
copyright = '{:%Y}, Derek Gulbranson'.format(date.today())
5453

5554
# The version info for the project you're documenting, acts as replacement for
5655
# |version| and |release|, also used in various other places throughout the
@@ -223,8 +222,8 @@
223222
# (source start file, target name, title,
224223
# author, documentclass [howto, manual, or own class]).
225224
latex_documents = [
226-
('index', 'Nameparser.tex', u'Nameparser Documentation',
227-
u'Derek Gulbranson', 'manual'),
225+
('index', 'Nameparser.tex', 'Nameparser Documentation',
226+
'Derek Gulbranson', 'manual'),
228227
]
229228

230229
# The name of an image file (relative to this directory) to place at the top of
@@ -253,8 +252,8 @@
253252
# One entry per manual page. List of tuples
254253
# (source start file, name, description, authors, manual section).
255254
man_pages = [
256-
('index', 'nameparser', u'Nameparser Documentation',
257-
[u'Derek Gulbranson'], 1)
255+
('index', 'nameparser', 'Nameparser Documentation',
256+
['Derek Gulbranson'], 1)
258257
]
259258

260259
# If true, show URL addresses after external links.
@@ -267,8 +266,8 @@
267266
# (source start file, target name, title, author,
268267
# dir menu entry, description, category)
269268
texinfo_documents = [
270-
('index', 'Nameparser', u'Nameparser Documentation',
271-
u'Derek Gulbranson', 'Nameparser', 'A simple python modules for parsing human names into components.',
269+
('index', 'Nameparser', 'Nameparser Documentation',
270+
'Derek Gulbranson', 'Nameparser', 'A simple python modules for parsing human names into components.',
272271
'Miscellaneous'),
273272
]
274273

nameparser/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __reduce__(self):
125125
return (TupleManager, (), self.__getstate__())
126126

127127

128-
class Constants(object):
128+
class Constants:
129129
"""
130130
An instance of this class hold all of the configuration constants for the parser.
131131

nameparser/config/capitalization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
)
88
"""
99
Any pieces that are not capitalized by capitalizing the first letter.
10-
"""
10+
"""

nameparser/config/conjunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
Pieces that should join to their neighboring pieces, e.g. "and", "y" and "&".
1313
"of" and "the" are also include to facilitate joining multiple titles,
1414
e.g. "President of the United States".
15-
"""
15+
"""

nameparser/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def group_contiguous_integers(data):
2424
return ranges
2525

2626

27-
class HumanName(object):
27+
class HumanName:
2828
"""
2929
Parse a person's name into individual components.
3030
@@ -352,7 +352,7 @@ def _set_list(self, attr, value):
352352
else:
353353
raise TypeError(
354354
"Can only assign strings, lists or None to name attributes."
355-
" Got {0}".format(type(value)))
355+
f" Got {0}".format(type(value)))
356356
setattr(self, attr+"_list", self.parse_pieces(val))
357357

358358
@title.setter
@@ -733,7 +733,7 @@ def parse_pieces(self, parts, additional_parts_count=0):
733733
for part in parts:
734734
if not isinstance(part, (str, bytes)):
735735
raise TypeError("Name parts must be strings. "
736-
"Got {0}".format(type(part)))
736+
f"Got {type(part)}")
737737
output += [x.strip(' ,') for x in part.split(' ')]
738738

739739
# If part contains periods, check if it's multiple titles or suffixes

nameparser/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
# http://code.google.com/p/python-nameparser/issues/detail?id=10
3+
44
log = logging.getLogger('HumanName')
55
log.addHandler(logging.NullHandler())
66
log.setLevel(logging.ERROR)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import nameparser
44
import os
55

6+
67
def read(fname):
78
return open(os.path.join(os.path.dirname(__file__), fname)).read()
89

tests.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929

3030
log = logging.getLogger('HumanName')
3131

32-
try:
33-
unittest.expectedFailure
34-
except AttributeError:
35-
# Python 2.6 backport
36-
import unittest2 as unittest
37-
3832

3933
class HumanNameTestBase(unittest.TestCase):
4034
def m(self, actual, expected, hn):
@@ -2608,9 +2602,9 @@ def test_variations_of_TEST_NAMES(self):
26082602
log.addHandler(logging.StreamHandler())
26092603
name_string = sys.argv[1]
26102604
hn_instance = HumanName(name_string, encoding=sys.stdout.encoding)
2611-
print((repr(hn_instance)))
2605+
print(repr(hn_instance))
26122606
hn_instance.capitalize()
2613-
print((repr(hn_instance)))
2607+
print(repr(hn_instance))
26142608
print("Initials: " + hn_instance.initials())
26152609
else:
26162610
print("-"*80)

0 commit comments

Comments
 (0)