Skip to content

Commit

Permalink
[p] Cover azul.strings with mypy (#6821)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Jan 27, 2025
1 parent bab8000 commit 8d0e525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ modules =
azul.bigquery,
azul.bigquery_reservation,
azul.csp,
azul.deployment
azul.deployment,
azul.strings
packages =
azul.openapi

Expand Down
11 changes: 11 additions & 0 deletions src/azul/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Iterable,
Sequence,
TypeVar,
overload,
)

from more_itertools import (
Expand All @@ -18,6 +19,14 @@ def to_camel_case(text: str) -> str:
return camel_cased[0].lower() + camel_cased[1:]


@overload
def departition(before: str, sep: str, after: str | None) -> str: ...


@overload
def departition(before: str | None, sep: str, after: str) -> str: ...


def departition(before: str | None, sep: str, after: str | None) -> str:
"""
>>> departition(None, '.', 'after')
Expand All @@ -30,6 +39,7 @@ def departition(before: str | None, sep: str, after: str | None) -> str:
'before.after'
"""
if before is None:
assert after is not None
return after
elif after is None:
return before
Expand Down Expand Up @@ -222,6 +232,7 @@ def longest_common_prefix(strings: Iterable[str]) -> str | None:
s1, s2 = minmax(strings, default=(None, None))
if s1 is None:
return None
assert s2 is not None
for i, c in enumerate(s1):
if s2[i] != c:
return s1[:i]
Expand Down

0 comments on commit 8d0e525

Please sign in to comment.