Skip to content

Commit

Permalink
refactor: move code from types to typing_utils
Browse files Browse the repository at this point in the history
in an effort to reduce number of modules
  • Loading branch information
jnoortheen committed Nov 3, 2020
1 parent d710dd4 commit b9c779c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion arger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import typing as tp

from .structs import Command
from .types import F
from .typing_utils import F

CMD_TITLE = "commands"
LEVEL = '__level__'
Expand Down
3 changes: 2 additions & 1 deletion arger/parser/actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
from typing import Any, Tuple, Union

from ..types import UNDEFINED, VarArg, VarKw
from ..types import VarArg, VarKw
from ..typing_utils import (
UNDEFINED,
cast,
get_inner_args,
get_origin,
Expand Down
2 changes: 1 addition & 1 deletion arger/parser/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from arger.parser.utils import FlagsGenerator

from ..types import UNDEFINED
from ..typing_utils import UNDEFINED
from .actions import TypeAction


Expand Down
3 changes: 2 additions & 1 deletion arger/parser/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from arger.parser.docstring import parse_docstring

from ..types import UNDEFINED, F, T, VarArg, VarKw
from ..types import VarArg, VarKw
from ..typing_utils import UNDEFINED, F, T
from .classes import Argument, Option
from .utils import FlagsGenerator

Expand Down
3 changes: 2 additions & 1 deletion arger/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from .parser import parse_function
from .parser.funcs import ParsedFunc
from .types import F, VarArg
from .types import VarArg
from .typing_utils import F


class Command:
Expand Down
15 changes: 1 addition & 14 deletions arger/types.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
from typing import Any, Callable, TypeVar

F = TypeVar("F", bound=Callable[..., Any]) # decorator
T = TypeVar('T')


class _Undefined:
"""sometimes the value could be None. we need this to distinguish such values."""

def __repr__(self):
return 'UNDEFINED'


UNDEFINED = _Undefined() # singleton
from typing import Any


class VarArg:
Expand Down
16 changes: 15 additions & 1 deletion arger/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from enum import Enum
from inspect import isclass
from typing import Any, FrozenSet, List, Set, Tuple
from typing import Any, Callable, FrozenSet, List, Set, Tuple, TypeVar

NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560

Expand Down Expand Up @@ -107,3 +107,17 @@ def cast(tp, val) -> Any:
return origin([cast(unpack_type(tp), v) for v in val])

return origin(val)


F = TypeVar("F", bound=Callable[..., Any]) # decorator
T = TypeVar('T')


class _Undefined:
"""sometimes the value could be None. we need this to distinguish such values."""

def __repr__(self):
return 'UNDEFINED'


UNDEFINED = _Undefined() # singleton
2 changes: 1 addition & 1 deletion tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from arger.parser.classes import Option
from arger.parser.funcs import Param, create_option
from arger.parser.utils import FlagsGenerator
from arger.types import UNDEFINED
from arger.typing_utils import UNDEFINED


@pytest.fixture
Expand Down

0 comments on commit b9c779c

Please sign in to comment.