Skip to content

Commit

Permalink
Merge pull request #138 from pbs-data-solutions/form-info-type
Browse files Browse the repository at this point in the history
Add custom types for form info
  • Loading branch information
sanders41 authored Oct 12, 2023
2 parents f60e7f7 + 6439c22 commit 020043b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions prelude_parser/_prelude_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations

from pathlib import Path
from typing import Any

from prelude_parser.types import FlatFormInfo

def _parse_flat_file_to_dict(
xml_file: str | Path, short_names: bool
) -> dict[str, list[dict[str, Any]]]: ...
) -> dict[str, FlatFormInfo]: ...
def _parse_flat_file_to_pandas_dict(
xml_file: str | Path, short_names: bool
) -> dict[str, list[Any]]: ...
) -> dict[str, FlatFormInfo]: ...

class FileNotFoundError(Exception):
pass
Expand Down
7 changes: 3 additions & 4 deletions prelude_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
from camel_converter import to_pascal

from prelude_parser._prelude_parser import _parse_flat_file_to_dict
from prelude_parser.types import FieldInfo, FlatFormInfo


class _MetaCls(type):
def __new__(
cls, clsname: str, superclasses: tuple[type, ...], attributedict: dict[str, Any]
cls, clsname: str, superclasses: tuple[type, ...], attributedict: dict[str, FieldInfo]
) -> _MetaCls:
return super().__new__(cls, clsname, superclasses, attributedict)


def parse_to_dict(
xml_file: str | Path, *, short_names: bool = False
) -> dict[str, list[dict[str, Any]]]:
def parse_to_dict(xml_file: str | Path, *, short_names: bool = False) -> dict[str, FlatFormInfo]:
"""Parse a Prelude flat XML file into a dict.
Args:
Expand Down
5 changes: 5 additions & 0 deletions prelude_parser/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from datetime import date, datetime
from typing import Dict, List, Union

FieldInfo = Union[str, int, float, date, datetime]
FlatFormInfo = List[Dict[str, FieldInfo]]

0 comments on commit 020043b

Please sign in to comment.