Skip to content

Commit

Permalink
Gut docs for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jan 27, 2015
1 parent 9560908 commit c7381fd
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 191 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Hynek Schlawack
Copyright (c) 2015 Hynek Schlawack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ attrs: Python attributes without boilerplate.
:target: https://coveralls.io/r/hynek/attrs?branch=master
:alt: Current coverage

.. begin
.. teaser-begin
``attrs`` is an `MIT <http://choosealicense.com/licenses/mit/>`_-licensed Python package with class decorators that ease the chores of implementing the most common attribute-related object protocols:

Expand Down Expand Up @@ -49,5 +49,7 @@ This gives you the power to use actual classes with actual types in your code in

So put down that type-less data structures and welcome some class into your life!

.. teaser-end
``attrs``\ ’s documentation lives at `Read the Docs <https://attrs.readthedocs.org/>`_, the code on `GitHub <https://github.com/hynek/attrs>`_.
It’s rigorously tested on Python 2.6, 2.7, 3.3+, and PyPy.
8 changes: 4 additions & 4 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ qthelp:
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/characteristic.qhcp"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/attrs.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/characteristic.qhc"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/attrs.qhc"

devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/characteristic"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/characteristic"
@echo "# mkdir -p $$HOME/.local/share/devhelp/attrs"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/attrs"
@echo "# devhelp"

epub:
Expand Down
97 changes: 0 additions & 97 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,3 @@

API
===

``characteristic`` consists of class decorators that add attribute-related features to your classes.

.. currentmodule:: characteristic

There are two approaches on how to define those attributes:

#. By defining those attributes as class variables using instances of the :class:`Attribute` class.
This approach has been added as of version 14.0 to make ``characteristic`` future-proof by adding more flexibility.
#. Using a list of names which I henceforth refer to as the 'legacy way'.
As per our backward compatibility policy, support for this approach will *not* be removed before 15.0 (if ever), however no new features will be added so I strongly urge you to *not* use it.

Both approaches usually entail the usage of the :func:`@attributes <attributes>` decorator which will automatically detect the desired approach and prevent mixing of them.

.. autofunction:: attributes

.. autoclass:: Attribute


Legacy
------

There are three that start with ``@with_`` that add *one* feature to your class based on a list of attributes.
Then there's the helper :func:`@attributes <attributes>` that combines them all into one decorator so you don't have to repeat the attribute list multiple times.


.. autofunction:: with_repr

.. doctest::

>>> from characteristic import with_repr
>>> @with_repr(["a", "b"])
... class RClass(object):
... def __init__(self, a, b):
... self.a = a
... self.b = b
>>> c = RClass(42, "abc")
>>> print c
<RClass(a=42, b='abc')>


.. autofunction:: with_cmp

.. doctest::

>>> from characteristic import with_cmp
>>> @with_cmp(["a", "b"])
... class CClass(object):
... def __init__(self, a, b):
... self.a = a
... self.b = b
>>> o1 = CClass(1, "abc")
>>> o2 = CClass(1, "abc")
>>> o1 == o2 # o1.a == o2.a and o1.b == o2.b
True
>>> o1.c = 23
>>> o2.c = 42
>>> o1 == o2 # attributes that are not passed to with_cmp are ignored
True
>>> o3 = CClass(2, "abc")
>>> o1 < o3 # because 1 < 2
True
>>> o4 = CClass(1, "bca")
>>> o1 < o4 # o1.a == o4.a, but o1.b < o4.b
True


.. autofunction:: with_init

.. doctest::

>>> from characteristic import with_init
>>> @with_init(["a", "b"], defaults={"b": 2})
... class IClass(object):
... def __init__(self):
... if self.b != 2:
... raise ValueError("'b' must be 2!")
>>> o1 = IClass(a=1, b=2)
>>> o2 = IClass(a=1)
>>> o1.a == o2.a
True
>>> o1.b == o2.b
True
>>> IClass()
Traceback (most recent call last):
...
ValueError: Missing keyword value for 'a'.
>>> IClass(a=1, b=3) # the custom __init__ is called after the attributes are initialized
Traceback (most recent call last):
...
ValueError: 'b' must be 2!

.. note::

The generated initializer explicitly does *not* support positional
arguments. Those are *always* passed to the existing ``__init__``
unaltered.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,4 @@ def find_version(*file_paths):


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {'https://docs.python.org/2': None}
36 changes: 0 additions & 36 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,3 @@

Examples
========


:func:`@attributes <characteristic.attributes>` together with the definition of the attributes using class attributes enhances your class by:

- a nice ``__repr__``,
- comparison methods that compare instances as if they were tuples of their attributes,
- and – optionally but by default – an initializer that uses the keyword arguments to initialize the specified attributes before running the class’ own initializer (you just write the validator!).


.. doctest::

>>> from characteristic import Attribute, attributes
>>> @attributes
... class C(object):
... a = Attribute()
... b = Attribute()
>>> obj1 = C(a=1, b="abc")
>>> obj1
<C(a=1, b='abc')>
>>> obj2 = C(a=2, b="abc")
>>> obj1 == obj2
False
>>> obj1 < obj2
True
>>> obj3 = C(a=1, b="bca")
>>> obj3 > obj1
True
>>> @attributes
... class CWithDefaults(object):
... a = Attribute()
... b = Attribute()
... c = Attribute(default=3)
>>> obj4 = CWithDefaults(a=1, b=2)
>>> obj5 = CWithDefaults(a=1, b=2, c=3)
>>> obj4 == obj5
True
32 changes: 4 additions & 28 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
characteristic: Say 'yes' to types but 'no' to typing!
======================================================
attrs: Say 'yes' to types but 'no' to typing!
=============================================

Release v\ |release| (:doc:`What's new? <changelog>`).


.. include:: ../README.rst
:start-after: begin


Teaser
------

.. doctest::

>>> from characteristic import Attribute, attributes
>>> @attributes
... class AClass(object):
... a = Attribute()
... b = Attribute()
>>> @attributes
... class AnotherClass(object):
... a = Attribute()
... b = Attribute(default="abc")
>>> obj1 = AClass(a=1, b="abc")
>>> obj2 = AnotherClass(a=1, b="abc")
>>> obj3 = AnotherClass(a=1)
>>> print obj1, obj2, obj3
<AClass(a=1, b='abc')> <AnotherClass(a=1, b='abc')> <AnotherClass(a=1, b='abc')>
>>> obj1 == obj2
False
>>> obj2 == obj3
True
:start-after: teaser-begin
:end-before: teaser-end


User's Guide
Expand Down
4 changes: 2 additions & 2 deletions docs/license.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
License and Hall of Fame
========================

``characteristic`` is licensed under the permissive `MIT <http://choosealicense.com/licenses/mit/>`_ license.
The full license text can be also found in the `source code repository <https://github.com/hynek/characteristic/blob/master/LICENSE>`_.
``attrs`` is licensed under the permissive `MIT <http://choosealicense.com/licenses/mit/>`_ license.
The full license text can be also found in the `source code repository <https://github.com/hynek/attrs/blob/master/LICENSE>`_.

.. _authors:

Expand Down
Loading

0 comments on commit c7381fd

Please sign in to comment.