Skip to content

Commit edef358

Browse files
bpo-29196: Removed old-deprecated classes Plist, Dict and _InternalDict (#488)
in the plistlib module. Dict values in the result of functions readPlist() and readPlistFromBytes() are now exact dicts.
1 parent d812eb7 commit edef358

File tree

5 files changed

+29
-100
lines changed

5 files changed

+29
-100
lines changed

Doc/library/plistlib.rst

+8-24
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,12 @@ The following functions are deprecated:
133133
This function calls :func:`load` to do the actual work, see the documentation
134134
of :func:`that function <load>` for an explanation of the keyword arguments.
135135

136-
.. note::
137-
138-
Dict values in the result have a ``__getattr__`` method that defers
139-
to ``__getitem_``. This means that you can use attribute access to
140-
access items of these dictionaries.
141-
142136
.. deprecated:: 3.4 Use :func:`load` instead.
143137

138+
.. versionchanged:: 3.7
139+
Dict values in the result are now normal dicts. You no longer can use
140+
attribute access to access items of these dictionaries.
141+
144142

145143
.. function:: writePlist(rootObject, pathOrFile)
146144

@@ -156,14 +154,12 @@ The following functions are deprecated:
156154

157155
See :func:`load` for a description of the keyword arguments.
158156

159-
.. note::
160-
161-
Dict values in the result have a ``__getattr__`` method that defers
162-
to ``__getitem_``. This means that you can use attribute access to
163-
access items of these dictionaries.
164-
165157
.. deprecated:: 3.4 Use :func:`loads` instead.
166158

159+
.. versionchanged:: 3.7
160+
Dict values in the result are now normal dicts. You no longer can use
161+
attribute access to access items of these dictionaries.
162+
167163

168164
.. function:: writePlistToBytes(rootObject)
169165

@@ -174,18 +170,6 @@ The following functions are deprecated:
174170

175171
The following classes are available:
176172

177-
.. class:: Dict([dict]):
178-
179-
Return an extended mapping object with the same value as dictionary
180-
*dict*.
181-
182-
This class is a subclass of :class:`dict` where attribute access can
183-
be used to access items. That is, ``aDict.key`` is the same as
184-
``aDict['key']`` for getting, setting and deleting items in the mapping.
185-
186-
.. deprecated:: 3.0
187-
188-
189173
.. class:: Data(data)
190174

191175
Return a "data" wrapper object around the bytes object *data*. This is used

Doc/whatsnew/3.7.rst

+6
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ API and Feature Removals
299299
longer take keyword arguments. The first argument of :func:`int` can now
300300
be passes only as positional argument.
301301

302+
* Removed previously deprecated in Python 2.4 classes ``Plist``, ``Dict`` and
303+
``_InternalDict`` in the :mod:`plistlib` module. Dict values in the result
304+
of functions :func:`~plistlib.readPlist` and
305+
:func:`~plistlib.readPlistFromBytes` are now normal dicts. You no longer
306+
can use attribute access to access items of these dictionaries.
307+
302308

303309
Porting to Python 3.7
304310
=====================

Lib/plistlib.py

+3-68
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"""
4848
__all__ = [
4949
"readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
50-
"Plist", "Data", "Dict", "InvalidFileException", "FMT_XML", "FMT_BINARY",
50+
"Data", "InvalidFileException", "FMT_XML", "FMT_BINARY",
5151
"load", "dump", "loads", "dumps"
5252
]
5353

@@ -76,44 +76,6 @@
7676
#
7777

7878

79-
class _InternalDict(dict):
80-
81-
# This class is needed while Dict is scheduled for deprecation:
82-
# we only need to warn when a *user* instantiates Dict or when
83-
# the "attribute notation for dict keys" is used.
84-
__slots__ = ()
85-
86-
def __getattr__(self, attr):
87-
try:
88-
value = self[attr]
89-
except KeyError:
90-
raise AttributeError(attr)
91-
warn("Attribute access from plist dicts is deprecated, use d[key] "
92-
"notation instead", DeprecationWarning, 2)
93-
return value
94-
95-
def __setattr__(self, attr, value):
96-
warn("Attribute access from plist dicts is deprecated, use d[key] "
97-
"notation instead", DeprecationWarning, 2)
98-
self[attr] = value
99-
100-
def __delattr__(self, attr):
101-
try:
102-
del self[attr]
103-
except KeyError:
104-
raise AttributeError(attr)
105-
warn("Attribute access from plist dicts is deprecated, use d[key] "
106-
"notation instead", DeprecationWarning, 2)
107-
108-
109-
class Dict(_InternalDict):
110-
111-
def __init__(self, **kwargs):
112-
warn("The plistlib.Dict class is deprecated, use builtin dict instead",
113-
DeprecationWarning, 2)
114-
super().__init__(**kwargs)
115-
116-
11779
@contextlib.contextmanager
11880
def _maybe_open(pathOrFile, mode):
11981
if isinstance(pathOrFile, str):
@@ -124,31 +86,6 @@ def _maybe_open(pathOrFile, mode):
12486
yield pathOrFile
12587

12688

127-
class Plist(_InternalDict):
128-
"""This class has been deprecated. Use dump() and load()
129-
functions instead, together with regular dict objects.
130-
"""
131-
132-
def __init__(self, **kwargs):
133-
warn("The Plist class is deprecated, use the load() and "
134-
"dump() functions instead", DeprecationWarning, 2)
135-
super().__init__(**kwargs)
136-
137-
@classmethod
138-
def fromFile(cls, pathOrFile):
139-
"""Deprecated. Use the load() function instead."""
140-
with _maybe_open(pathOrFile, 'rb') as fp:
141-
value = load(fp)
142-
plist = cls()
143-
plist.update(value)
144-
return plist
145-
146-
def write(self, pathOrFile):
147-
"""Deprecated. Use the dump() function instead."""
148-
with _maybe_open(pathOrFile, 'wb') as fp:
149-
dump(self, fp)
150-
151-
15289
def readPlist(pathOrFile):
15390
"""
15491
Read a .plist from a path or file. pathOrFile should either
@@ -160,8 +97,7 @@ def readPlist(pathOrFile):
16097
DeprecationWarning, 2)
16198

16299
with _maybe_open(pathOrFile, 'rb') as fp:
163-
return load(fp, fmt=None, use_builtin_types=False,
164-
dict_type=_InternalDict)
100+
return load(fp, fmt=None, use_builtin_types=False)
165101

166102
def writePlist(value, pathOrFile):
167103
"""
@@ -184,8 +120,7 @@ def readPlistFromBytes(data):
184120
"""
185121
warn("The readPlistFromBytes function is deprecated, use loads() instead",
186122
DeprecationWarning, 2)
187-
return load(BytesIO(data), fmt=None, use_builtin_types=False,
188-
dict_type=_InternalDict)
123+
return load(BytesIO(data), fmt=None, use_builtin_types=False)
189124

190125

191126
def writePlistToBytes(value):

Lib/test/test_plistlib.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def test_bytes(self):
173173
pl = self._create()
174174
data = plistlib.dumps(pl)
175175
pl2 = plistlib.loads(data)
176-
self.assertNotIsInstance(pl, plistlib._InternalDict)
177176
self.assertEqual(dict(pl), dict(pl2))
178177
data2 = plistlib.dumps(pl2)
179178
self.assertEqual(data, data2)
@@ -454,14 +453,14 @@ def test_io_deprecated(self):
454453
'data': b'buffer',
455454
}
456455
}
457-
pl_out = plistlib._InternalDict({
456+
pl_out = {
458457
'key': 42,
459-
'sub': plistlib._InternalDict({
458+
'sub': {
460459
'key': 9,
461460
'alt': 'value',
462461
'data': plistlib.Data(b'buffer'),
463-
})
464-
})
462+
}
463+
}
465464

466465
self.addCleanup(support.unlink, support.TESTFN)
467466
with self.assertWarns(DeprecationWarning):
@@ -499,10 +498,10 @@ def test_bytes_deprecated(self):
499498
with self.assertWarns(DeprecationWarning):
500499
pl2 = plistlib.readPlistFromBytes(data)
501500

502-
self.assertIsInstance(pl2, plistlib._InternalDict)
503-
self.assertEqual(pl2, plistlib._InternalDict(
501+
self.assertIsInstance(pl2, dict)
502+
self.assertEqual(pl2, dict(
504503
key=42,
505-
sub=plistlib._InternalDict(
504+
sub=dict(
506505
key=9,
507506
alt='value',
508507
data=plistlib.Data(b'buffer'),

Misc/NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ Extension Modules
323323
Library
324324
-------
325325

326+
- bpo-29196: Removed previously deprecated in Python 2.4 classes Plist, Dict
327+
and _InternalDict in the plistlib module. Dict values in the result of
328+
functions readPlist() and readPlistFromBytes() are now normal dicts. You
329+
no longer can use attribute access to access items of these dictionaries.
330+
326331
- bpo-9850: The :mod:`macpath` is now deprecated and will be removed
327332
in Python 3.8.
328333

0 commit comments

Comments
 (0)