GithubHelp home page GithubHelp logo

Auto attributes creation about box HOT 4 CLOSED

cdgriffith avatar cdgriffith commented on May 18, 2024
Auto attributes creation

from box.

Comments (4)

cdgriffith avatar cdgriffith commented on May 18, 2024

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.

jhermann avatar jhermann commented on May 18, 2024

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.

cdgriffith avatar cdgriffith commented on May 18, 2024

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.

cdgriffith avatar cdgriffith commented on May 18, 2024

added default_box in 3.0 6d90e42

from box.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.