Comments (4)
I'm personally leaning towards doing keyword arguments, as that would allow for other customization and expansions in the future. I am mulling over how best to name them (so they aren't close to anything someone might have in a dictionary).
Either something like box_auto_attr
or _auto_attr
. Potentially add a box_auto_default=Box
field as well so it's possible to make it more like a true default dict that a user can specify what type of object the default fallback is.
Closing #5 as it was less detailed
from box.
Sounds like separation of creating Box variants from using them would be valuable (separate namespaces with no awkward avoidance of overlap). So how about this:
@box.closable
@box.autoattr
class MyClosableAutoBox(Box):
"""Customized ``Box``."""
Chances are you want to use such a beast at several places anyway, and then you'd have to curry the Box construction with those keyword args. 😬
Alas, Python3 only, but you could call the decorators explicitly in Python2.
from box.
It's own namespace would be nice and simple, but for #6 need to have some sort of namespace pollution anyways, so I have been working on a way to make it near invisible. https://github.com/cdgriffith/Box/blob/auto_attr/box.py#L269
my_box = Box({"I call Hax!": "totally"}, default_box=True, conversion_box=True)
my_box.i_call_hax
# Out[8]: 'totally'
my_box.sub_box.another_box.boxes_the_whole_way_down = 'Yet another box'
my_box
# Out[10]: <Box: {'I call Hax!': 'totally', 'sub_box': {'another_box': {'boxes_the_whole_way_down': 'Yet another box'}}}>
Could still make it into it's own subclass if those same options will always be repeated (still mulling over just adding a few of these as well for simplicity):
class DefaultBox(Box):
def __init__(self, *args, **kwargs):
super(Box, self).__init__(*args, **kwargs)
self._box_config['default'] = True
Thoughts?
from box.
added default_box
in 3.0 6d90e42
from box.
Related Issues (20)
- Feature request: add additional values from file HOT 3
- Feature request: only one function for loading files HOT 3
- Support for tracking the box "namespace" HOT 6
- Feature Request: default to an empty dict for missing keys HOT 3
- Version mismatch between setup.py and tag HOT 3
- Two small typos in Wiki / Types of Boxes HOT 3
- Breaking convention with __or__/ __ror__ dunder methods HOT 3
- Using help (`?`) with `default_box=True` unintentionally adds a key HOT 3
- Keys method with (dotted=True) gives multiplication of the same key HOT 1
- `__add__` and `__or__` operators for frozen boxes HOT 3
- Add Cython builds to MacOS using `universal2` HOT 4
- Switch to poetry-core HOT 2
- Missing python-box 7.0.0 arm64 wheels HOT 1
- BoxKeyError when constructing a Box with box_dots = True in v7.0.0 HOT 2
- Appending a list to a list causes recursion HOT 4
- IDE Auto Completion for keys
- merge_update() not merging nested dictionaries or lists HOT 1
- path as string HOT 2
- Two test failures due to arguments having incorrect types HOT 3
- Caching a box resuts in read error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from box.