Skip to content

Commit 1482fa5

Browse files
authored
Made all lines less than 80 characters in length
1 parent c856491 commit 1482fa5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

docs/cheatsheet/decorators.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
---
22
title: Python Decorators - Python Cheatsheet
3-
description: A Python Decorator is a syntax that provide a concise and reusable way for extending a function or a class.
3+
description: A Python Decorator is a syntax that provide a concise
4+
and reusable way for extending a function or a class.
45
---
56

67
<base-title :title="frontmatter.title" :description="frontmatter.description">
78
Python Decorators
89
</base-title>
910

10-
A Python Decorator provides a concise and reusable way for extending a function or a class.
11+
A Python Decorator provides a concise and reusable way for extending
12+
a function or a class.
1113

1214
## Bare bone decorator
1315

14-
A decorator in its simplest form is a function that takes another function as an argument and returns a wrapper. The following example shows the creation of a decorator and its usage.
16+
A decorator in its simplest form is a function that takes another
17+
function as an argument and returns a wrapper. The following example
18+
shows the creation of a decorator and its usage.
1519

1620
```python
1721
def your_decorator(func):
@@ -58,7 +62,8 @@ foo("Jack")
5862

5963
## Template for a basic decorator
6064

61-
This template is useful for most decorator use-cases. It is valid for functions with or without parameters, and with or without a return value.
65+
This template is useful for most decorator use-cases. It is valid for functions
66+
with or without parameters, and with or without a return value.
6267

6368
```python
6469
import functools
@@ -102,7 +107,11 @@ def foo(bar):
102107

103108
## Class based decorators
104109

105-
To decorate a class methos, you must define the decorator within the class. When only the implicit argument `self` is passed to the method, without any other additional arguments, you must make a separate decorator for only those methods without any additional arguments. An example of this is when you want to catch and print exceptions in a certain way.
110+
To decorate a class methos, you must define the decorator within the class. When
111+
only the implicit argument `self` is passed to the method, without any other
112+
additional arguments, you must make a separate decorator for only those methods
113+
without any additional arguments. An example of this is when you want to catch
114+
and print exceptions in a certain way.
106115

107116
```python
108117
class DecorateMyMethod:
@@ -135,7 +144,9 @@ test_fail.class_action()
135144
# Exception: Epic fail of your own creation.
136145
```
137146

138-
A decorator can also be defined as a class instead of a method. This is useful for maintaining and updating a state, such as in the following example, where we count the number of calls made to a method:
147+
A decorator can also be defined as a class instead of a method. This is useful
148+
for maintaining and updating a state, such as in the following example, where we
149+
count the number of calls made to a method:
139150

140151
```python
141152
class CountCallNumber:

0 commit comments

Comments
 (0)