Read about Python style guide (PEP8)
Your case:
- PEP8: E302 – you have to write 2 blank lines before and after each of classes
- Both function and variable names should be snake-case (
sendEmail
->send_email
)
Also:
- Don’t be afraid of long names: it is a good practice to write
self.notification
instead ofself.notif
- Use type annotations
It is convinient to use dataclasses
Instead of
details = {'email': 'email_address', 'username':'user_name', 'body': 'body_email'}
You can write dataclass:
from dataclasses import dataclass
@dataclass
class EmailDetails:
email_address: str
username: str
body: str
class Notification:
def __init__(self, email_details: EmailDetails):
self.email = email_details.email_address
self.username = email_details.username
self.body = email_details.body
Method’s name should describe it
In the class Notification you have a method called sending_email
, but it does return a list for you, so it have to be named like get_info_to_send_email
. If the main goal of method is to send email, then the method should be named something like send_email
instead of sending_email
.
Avoid magic in the code
The method sending_email
probably should return dataclass EmailDetails
instead of list
, because:
- when you working with that list, you have to strictly specify the indexes,
- when you want to modify that list, you have to hard refactor adjacent parts of the code.
This brings magic to the code. The simpler, the better.