reagento / adaptix

An extremely flexible and configurable data model conversion library.
https://adaptix.readthedocs.io
Apache License 2.0
362 stars 24 forks source link

Some typos fixes in dataclasses introspection #266

Closed lubaskinc0de closed 4 months ago

lubaskinc0de commented 4 months ago

Rename

def _create_inp_field_from_dc_fields(dc_field: DCField, type_hints):

to

def _create_inp_field_from_dc_field(dc_field: DCField, type_hints):

because the function creates one input field from ONE dataclass field, not from multiple dataclass fields.

Which can be seen from the code:

def _create_inp_field_from_dc_field(dc_field: DCField, type_hints):
    default = _get_default(dc_field)
    return InputField(
        type=type_hints[dc_field.name],
        id=dc_field.name,
        default=default,
        is_required=default == NoDefault(),
        metadata=dc_field.metadata,
        original=dc_field,
    )

as well as

    def _get_param_kind(dc_field: DCField) -> ParamKind:
        return ParamKind.POS_OR_KW

to

    def _get_param_kind(_dc_field: DCField) -> ParamKind:
        return ParamKind.POS_OR_KW

since the dc_field parameter is not used (to avoid warnings in IDE)

lubaskinc0de commented 4 months ago

We can make the dc_field parameter positional-only, and put _ since the parameter name will now be unimportant


If HAS_PY_310:
    def _get_param_kind(dc_field: DCField, /) -> ParamKind:
        return ParamKind.KW_ONLY if dc_field.kw_only else ParamKind.POS_OR_KW
else:
    def _get_param_kind(_dc_field: DCField, /) -> ParamKind:
        return ParamKind.POS_OR_KW
github-actions[bot] commented 4 months ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/adaptix/_internal/model_tools/introspection
  dataclass.py
Project Total  

This report was generated by python-coverage-comment-action