Skip to content

Commit cf23fa8

Browse files
committed
Updated docs and refactoring to avoid name clashes.
1 parent 3e78601 commit cf23fa8

16 files changed

Lines changed: 83 additions & 78 deletions

cawdrey/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
# this package
3030
from .alphadict import AlphaDict, alphabetical_dict
3131
from .base import FrozenBase, MutableBase
32-
from .bdict import bdict
33-
from .frozendict import frozendict
32+
from ._bdict import bdict
33+
from ._frozendict import frozendict
3434
from .frozenordereddict import FrozenOrderedDict
3535
from .nonelessdict import NonelessDict, NonelessOrderedDict
3636

cawdrey/bdict.py renamed to cawdrey/_bdict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class bdict(UserDict):
5858
5959
Based on https://stackoverflow.com/a/1063393 by https://stackoverflow.com/users/9493/brian
6060
61-
Improved May 2020 suggestions from
61+
Improved May 2020 with suggestions from
6262
https://treyhunner.com/2019/04/why-you-shouldnt-inherit-from-list-and-dict-in-python/
6363
"""
6464

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __hash__(self) -> int:
6060

6161
def sorted(self, *args, by: str = "keys", **kwargs):
6262
"""
63-
Return a new :class:`~cawdrey.frozendict.frozendict`, with the element
63+
Return a new :class:`~cawdrey.frozendict`, with the element
6464
insertion sorted. The signature is the same as the builtin
6565
:class:`python:sorted` function, except for the additional parameter
6666
``by``, that is ``"keys"`` by default and can also be ``"values"`` and

cawdrey/frozenordereddict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self, *args, **kwargs):
4949

5050
def copy(self, *args, **kwargs):
5151
"""
52-
Return a copy of the :class:`~cawdrey.frozenordereddict.FrozenOrderedDict`.
52+
Return a copy of the :class:`~cawdrey.FrozenOrderedDict`.
5353
5454
:param args:
5555
:type args:

doc-source/base.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Base Class
55
About
66
========
77

8-
``FrozenBase`` is the base class for :class:`~cawdrey.frozendict.frozendict`
9-
and :class:`~cawdrey.frozenordereddict.FrozenOrderedDict`. If you wish to
8+
``FrozenBase`` is the base class for :class:`~cawdrey.frozendict`
9+
and :class:`~cawdrey.FrozenOrderedDict`. If you wish to
1010
construct your own frozen dictionary classes, you may wish to inherit from
1111
this class.
1212

@@ -17,9 +17,10 @@ Usage
1717
API Reference
1818
===========================
1919

20-
.. autoclass:: cawdrey.base.FrozenBase
20+
.. automodule:: cawdrey.base
2121
:members:
2222
:inherited-members:
2323
:special-members:
2424
:private-members:
2525
:undoc-members:
26+
:exclude-members: __dict__

doc-source/classes/alphadict.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Usage
1212
API Reference
1313
===========================
1414

15-
.. automodule:: cawdrey.alphadict
16-
:members:
17-
:undoc-members:
15+
.. autoclass:: cawdrey.AlphaDict
16+
:members:
17+
:undoc-members:
18+
:special-members:
19+
:inherited-members:
20+
:exclude-members: __dict__

doc-source/classes/bdict.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ API Reference
1515
.. autoclass:: cawdrey.bdict
1616
:members:
1717
:undoc-members:
18+
:special-members:
19+
:inherited-members:
20+
:exclude-members: __dict__

doc-source/classes/frozendict.rst

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ frozendict
55
About
66
========
77

8-
:class:`~cawdrey.frozendict.frozendict` is an immutable wrapper around dictionaries that implements the
8+
:class:`~cawdrey.frozendict` is an immutable wrapper around dictionaries that implements the
99
complete mapping interface. It can be used as a drop-in replacement for
1010
dictionaries where immutability is desired.
1111

1212
Of course, this is ``python``, and you can still poke around the object's
1313
internals if you want.
1414

15-
The :class:`~cawdrey.frozendict.frozendict` constructor mimics ``dict``, and all of the expected
15+
The :class:`~cawdrey.frozendict` constructor mimics :class:`dict`, and all of the expected
1616
interfaces (``iter``, ``len``, ``repr``, ``hash``, ``getitem``) are provided.
17-
Note that a :class:`~cawdrey.frozendict.frozendict` does not guarantee the immutability of its values, so
18-
the utility of ``hash`` method is restricted by usage.
17+
Note that a :class:`~cawdrey.frozendict` does not guarantee the immutability of its values, so
18+
the utility of the ``hash`` method is restricted by usage.
1919

20-
The only difference is that the ``copy()`` method of :class:`~cawdrey.frozendict.frozendict` takes
20+
The only difference is that the ``copy()`` method of :class:`~cawdrey.frozendict` takes
2121
variable keyword arguments, which will be present as key/value pairs in the new,
2222
immutable copy.
2323

@@ -26,7 +26,7 @@ Usage
2626

2727
.. code-block:: python
2828
29-
>>> from frozendict import frozendict
29+
>>> from cawdrey import frozendict
3030
>>>
3131
>>> fd = frozendict({ 'hello': 'World' })
3232
>>>
@@ -40,17 +40,17 @@ Usage
4040
<frozendict {'hello': 'World', 'another': 'key/value'}>
4141
>>>
4242
43-
In addition, :class:`~cawdrey.frozendict.frozendict` supports the `+` and `-` operands. If you add a
44-
`dict`-like object, a new :class:`~cawdrey.frozendict.frozendict` will be returned, equal to the old
45-
:class:`~cawdrey.frozendict.frozendict` updated with the other object. Example:
43+
In addition, :class:`~cawdrey.frozendict` supports the `+` and `-` operands. If you add a
44+
`dict`-like object, a new :class:`~cawdrey.frozendict` will be returned, equal to the old
45+
:class:`~cawdrey.frozendict` updated with the other object. Example:
4646

4747
.. code-block:: python
4848
4949
>>> frozendict({"Sulla": "Marco", 2: 3}) + {"Sulla": "Marò", 4: 7}
5050
<frozendict {'Sulla': 'Marò', 2: 3, 4: 7}>
5151
>>>
5252
53-
You can also subtract an iterable from a :class:`~cawdrey.frozendict.frozendict`. A new :class:`~cawdrey.frozendict.frozendict`
53+
You can also subtract an iterable from a :class:`~cawdrey.frozendict`. A new :class:`~cawdrey.frozendict`
5454
will be returned, without the keys that are in the iterable. Examples:
5555

5656
.. code-block::
@@ -66,7 +66,7 @@ Some other examples:
6666

6767
.. code-block:: python
6868
69-
>>> from frozendict import frozendict
69+
>>> from cawdrey import frozendict
7070
>>> fd = frozendict({"Sulla": "Marco", "Hicks": "Bill"})
7171
>>> print(fd)
7272
<frozendict {'Sulla': 'Marco', 'Hicks': 'Bill'}>
@@ -137,26 +137,23 @@ API Reference
137137
.. autoclass:: cawdrey.frozendict
138138
:members:
139139
:undoc-members:
140+
:special-members:
141+
:inherited-members:
142+
:exclude-members: __dict__
140143

141144
Copyright
142145
=========
143146

144-
Based on https://github.com/slezica/python-frozendict and https://github.com/mredolatti/python-frozendict .
145-
146-
Copyright (c) 2012 Santiago Lezica
147-
148-
Licensed under the MIT License:
147+
| Based on https://github.com/slezica/python-frozendict and https://github.com/mredolatti/python-frozendict .
148+
| Copyright (c) 2012 Santiago Lezica
149+
| Licensed under the MIT License:
149150
150151
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
151152

152153
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
153154

154155
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
155156

156-
|
157-
158-
Also based on https://github.com/Marco-Sulla/python-frozendict
159-
160-
Copyright (c) Marco Sulla
161-
162-
Licensed under the `GNU Lesser General Public License Version 3 <https://www.gnu.org/licenses/lgpl-3.0.en.html>`_
157+
| Also based on https://github.com/Marco-Sulla/python-frozendict
158+
| Copyright (c) Marco Sulla
159+
| Licensed under the `GNU Lesser General Public License Version 3 <https://www.gnu.org/licenses/lgpl-3.0.en.html>`_

doc-source/classes/frozenordereddict.rst

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,61 @@ FrozenOrderedDict
55
About
66
========
77

8-
:class:`~cawdrey.frozenordereddict.FrozenOrderedDict` is a immutable wrapper around an OrderedDict.
8+
:class:`~cawdrey.FrozenOrderedDict` is a immutable wrapper around an OrderedDict.
99

10-
:class:`~cawdrey.frozenordereddict.FrozenOrderedDict` is similar to ``frozendict``, and with regards to immutability it
10+
:class:`~cawdrey.FrozenOrderedDict` is similar to :class:`~cawdrey.frozendict`, and with regards to immutability it
1111
solves the same problems:
1212

1313
- Because dictionaries are mutable, they are not hashable and cannot be used in sets or as dictionary keys.
1414
- Nasty bugs can and do occur when mutable data structures are passed around.
1515

1616
It can be initialized just like a :class:`~python:dict` or :class:`~python:collections.OrderedDict`.
17-
Once instantiated, an instance of :class:`~cawdrey.frozenordereddict.FrozenOrderedDict` cannot be altered,
18-
since it does not implement the ``MutableMapping`` interface.
17+
Once instantiated, an instance of :class:`~cawdrey.FrozenOrderedDict` cannot be altered,
18+
since it does not implement the :class:`~collections.abc.MutableMapping` interface.
1919

20-
It does implement the ``Mapping`` interface, so can be used just like a
20+
It does implement the :class:`~collections.abc.Mapping` interface, so can be used just like a
2121
normal dictionary in most cases.
2222

23-
In order to modify the contents of a :class:`~cawdrey.frozenordereddict.FrozenOrderedDict`, a new
23+
In order to modify the contents of a :class:`~cawdrey.FrozenOrderedDict`, a new
2424
instance must be created. The easiest way to do that is by
2525
calling the `.copy()` method. It will return a new instance of
26-
:class:`~cawdrey.frozenordereddict.FrozenOrderedDict` initialized using the following steps:
26+
:class:`~cawdrey.FrozenOrderedDict` initialized using the following steps:
2727

28-
1. A copy of the wrapped OrderedDict instance will be created.
29-
2. If any arguments or keyword arguments are passed to the `.copy()` method, they will be used to create another OrderedDict instance, which will then be used to update the copy made in step #1.
28+
1. A copy of the wrapped :class:`~python:collections.OrderedDict` instance will be created.
29+
2. If any arguments or keyword arguments are passed to the `.copy()` method, they will be used to create another :class:`~python:collections.OrderedDict` instance, which will then be used to update the copy made in step #1.
3030
3. Finally, `self.__class__()` will be called, passing the copy as the only argument.
3131

3232
API Reference
3333
===========================
3434

35-
.. autoclass:: cawdrey.frozenordereddict.FrozenOrderedDict
35+
.. autoclass:: cawdrey.FrozenOrderedDict
3636
:members:
3737
:undoc-members:
38+
:special-members:
39+
:inherited-members:
40+
:exclude-members: __dict__
3841

3942

4043
Copyright
4144
=========
4245

43-
Based on https://github.com/slezica/python-frozendict and https://github.com/mredolatti/python-frozendict .
44-
45-
Copyright (c) 2012 Santiago Lezica
46-
47-
Licensed under the MIT License:
46+
| Based on https://github.com/slezica/python-frozendict and https://github.com/mredolatti/python-frozendict .
47+
| Copyright (c) 2012 Santiago Lezica
48+
| Licensed under the MIT License:
4849
4950
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5051

5152
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5253

5354
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5455

55-
|
56-
57-
Also based on
58-
https://github.com/Marco-Sulla/python-frozendict
59-
Copyright (c) Marco Sulla
60-
Licensed under the `GNU Lesser General Public License Version 3 <https://www.gnu.org/licenses/lgpl-3.0.en.html>`_
61-
62-
|
63-
64-
Also based on https://github.com/wsmith323/frozenordereddict
65-
66-
Copyright (c) 2015 Warren Smith
56+
| Also based on https://github.com/Marco-Sulla/python-frozendict
57+
| Copyright (c) Marco Sulla
58+
| Licensed under the `GNU Lesser General Public License Version 3 <https://www.gnu.org/licenses/lgpl-3.0.en.html>`_
6759
68-
Licensed under the MIT License:
60+
| Also based on https://github.com/wsmith323/frozenordereddict
61+
| Copyright (c) 2015 Warren Smith
62+
| Licensed under the MIT License:
6963
7064
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7165

0 commit comments

Comments
 (0)