Skip to content

Commit

Permalink
Adding extra lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudia Ng authored and Claudia Ng committed Oct 2, 2023
1 parent 0e63bbc commit be759a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Union


def parse_email(email_address: str) -> str | None:
if "@" in email_address:
username, domain = email_address.split("@")
return username
return None


def parse_email(email_address: str) -> Union[str, None]:
if "@" in email_address:
username, domain = email_address.split("@")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Tuple, Union


def parse_email(email_address: str) -> tuple[str, str] | None:
if "@" in email_address:
username, domain = email_address.split("@")
return username, domain
return None


def parse_email(email_address: str) -> Union[Tuple[str, str], None]:
if "@" in email_address:
username, domain = email_address.split("@")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from collections.abc import Callable
from typing import Any


def apply_func(
func: Callable[..., Any], *args: Any
) -> Any:
return func(*args)


def parse_email(email_address: str) -> tuple[str, str] | None:
if "@" in email_address:
username, domain = email_address.split("@")
return username, domain
return None


apply_funct(parse_email, "[email protected]")
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections.abc import Callable
from typing import Any


def timeit(function: Callable[..., Any]) -> Callable[..., Any]:
@functools.wraps(function)
def wrapper(*args, **kwargs):
Expand All @@ -14,12 +15,14 @@ def wrapper(*args, **kwargs):

return wrapper


@timeit
def parse_email(email_address: str) -> tuple[str, str] | None:
if "@" in email_address:
username, domain = email_address.split("@")
return username, domain
return None


username, domain = parse_email("[email protected]")
print(username, domain)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Generator, Iterable, Iterator


def parse_email() -> Generator[tuple[str, str], str, str]:
sent = yield "", ""
while sent != "":
Expand All @@ -10,6 +11,7 @@ def parse_email() -> Generator[tuple[str, str], str, str]:
sent = yield "invalid email"
return "Done"


generator = parse_email()
next(generator)
generator.send("[email protected]")
Expand All @@ -19,12 +21,14 @@ def parse_email() -> Generator[tuple[str, str], str, str]:
except StopIteration as ex:
print(ex.value)


def parse_emails(emails: list[str]) -> Iterator[tuple[str, str]]:
for email in emails:
if "@" in email:
username, domain = email.split("@")
yield username, domain


def parse_emails(emails: Iterable[str]) -> Iterable[tuple[str, str]]:
for email in emails:
if "@" in email:
Expand Down
3 changes: 3 additions & 0 deletions python-type-hints-multiple-types/06_type_aliases.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from typing import TypeAlias


EmailComponents = tuple[str, str] | None


def parse_email(email_address: str) -> EmailComponents:
if "@" in email_address:
username, domain = email_address.split("@")
return username, domain
return None


EmailComponents: TypeAlias = tuple[str, str] | None
type EmailComponents = tuple[str, str] | None

0 comments on commit be759a2

Please sign in to comment.