Skip to content

Commit acf766b

Browse files
committed
docs(collections): Cleaned up documentation in response to building docs and running lint, plus other minor clean-up.
1 parent aa39352 commit acf766b

9 files changed

+63
-46
lines changed

HISTORY.rst

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
History
44
-------
55

6-
???
7-
~~~
8-
* Worked to switch out the custom OrderedMultiDict with the 3rd party
9-
multidict.MultiDict. Still in-process, have identified issues in
10-
the docstring for pvl._collections.PVLMultiDict, not all tests passing.
6+
1.0.0-alpha.9 (2020-08-18)
7+
~~~~~~~~~~~~~~~~~~~~~~~~~~
8+
* Minor addition to pvl.collections.MutableMappingSequence.
9+
* Implemented PVLMultiDict which is based on the 3rd Party
10+
`multidict.MultiDict` object as an option to use instead
11+
of the default OrderedMultiDict. The new PVLMultiDict
12+
is better aligned with the Python 3 way that Mapping
13+
objects behave.
14+
* Enhanced the existing OrderedMultiDict with some functionality
15+
that extends its behavior closer to the Python 3 ideal, and
16+
inserted warnings about how the retained non-Python-3
17+
behaviors might be removed at the next major patch.
18+
* Implemented pvl.new that can be included for those that wish
19+
to try out what getting the new PVLMultiDict returned from
20+
the loaders might be like by just changing an import statement.
1121

1222
1.0.0-alpha.8 (2020-08-01)
1323
~~~~~~~~~~~~~~~~~~~~~~~~~~

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ dependencies:
1919
- python-dateutil
2020
- astropy
2121
- pint
22+
- multidict

pvl/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
__author__ = 'The pvl Developers'
2626
__email__ = '[email protected]'
27-
__version__ = '1.0.0-alpha.8'
27+
__version__ = '1.0.0-alpha.9'
2828
__all__ = [
2929
'load',
3030
'loads',

pvl/collections.py

+27-28
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ def _insert_arg_helper(args):
489489

490490
return kvlist
491491

492-
try:
492+
493+
try: # noqa: C901
493494
# In order to access super class attributes for our derived class, we must
494495
# import the native Python version, instead of the default Cython version.
495496
from multidict._multidict_py import MultiDict
@@ -500,30 +501,31 @@ class PVLMultiDict(MultiDict, MutableMappingSequence):
500501
OrderedMultiDict).
501502
502503
Here is a summary of the differences:
503-
- OrderedMultiDict.getall('k') where k is not in the structure returns
504-
an empty list, PVLMultiDict.getall('k') properly returns a KeyError.
505-
- The .items(), .keys(), and .values() are proper iterators
506-
and don't return sequences like OrderedMultiDict did.
507-
- Calling list() on an OrderedMultiDict returns a list of tuples, which
508-
is like calling list() on the results of a dict.items() iterator.
509-
Calling list() on a PVLMultiDict returns just a list of keys,
510-
which is semantically identical to calling list() on a dict.
511-
- OrderedMultiDict.pop(k) removed all keys that matched k,
512-
PVLMultiDict.pop(k) just removes the first occurrence.
513-
PVLMultiDict.popall(k) would pop all.
514-
- OrderedMultiDict.popitem() removes the last item from the underlying
515-
list, PVLMultiDict.popitem() removes an arbitrary key, value pair,
516-
semantically identical to .popitem() on a dict.
517-
- OrderedMultiDict.__repr__() and .__str__() return identical strings,
518-
PVLMultiDict provides a .__str__() that is pretty-printed similar
519-
to OrderedMultiDict, but also a .__repr__() with a more compact
520-
representation.
521-
- equality is different: OrderedMultiDict has an isinstance()
522-
check in the __eq__() operator, which I don't think was right,
523-
since equality is about values, not about type. PVLMultiDict
524-
has a value-based notion of equality. So an empty PVLGroup and an
525-
empty PVLObject derived from PVLMultiDict could test equal,
526-
but would fail an isinstance() check.
504+
505+
* OrderedMultiDict.getall('k') where k is not in the structure returns
506+
an empty list, PVLMultiDict.getall('k') properly returns a KeyError.
507+
* The .items(), .keys(), and .values() are proper iterators
508+
and don't return sequences like OrderedMultiDict did.
509+
* Calling list() on an OrderedMultiDict returns a list of tuples, which
510+
is like calling list() on the results of a dict.items() iterator.
511+
Calling list() on a PVLMultiDict returns just a list of keys,
512+
which is semantically identical to calling list() on a dict.
513+
* OrderedMultiDict.pop(k) removed all keys that matched k,
514+
PVLMultiDict.pop(k) just removes the first occurrence.
515+
PVLMultiDict.popall(k) would pop all.
516+
* OrderedMultiDict.popitem() removes the last item from the underlying
517+
list, PVLMultiDict.popitem() removes an arbitrary key, value pair,
518+
semantically identical to .popitem() on a dict.
519+
* OrderedMultiDict.__repr__() and .__str__() return identical strings,
520+
PVLMultiDict provides a .__str__() that is pretty-printed similar
521+
to OrderedMultiDict, but also a .__repr__() with a more compact
522+
representation.
523+
* Equality is different: OrderedMultiDict has an isinstance()
524+
check in the __eq__() operator, which I don't think was right,
525+
since equality is about values, not about type. PVLMultiDict
526+
has a value-based notion of equality. So an empty PVLGroup and an
527+
empty PVLObject derived from PVLMultiDict could test equal,
528+
but would fail an isinstance() check.
527529
"""
528530
# Also evaluated the boltons.OrderedMultiDict, but its semantics were
529531
# too different #52
@@ -669,15 +671,12 @@ def append(self, key, value):
669671
class PVLModuleNew(PVLMultiDict):
670672
pass
671673

672-
673674
class PVLAggregationNew(PVLMultiDict):
674675
pass
675676

676-
677677
class PVLGroupNew(PVLAggregationNew):
678678
pass
679679

680-
681680
class PVLObjectNew(PVLAggregationNew):
682681
pass
683682

pvl/new.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import inspect
2525
import urllib.request
2626

27-
from pvl import *
27+
from pvl import * # noqa: F401,F403
2828
from pvl import get_text_from, decode_by_char
2929

3030
from .parser import PVLParser, OmniParser
@@ -123,4 +123,4 @@ def loads(s: str, parser=None, grammar=None, decoder=None, **kwargs):
123123
elif not isinstance(parser, PVLParser):
124124
raise TypeError('The parser must be an instance of pvl.PVLParser.')
125125

126-
return parser.parse(s)
126+
return parser.parse(s)

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.0-alpha.8
2+
current_version = 1.0.0-alpha.9
33
commit = False
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<prerelease>[a-z]+)\.((?P<serial>\d+)))?

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='pvl',
15-
version='1.0.0-alpha.8',
15+
version='1.0.0-alpha.9',
1616
description='Python implementation of PVL (Parameter Value Language)',
1717
long_description=readme + '\n\n' + history,
1818
author='The PlanetaryPy Developers',

tests/test_collections.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,26 @@ def test_copy(self):
278278
self.assertNotEqual(module, copy)
279279

280280
def test_equality(self):
281-
for modcls, grpcls, objcls in (
281+
classes = [
282282
(
283283
pvl.collections.PVLModule,
284284
pvl.collections.PVLGroup,
285285
pvl.collections.PVLObject
286-
),
287-
(
288-
pvl.collections.PVLModuleNew,
289-
pvl.collections.PVLGroupNew,
290-
pvl.collections.PVLObjectNew
291286
)
292-
):
287+
]
288+
try:
289+
from pvl.collections import PVLMultiDict
290+
classes.append(
291+
(
292+
pvl.collections.PVLModuleNew,
293+
pvl.collections.PVLGroupNew,
294+
pvl.collections.PVLObjectNew
295+
)
296+
)
297+
except ImportError:
298+
pass
299+
300+
for modcls, grpcls, objcls in classes:
293301
module = modcls()
294302
group = grpcls()
295303
obj = objcls()

tests/test_pvl.py

-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ def test_broken_labels(label, expected, expected_errors):
990990
# But this should compare the 'line numbers' of the EmptyValueAtLine
991991
# objects.
992992
assert module.errors == expected_errors
993-
# assert not module.valid
994993

995994

996995
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)