Skip to content

Commit

Permalink
Improve the docs somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
emreozcan committed Nov 10, 2024
1 parent 0b43da0 commit 6d796c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
autodoc2_module_all_regexes = [
# r'tdk\..*',
]
autodoc2_hidden_objects = {"inherited", "undoc"}
autodoc2_hidden_objects = {"inherited", "private"}
autodoc2_replace_annotations = [
("tdk.etc.tools.T", "T"),
("tdk.etc.tools._T", "T"),
]

# -- Options for intersphinx
Expand Down
18 changes: 10 additions & 8 deletions src/tdk/etc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def lowercase(
return word_io.read()


def dictionary_order(word: str, /, *, alphabet=ALPHABET) -> tuple[int]:
def dictionary_order(word: str, /, *, alphabet: str = ALPHABET) -> tuple[int]:
"""Returns a tuple of indices that can be used as orthographic order.
```python
Expand All @@ -200,7 +200,7 @@ def dictionary_order(word: str, /, *, alphabet=ALPHABET) -> tuple[int]:
return tuple(alphabet.index(letter) for letter in lowercase(word))


def counter(word: str, *, targets=VOWELS) -> int:
def counter(word: str, *, targets: str = VOWELS) -> int:
"""Find total number of occurrences of each element in targets.
```pycon
>>> counter(word="aaaaaBBBc", targets="c")
Expand All @@ -222,7 +222,7 @@ def counter(word: str, *, targets=VOWELS) -> int:
return sum(word.count(x) for x in targets)


def streaks(word: str, *, targets=CONSONANTS) -> list[int]:
def streaks(word: str, *, targets: str = CONSONANTS) -> list[int]:
"""
Accumulate the number of characters in word which are also in targets.
When a character in word isn't in targets,
Expand Down Expand Up @@ -254,16 +254,18 @@ def streaks(word: str, *, targets=CONSONANTS) -> list[int]:
return streaks_found


def max_streak(word: str, *, targets=CONSONANTS) -> int:
def max_streak(word: str, *, targets: str = CONSONANTS) -> int:
"""Find the maximum consecutive targets in word."""
return max(streaks(word=word, targets=targets))


T = TypeVar("T")
_T = TypeVar("_T")


def distinct(seq: Sequence[T]) -> list[T]:
"""Returns the sequence with each element appearing once with FIFO order."""
seen: set[T] = set()
def distinct(seq: Sequence[_T]) -> Sequence[_T]:
"""
Get a copy of the sequence with each element appearing once in input order.
"""
seen: set[_T] = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
3 changes: 2 additions & 1 deletion src/tdk/gts.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def get_index_sync(): ...
async def get_circumflex_index(
*, http_session: ClientSession
) -> dict[str, str]:
"""
"""Get the circumflex index.
:returns: A dictionary where the keys are entries without circumflex,
and the values are the entries with.
"""
Expand Down
15 changes: 8 additions & 7 deletions src/tdk/internal/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import aiohttp

http_headers = {
http_headers: dict[str, str] = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Referer": "https://sozluk.gov.tr/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
Expand All @@ -16,24 +16,25 @@
"Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
"""Default headers for HTTP requests."""


def session_maker(**kwargs) -> aiohttp.ClientSession:
"""Create a <inv:#ClientSession> with some default headers.
"""Create a <inv:#aiohttp.ClientSession> with some default headers.
This is preferred over creating a base <inv:#ClientSession> because the TDK
servers block requests that do not have headers.
This is preferred over creating a base <inv:#aiohttp.ClientSession> because
the TDK servers block requests that do not have headers.
"""
kwargs["headers"] = {**http_headers, **kwargs.get("headers", {})}
return aiohttp.ClientSession(**kwargs)


def with_http_session(func):
"""Make <inv:#ClientSession> optional for a function that requires it.
"""Make <inv:#aiohttp.ClientSession> optional for functions that require it.
Creates a decorator
that provides a default <inv:#ClientSession>
created by <inv:#session_maker>
that provides a default <inv:#aiohttp.ClientSession>
created by <project:#session_maker>
to the wrapped function.
"""
@wraps(func)
Expand Down

0 comments on commit 6d796c7

Please sign in to comment.