Skip to content

Instantly share code, notes, and snippets.

@konradhalas
Created August 29, 2018 14:36
Show Gist options
  • Save konradhalas/03b7f0863e29fa1028cf8160a1dff77c to your computer and use it in GitHub Desktop.
Save konradhalas/03b7f0863e29fa1028cf8160a1dff77c to your computer and use it in GitHub Desktop.
# ugly
def register_user(user_data):
...
save_user_in_db(
email=user_data['email'],
first_name=user_data['first_name'],
...
)
# beautiful
from dataclasses import dataclass
@dataclass
class UserRegistrationData:
email: str
first_name: str
...
def register_user(user_data: UserRegistrationData) -> None:
...
save_user_in_db(
email=user_data.email,
first_name=user_data.first_name,
...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment