Skip to content

Commit

Permalink
[cdd/shared/parse/__init__.py] Expand kind2_instance_type ; [cdd/sq…
Browse files Browse the repository at this point in the history
…lalchemy/utils/parser_utils.py] Implement `column_parse_extra_sql`
  • Loading branch information
SamuelMarks committed Feb 7, 2023
1 parent 96cd992 commit 62fcd20
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from logging import getLogger as get_logger

__author__ = "Samuel Marks"
__version__ = "0.0.99-beta"
__version__ = "0.0.99-rc0"
__description__ = (
"Open API to/fro routes, models, and tests. "
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."
Expand Down
9 changes: 6 additions & 3 deletions cdd/shared/parse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
]

kind2instance_type = {
"sqlalchemy_table": (Assign, AnnAssign),
"argparse": (FunctionDef,),
"function": (FunctionDef, AsyncFunctionDef),
"pydantic": (FunctionDef, AsyncFunctionDef),
"argparse_function": (FunctionDef,),
"class": (ClassDef,),
"class_": (ClassDef,),
"function": (FunctionDef, AsyncFunctionDef),
"method": (FunctionDef, AsyncFunctionDef),
"pydantic": (ClassDef,),
"sqlalchemy_table": (Assign, AnnAssign),
"sqlalchemy": (ClassDef,),
}

__all__ = ["PARSERS", "kind2instance_type"]
16 changes: 16 additions & 0 deletions cdd/sqlalchemy/utils/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
)


def column_parse_extra_sql(idx_arg):
"""
Parse Column arg into extra sql type information
:param idx_arg: argument number, node
:type idx_arg: ```Tuple[int, AST]```
:rtype: ```Optional[Tuple[str, dict]]```
"""
idx, arg = idx_arg
if idx < 2 and isinstance(arg, Name) and arg.id in column_type2typ:
return "x_typ", {"sql": {"type": arg.id}}
return None


def column_parse_arg(idx_arg):
"""
Parse Column arg
Expand Down Expand Up @@ -165,6 +180,7 @@ def column_call_to_param(call):
chain.from_iterable(
(
map(column_parse_arg, enumerate(call.args)),
map(column_parse_extra_sql, enumerate(call.args)),
map(column_parse_kwarg, call.keywords),
)
),
Expand Down

0 comments on commit 62fcd20

Please sign in to comment.