Generate style compliant code

This commit is contained in:
Marko Durkovic 2021-10-21 18:45:04 +02:00 committed by Florian Friesdorf
parent 4f658378eb
commit b14085019c
3 changed files with 2270 additions and 1955 deletions

View File

@ -37,6 +37,7 @@ def main() -> None: # pragma: no cover
if '/msg/' not in str(name):
name = name.parent / 'msg' / name.name
typs.update(get_types_from_msg(path.read_text(encoding='utf-8'), str(name)))
typs = dict(sorted(typs.items()))
register_types(typs)
(selfdir / 'types.py').write_text(generate_python_code(typs))

View File

@ -76,6 +76,7 @@ def generate_python_code(typs: Typesdict) -> str:
'',
' from .base import Typesdict',
'',
'',
]
for name, (consts, fields) in typs.items():
@ -107,11 +108,21 @@ def generate_python_code(typs: Typesdict) -> str:
for name, (consts, fields) in typs.items():
pyname = name.replace('/', '__')
lines += [
f' \'{name}\': ([',
*[f' ({fname!r}, {ftype!r}, {fvalue!r}),' for fname, ftype, fvalue in consts],
' ], [',
*[f' ({fname!r}, {get_ftype(ftype)!r}),' for fname, ftype in fields],
' ]),',
f' \'{name}\': (',
*(
[
' [',
*[
f' ({fname!r}, {ftype!r}, {fvalue!r}),'
for fname, ftype, fvalue in consts
],
' ],',
] if consts else [' [],']
),
' [',
*[f' ({fname!r}, {get_ftype(ftype)!r}),' for fname, ftype in fields],
' ],',
' ),',
]
lines += [
'}',

File diff suppressed because it is too large Load Diff