Skip to content

Commit

Permalink
Actually do overloads correctly
Browse files Browse the repository at this point in the history
Originally I did not realize that it was possible to put the keyword
arguments in an overload, so I ended up doing way more overload
definitions than needed.
  • Loading branch information
SethMMorton committed Oct 31, 2021
1 parent 14f72a4 commit 4cc58e2
Showing 1 changed file with 68 additions and 126 deletions.
194 changes: 68 additions & 126 deletions natsort/natsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,62 +253,16 @@ def natsort_keygen(


@overload
def natsorted(seq: Iter_ns) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, *, reverse: bool) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, *, alg: NSType) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, *, reverse: bool, alg: NSType) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, key: None) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, key: None, reverse: bool) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, key: None, *, alg: NSType) -> List_ns:
...


@overload
def natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NSType) -> List_ns:
...


@overload
def natsorted(seq: Iter_any, key: KeyType) -> List_any:
...


@overload
def natsorted(seq: Iter_any, key: KeyType, reverse: bool) -> List_any:
...


@overload
def natsorted(seq: Iter_any, key: KeyType, *, alg: NSType) -> List_any:
def natsorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_ns:
...


@overload
def natsorted(seq: Iter_any, key: KeyType, reverse: bool, alg: NSType) -> List_any:
def natsorted(
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_any:
...


Expand Down Expand Up @@ -365,6 +319,20 @@ def natsorted(
return sorted(seq, reverse=reverse, key=natsort_keygen(key, alg))


@overload
def humansorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_ns:
...


@overload
def humansorted(
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_any:
...


def humansorted(
seq: Iter_any,
key: MaybeKeyType = None,
Expand Down Expand Up @@ -422,6 +390,20 @@ def humansorted(
return natsorted(seq, key, reverse, alg | ns.LOCALE)


@overload
def realsorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_ns:
...


@overload
def realsorted(
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_any:
...


def realsorted(
seq: Iter_any,
key: MaybeKeyType = None,
Expand Down Expand Up @@ -481,63 +463,15 @@ def realsorted(


@overload
def index_natsorted(seq: Iter_ns) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, *, reverse: bool) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, *, alg: NSType) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, *, reverse: bool, alg: NSType) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, key: None) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, key: None, reverse: bool) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, key: None, *, alg: NSType) -> List_int:
...


@overload
def index_natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NSType) -> List_int:
...


@overload
def index_natsorted(seq: Iter_any, key: KeyType) -> List_int:
...


@overload
def index_natsorted(seq: Iter_any, key: KeyType, reverse: bool) -> List_int:
...


@overload
def index_natsorted(seq: Iter_any, key: KeyType, *, alg: NSType) -> List_int:
def index_natsorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...


@overload
def index_natsorted(
seq: Iter_any, key: KeyType, reverse: bool, alg: NSType
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...

Expand Down Expand Up @@ -617,6 +551,20 @@ def newkey(x: Any) -> NatsortInType:
return [x for x, _ in index_seq_pair]


@overload
def index_humansorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...


@overload
def index_humansorted(
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...


def index_humansorted(
seq: Iter_any,
key: MaybeKeyType = None,
Expand Down Expand Up @@ -671,6 +619,20 @@ def index_humansorted(
return index_natsorted(seq, key, reverse, alg | ns.LOCALE)


@overload
def index_realsorted(
seq: Iter_ns, key: None = None, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...


@overload
def index_realsorted(
seq: Iter_any, key: KeyType, reverse: bool = False, alg: NSType = ns.DEFAULT
) -> List_int:
...


def index_realsorted(
seq: Iter_any,
key: MaybeKeyType = None,
Expand Down Expand Up @@ -897,32 +859,12 @@ def os_sort_keygen(key: MaybeKeyType = None) -> OSSortKeyType:


@overload
def os_sorted(seq: Iter_path) -> List_path:
...


@overload
def os_sorted(seq: Iter_path, *, reverse: bool) -> List_path:
...


@overload
def os_sorted(seq: Iter_path, key: None) -> List_path:
...


@overload
def os_sorted(seq: Iter_path, key: None, reverse: bool) -> List_path:
...


@overload
def os_sorted(seq: Iter_any, key: KeyType) -> List_any:
def os_sorted(seq: Iter_path, key: None = None, reverse: bool = False) -> List_path:
...


@overload
def os_sorted(seq: Iter_any, key: KeyType, reverse: bool) -> List_any:
def os_sorted(seq: Iter_any, key: KeyType, reverse: bool = False) -> List_any:
...


Expand Down

0 comments on commit 4cc58e2

Please sign in to comment.