Coverage for bow.py: 98%
42 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-08 21:58 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-08 21:58 +0200
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4All you need to shoot yourself an arrow in the knee : preconfigured class
5that seems harmless and seems to be powerfull.
7Short bows = one operator
8long bows = one quiver
9Cross bow = algebrae + other quiver
10Japanese bows : algebrae
11European bows (common names) : proposed standard behaviour
12I think I am already short of ideas
14"""
15__all__ = [ 'Hankyu', 'Daikyu', "vdict","sdict", 'mdict' ]
17from .trait import (
18 InclusiveAdder, InclusiveSubber, ExclusiveMuler,
19 Iterator, Searchable
20 )
21from .quiver import LinearAlgebrae, VectorDict
22from .barrack import bowyer
23try:
24 from collections import MutableMapping
25except ImportError:
26 from collections.abc import MutableMapping
28from warnings import warn
32class _Hankyu(InclusiveAdder,dict):
33 pass
36class Hankyu(InclusiveAdder):
37 """Use this at your own risk.
38 Hankyu is the same class with the mnemonic for d(efault)dict with addition
40 >>> from archery.bow import Hankyu
41 >>> tata = Hankyu( dict(a = 1, b = 0, c = -1 ) )
42 >>>
43 >>> toto = Hankyu( dict(a = 1 ) )
44 >>> print toto+tata
45 {'a': 2, 'c': -1, 'b': 0}
46 >>> toto-=( tata+tata )
47 >>> print toto
48 {'a': -1, 'c': 2, 'b': 0}
49"""
50 mapping = dict
51from copy import deepcopy
52class Hankyu(_Hankyu, dict):
53 """Fix the broken copier
54 metaclass are hard"""
55 def copy(self):
56 return deepcopy(
57 bowyer(
58 Hankyu,
59 self
60 )
61 )
64class _Daikyu(LinearAlgebrae):
65 """japanese longbow"""
66 """Fix the broken copier
67 metaclass are hard"""
68 def copy(self):
69 return deepcopy(
70 bowyer(
71 Daikyu,
72 self
73 )
74 )
76class Daikyu(_Daikyu, dict):
77 """Fix the broken copier
78 metaclass are hard"""
79 pass
82mdict = Daikyu
85class _vdict(VectorDict,dict): pass
87class vdict(_vdict):
88 def __init__(self, *a, **kw):
89 super(_vdict, self).__init__(*a, **kw)
90 for k, v in self.items():
91 if isinstance(v, MutableMapping):
92 self[k] = bowyer(globals()[type(self).__name__], v)
94class _sdict(Searchable, LinearAlgebrae, dict):
95 """japanese longbow"""
96 mapping = dict
98class sdict(_sdict):
99 pass
102### for compatibility puprose
103class edict(_sdict):
105 def __init__(self, *a, **kw):
106 warn("ExpDict/edict will become sdict", DeprecationWarning)
107 super(_sdict, self).__init__(*a, **kw)
108 for k, v in self.items():
109 if isinstance(v, MutableMapping):
110 self[k] = bowyer(globals()[type(self).__name__], v)