Giter VIP home page Giter VIP logo

roview's Introduction

tests

In [1]: from roview import rolist

In [2]: l = [5, 0, 10]

In [3]: ro_l = rolist(l)

In [4]: ro_l
Out[4]: [5, 0, 10]

In [5]: type(ro_l)
Out[5]: roview.listROView

In [6]: isinstance(ro_l, list)
Out[6]: True

In [7]: ro_l.__class__
Out[7]: roview.listROView

In [8]: ro_l.__dict__
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-010dbe493c26> in <module>
----> 1 ro_l.__dict__

~/workspace/dev/roview/roview.py in __getattr__(self, attr)
    179 
    180         def __getattr__(self, attr):
--> 181             return getattr(obj, attr)
    182 
    183     proxy = type(

AttributeError: 'list' object has no attribute '__dict__'

In [9]: ro_l.append(555)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-98107de6aec9> in <module>
----> 1 ro_l.append(555)

~/workspace/dev/roview/roview.py in attribute_error(cls_or_self, *args, **kwds)
    143             def make_attribute_error(attr: str):
    144                 def attribute_error(cls_or_self, *args, **kwds):
--> 145                     raise AttributeError("Attribute '%s' is not enabled" % attr)
    146 
    147                 attribute_error.__qualname__ = getattr(obj, attr).__qualname__

AttributeError: Attribute 'append' is not enabled

In [10]: ro_l.__original__
Out[10]: [5, 0, 10]

In [11]: l.append(555)

In [12]: ro_l
Out[12]: [5, 0, 10, 555]

In [13]: l = [[]]

In [14]: l_ro = rolist(l, nested=True)

In [15]: l_ro[0].append(1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-128d12d96898> in <module>
----> 1 l_ro[0].append(1)

~/workspace/dev/roview/roview.py in attribute_error(cls_or_self, *args, **kwds)
    143             def make_attribute_error(attr: str):
    144                 def attribute_error(cls_or_self, *args, **kwds):
--> 145                     raise AttributeError("Attribute '%s' is not enabled" % attr)
    146 
    147                 attribute_error.__qualname__ = getattr(obj, attr).__qualname__

AttributeError: Attribute 'append' is not enabled
In [1]: from roview import roview

In [2]: class O:
   ...:     def __init__(self):
   ...:         self.x = 0
   ...:

In [3]: o = O()

In [4]: ro_o = roview(o, enabled_attrs=["__str__", "__getattr__"])

In [5]: ro_o.x
Out[5]: 0

In [6]: ro_o.x = 1
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-8598cf01a30a> in <module>
----> 1 ro_o.x = 1

~/workspace/dev/roview/roview.py in attribute_error(cls_or_self, *args, **kwds)
    143             def make_attribute_error(attr: str):
    144                 def attribute_error(cls_or_self, *args, **kwds):
--> 145                     raise AttributeError("Attribute '%s' is not enabled" % attr)
    146 
    147                 attribute_error.__qualname__ = getattr(obj, attr).__qualname__

AttributeError: Attribute '__setattr__' is not enabled

In [7]: ro_o.__dict__
Out[7]: {'x': 0}

In [8]: ro_o.__dict__["x"] = 1
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-e98ada46ce51> in <module>
----> 1 ro_o.__dict__["x"] = 1

~/workspace/dev/roview/roview.py in attribute_error(cls_or_self, *args, **kwds)
    143             def make_attribute_error(attr: str):
    144                 def attribute_error(cls_or_self, *args, **kwds):
--> 145                     raise AttributeError("Attribute '%s' is not enabled" % attr)
    146 
    147                 attribute_error.__qualname__ = getattr(obj, attr).__qualname__

AttributeError: Attribute '__setitem__' is not enabled

In [8]: o.x = 1

In [9]: ro_o.x
Out[9]: 1

roview's People

Contributors

levsh avatar

Watchers

 avatar

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.