pydantic / bump-pydantic

Convert Pydantic from V1 to V2 ♻
MIT License
303 stars 24 forks source link

Convert `example` parameter into `examples` on `Field` #122

Closed Gamrix closed 12 months ago

Gamrix commented 1 year ago

This codemod is intended to convert an example to a single element list of examples.

~When I tried to run it however, I get the following exception from libcst. I presume it is because there is a bug with the list construct, but it could be a coding mistake on my part.~

Thanks Brian for the suggestion that fixed this PR.

self = Integer(
    value='1',
    lpar=[],
    rpar=[],
)
state = CodegenState(default_indent='    ', default_newline='\n', provider=None, indent_tokens=['    '], tokens=['from', ' ', ...'int', ' ', '=', ' ', 'Field', '', '(', '', '', '', '...', '', ',', ' ', '', '', '', 'examples', '', '=', '', '[', ''])
kwargs = {'default_comma': False, 'default_comma_whitespace': True}

    def _codegen(self, state: CodegenState, **kwargs: Any) -> None:
        state.before_codegen(self)
>       self._codegen_impl(state, **kwargs)
E       TypeError: _codegen_impl() got an unexpected keyword argument 'default_comma'

../../.pyenv/versions/3.9.16/lib/python3.9/site-packages/libcst/_nodes/base.py:300: TypeError
- generated xml file: /var/folders/sh/fdr554614wlb2s12tx1bw8wm0000gn/T/tmp-78979sbVUwmyuq3zy.xml -

EDIT by @Kludex: