You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caught in between the difficulties of both cleanly and simply supporting a common interface between a simple decentant of object and a more useful custom class (simple bunch vs. PysonBunch). Abandoning this effort for now, until a situation arises where it is actually definitley useful to have a "SimpleBunch".
Copy file name to clipboardExpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ The optional `delname` argument can be used to remove unwanted name polution (su
79
79
80
80
`PysonBunch` objects behave very much like dicts and support most of their built-in operations (such as indexing and `in` tests), but the names stored in them are, of course, also accessible via `getattr()` and the `.` operator.
81
81
82
-
`PysonBunch` objects support conversion back to valid PySON strings, via `__repr__`. Calling `repr` on a `PysonBunch` will only produce a representation of the values contained **within** the bunch, since the bunch does not know its own name. To get a full representation of the named bunch, you can use the helper method `namedPysonBunchRepr(name, bunch)`.
82
+
`PysonBunch` objects support conversion back to valid PySON strings, via `__repr__`. Calling `repr` on a `PysonBunch` will only produce a representation of the values contained **within** the bunch, since the bunch does not know its own name. To get a full representation of the named bunch, you can use the helper method `namedBunchRepr(name, bunch)`.
Copy file name to clipboardExpand all lines: __init__.py
+1-1
Original file line number
Diff line number
Diff line change
@@ -19,5 +19,5 @@
19
19
20
20
# The present purpose of this file is simply to allow using PySON as a file or a package interchangeably. TODO: Only export things that should be part of the interface.
21
21
22
-
from .pysonimportnamedPysonBunchRepr, PysonBunch, parseDir, parseFile, parse
22
+
from .pysonimportnamedBunchRepr, PysonBunch, parseDir, parseFile, parse
23
23
from .importerimportregisterPysonImportRoot, convertToPysonRootPackage
"""Returns a valid PySON representation of this PysonBunch object.
38
-
39
-
Since an object usually doesn't know the name it is stored under, a bunch settles for just returning a valid PySON representation of the set of its constituents. For creating a repr of a named PySON bunch use pyson.namedPysonBunchRepr(name, bunch)."""
ifisinstance(allDefinitions[-1], self.__class__): # if the final (dominating) definition is a bunch, we want to merge it with any relevant preceding bunch definitions (i.e. ones which would not have been overriden by a non-bunch object)
"""Returns a valid PySON representation of the given bunch object.
34
+
35
+
Since an object usually doesn't know the name it is stored under, a bunch settles for just returning a valid PySON representation of the set of its constituents. For creating a repr of any kind of named PySON bunch use namedBunchRepr(name, bunch)."""
"""return a deep copy of the first given bunch, which has been updated (overwriting any existing contents) with deep copies of any further given bunches. Returned bunch type is determined by the first argument."""
ifisinstance(allDefinitions[-1], BaseBunch): # if the final (dominating) definition is a bunch, we want to merge it with any relevant preceding bunch definitions (i.e. ones which would not have been overriden by a non-bunch object)
classBaseBunch(object): pass#FIXME: Base type is misleading. They won't support the same interface (at least for now: no way to "list" the keys in a SimplePysonBunch).
73
+
classSimplePysonBunch(BaseBunch):
74
+
"""Use this if you *really* want to avoid name collisions between entries in the raw PySON code and names belonging to the bunch object.
75
+
76
+
WARNINGS:
77
+
* still vulnerable to collisions with anything that is part of a basic python object
78
+
* does not support any convenience, such as using repr(SimplePysonBunch) to get a PySON string representation of the object
79
+
80
+
Where possible, it is recommended to use PysonBunch and simply avoid the use of the following names in PySON definitions:
81
+
* anything that is a part of basic python objects
82
+
* anything that is a part of python dict objects
83
+
* anything that is listed in PysonBunchConvenienceMethods above"""
# try: return supergetattr(name) #in any other case, fall back to default getattr behaviour
116
+
# except AttributeError as e:
117
+
## if hasattr(selfdict, name): return getattr(selfdict, name) #if we are trying to use a feature supported by dictionaries, we support this by calling the method on the underlying __dict__, which PySON exclusively uses to store any bunch's members
0 commit comments