Skip to content

Commit

Permalink
Update examples.md (#1163)
Browse files Browse the repository at this point in the history
* Update examples.md

Changing order type annotations to fit code
Added attrs.define implementation to slots category

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update docs/examples.md

Co-authored-by: Hynek Schlawack <[email protected]>

* Update docs/examples.md

Co-authored-by: Hynek Schlawack <[email protected]>

* revert test_annotations.py

* Revert test_annotations.py

removed space

---------

Co-authored-by: Hynek Schlawack <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 17, 2023
1 parent d538cba commit 940dd1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ If you're the author of a third-party library with *attrs* integration, please s

## Types

*attrs* also allows you to associate a type with an attribute using either the *type* argument to {func}`attr.ib` and {func}`attr.field` or using {pep}`526`-annotations:
*attrs* also allows you to associate a type with an attribute using either the *type* argument to using {pep}`526`-annotations or {func}`attrs.field`/{func}`attr.ib`:

```{doctest}
>>> @define
Expand Down Expand Up @@ -588,6 +588,11 @@ However it's useful for writing your own validators or serialization frameworks.
Defining `__slots__` by hand is tedious, in *attrs* it's just a matter of using {func}`attrs.define` or passing `slots=True` to {func}`attr.s`:

```{doctest}
>>> @define
... class Coordinates:
... x: int
... y: int
>>> import attr
>>> @attr.s(slots=True)
Expand Down Expand Up @@ -662,7 +667,7 @@ True
<class 'int'>
```

You can still have power over the attributes if you pass a dictionary of name: {func}`~attrs.field` mappings and can pass arguments to `@attr.s`:
You can still have power over the attributes if you pass a dictionary of name: {func}`~attrs.field` mappings and can pass the same arguments as you can to `@attrs.define`:

```{doctest}
>>> C = make_class("C", {"x": field(default=42),
Expand Down

0 comments on commit 940dd1f

Please sign in to comment.