-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorator_rules.py
32 lines (27 loc) · 1.26 KB
/
decorator_rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
----------------------------------------------------------------------------------
[2.17 Decorator Rules](https://docs.sourcery.ai/Reference/Custom-Rules/gpsg/#217-decorator-rules)
----------------------------------------------------------------------------------
This example file contains pieces of code that either comply with or violate the
rule `do-not-use-staticmethod`.
"""
class EventRecommender:
"""Recommend events to users."""
# violation of `do-not-use-staticmethod`
@staticmethod
def get_suggested_event_from_default_recommender() -> str:
"""What about watching Monty Python?"""
return (
EventRecommender.default_instance()
.all_events.sortby(lambda event: event.score)
.first()
)
# no violation: no decorators :)
def get_suggested_event_from_current_recommender(self) -> str:
"""What about watching Monty Python... again?"""
return self.all_events.sortby(lambda event: event.score).first()
# no violation: other decorators are OK
@send_email_as_well
def get_suggested_event_from_current_recommender_and_send_email(self) -> str:
"""What about watching Monty Python... again?"""
return self.all_events.sortby(lambda event: event.score).first()