Code Monkey home page Code Monkey logo

candv's People

Contributors

dsuch avatar o3bvv avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

dsuch pombredanne

candv's Issues

'with_constant_class' mixin factory

Add ability to specify class of constants via dynamic mixin, e.g. this:

class FOO(Constants):
    constant_class = FOO_CONSTANT

    ONE = FOO_CONSTANT()
    TWO = FOO_CONSTANT()

with decorator will look like:

class FOO(with_constant_class(FOO_CONSTANT), Constants):    
    ONE = FOO_CONSTANT()
    TWO = FOO_CONSTANT()

Improve/add reprresentation of objects

Add ability to get:

  • name of container (alias for __name__)
  • full name of container
  • __repr__ of a container
  • __repr__ of a group
  • full name of a constant, which will include name of container

Dynamic values

Provide ability to set dynamic values for constants using some storage (e.g. integrate with Redis, django-constance or whatsoever).

Initialization of non-'constant_class' constants

Constants which are not instances of container's constant_class are not initialized. E.g.

>>> from candv import Values, SimpleConstant
>>> class FOO(Values):
...     BAR = SimpleConstant()
...     
... 
>>> FOO.BAR

>>> FOO.BAR.name
>>> repr(FOO.BAR)
''

Despite FOO.BAR is invalid, it still needs to be initialized.

Constants must be equal no matter how they are loaded

Assume you have the following package structure:

.
└── x
    ├── __init__.py
    └── y
        ├── __init__.py
        └── constants.py

where x.y.constants.py contains the following:

# -*- coding: utf-8 -*-

from candv import Constants, SimpleConstant


class FOO_TYPES(Constants):
    PRIMARY = SimpleConstant()
    SECONDARY = SimpleConstant()

If x is in Python's path, and you import constants from x.y and simply from y, then their module will differ and comparison of constants will fail:

>>> import sys
>>> sys.path.insert(0, './x')
>>> from x.y.constants import FOO_TYPES as X_TYPES
>>> from y.constants import FOO_TYPES as Y_TYPES
>>> X_TYPES.__module__
'x.y.constants'
>>> Y_TYPES.__module__
'y.constants'
>>> X_TYPES.PRIMARY
<constant 'FOO_TYPES.PRIMARY'>
>>> Y_TYPES.PRIMARY
<constant 'FOO_TYPES.PRIMARY'>
>>> X_TYPES.PRIMARY == Y_TYPES.PRIMARY
False

Solution: constants base must implement own __hash__ and __eq__ magic methods, whose result will be based on full name of constant.

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.