Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 655a7d0

Browse filesBrowse files
authored
Return dict instead of OrderedDict (#419)
dict is guaranteed to preserve order in all supported versions
1 parent 39774df commit 655a7d0
Copy full SHA for 655a7d0

File tree

4 files changed

+17
-16
lines changed
Filter options

4 files changed

+17
-16
lines changed

‎changelog.d/pr418.bugfix.rst

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Replace :class:`~collection.OrderedDict` with :class:`dict`.
2+
3+
The dict datatype is ordered since Python 3.7. As we do not support
4+
Python 3.6 anymore, it can be considered safe to avoid :class:`~collection.OrderedDict`.
5+
Related to :gh:`419`.

‎docs/usage/convert-version-into-different-types.rst

Copy file name to clipboardExpand all lines: docs/usage/convert-version-into-different-types.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It is possible to convert a :class:`~semver.version.Version` instance:
1717

1818
>>> v = Version(major=3, minor=4, patch=5)
1919
>>> v.to_dict()
20-
OrderedDict([('major', 3), ('minor', 4), ('patch', 5), ('prerelease', None), ('build', None)])
20+
{'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None}
2121

2222
* Into a tuple with :meth:`~semver.version.Version.to_tuple`::
2323

‎docs/usage/create-a-version.rst

Copy file name to clipboardExpand all lines: docs/usage/create-a-version.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Depending on your use case, the following methods are available:
9090
To access individual parts, you can use the function :func:`semver.parse`::
9191

9292
>>> semver.parse("3.4.5-pre.2+build.4")
93-
OrderedDict([('major', 3), ('minor', 4), ('patch', 5), ('prerelease', 'pre.2'), ('build', 'build.4')])
93+
{'major': 3, 'minor': 4, 'patch': 5, 'prerelease': 'pre.2', 'build': 'build.4'}
9494

9595
If you pass an invalid version string you will get a :py:exc:`ValueError`::
9696

‎src/semver/version.py

Copy file name to clipboardExpand all lines: src/semver/version.py
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Version handling by a semver compatible version class."""
22

3-
import collections
43
import re
54
from functools import wraps
65
from typing import (
@@ -218,27 +217,24 @@ def to_tuple(self) -> VersionTuple:
218217

219218
def to_dict(self) -> VersionDict:
220219
"""
221-
Convert the Version object to an OrderedDict.
220+
Convert the Version object to an dict.
222221
223222
.. versionadded:: 2.10.0
224223
Renamed :meth:`Version._asdict` to :meth:`Version.to_dict` to
225224
make this function available in the public API.
226225
227-
:return: an OrderedDict with the keys in the order ``major``, ``minor``,
226+
:return: an dict with the keys in the order ``major``, ``minor``,
228227
``patch``, ``prerelease``, and ``build``.
229228
230229
>>> semver.Version(3, 2, 1).to_dict()
231-
OrderedDict([('major', 3), ('minor', 2), ('patch', 1), \
232-
('prerelease', None), ('build', None)])
233-
"""
234-
return collections.OrderedDict(
235-
(
236-
("major", self.major),
237-
("minor", self.minor),
238-
("patch", self.patch),
239-
("prerelease", self.prerelease),
240-
("build", self.build),
241-
)
230+
{'major': 3, 'minor': 2, 'patch': 1, 'prerelease': None, 'build': None}
231+
"""
232+
return dict(
233+
major=self.major,
234+
minor=self.minor,
235+
patch=self.patch,
236+
prerelease=self.prerelease,
237+
build=self.build,
242238
)
243239

244240
def __iter__(self) -> VersionIterator:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.