Skip to content

Commit bcf37cc

Browse files
committed
Refactoring
1 parent 7cc978c commit bcf37cc

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

Diff for: Decorators__examples/combine_decorators__with_args.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ def wrapped(*args, **kwargs):
4747
return wrapped
4848

4949

50+
def custom_tag(
51+
name: str,
52+
**arguments,
53+
):
54+
def actual_decorator(func):
55+
@functools.wraps(func)
56+
def wrapped(*args, **kwargs):
57+
attrs = get_attrs_str(arguments)
58+
return f"<{name}{attrs}>{func(*args, **kwargs)}</{name}>"
59+
60+
return wrapped
61+
62+
return actual_decorator
63+
64+
5065
def composed(*decs):
5166
def deco(f):
5267
for dec in reversed(decs):
@@ -69,21 +84,6 @@ def multi(func):
6984
)(func)
7085

7186

72-
def custom_tag(
73-
name: str,
74-
**arguments,
75-
):
76-
def actual_decorator(func):
77-
@functools.wraps(func)
78-
def wrapped(*args, **kwargs):
79-
attrs = get_attrs_str(arguments)
80-
return f"<{name}{attrs}>{func(*args, **kwargs)}</{name}>"
81-
82-
return wrapped
83-
84-
return actual_decorator
85-
86-
8787
@custom_tag(
8888
name="a",
8989
href="https://example.com",
@@ -101,8 +101,9 @@ def hello_2(text):
101101
return text
102102

103103

104-
print(hello("Hello World!"))
105-
# <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
104+
if __name__ == '__main__':
105+
print(hello("Hello World!"))
106+
# <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
106107

107-
print(hello_2("Hello World!"))
108-
# <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
108+
print(hello_2("Hello World!"))
109+
# <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>

0 commit comments

Comments
 (0)