pydantic / bump-pydantic

Convert Pydantic from V1 to V2 ♻
MIT License
323 stars 25 forks source link

Preserve line break codes #169

Closed ajisaka closed 4 months ago

ajisaka commented 5 months ago

Ensure that bump-pydantic command does not change the newline code.

Kludex commented 5 months ago

What is happening?

ajisaka commented 5 months ago

On Linux, when bump-pydantic is run on source code with Windows-style newline code (CRLF), the newline code is rewritten to LF. Changing newlines is not the expected behavior of this tool.

ajisaka commented 5 months ago

The reproduction method is as follows

$ echo -n 'from pydantic import BaseModel\r\nclass User(BaseModel):\r\n  name: Optional[str]\r\n' > test.py
$ file test.py
test.py: Python script, ASCII text executable, with CRLF line terminators
$ rye run --pyproject ~/repos/bump-pydantic/pyproject.toml bump-pydantic .
[22:16:37] Start bump-pydantic.                                                                                                                                                                            main.py:67
           Found 1 file to process.                                                                                                                                                                        main.py:82
[22:16:38] Refactored 1 files.                                                                                                                                                                            main.py:150
           Run successfully!                                                                                                                                                                              main.py:160
$ file test.py
test.py: Python script, ASCII text executable

The output result of the file command is different between the first and second times.

Kludex commented 4 months ago

Thanks!