-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_processing.py
More file actions
27 lines (22 loc) · 805 Bytes
/
Copy pathpost_processing.py
File metadata and controls
27 lines (22 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
path = 'src/models.py'
# Read the file content.
with open(path, 'r', encoding='utf-8') as file:
lines = file.readlines()
# Add the extra import (after `from __future__` to avoid errors).
lines.insert(5, 'from pydantic import RootModel, ConfigDict\n')
content = ''.join(lines)
# Perform string replacements.
content = content.replace('__root__', 'RootModel').replace('ResponseModel', 'Response')
# Replace
# ```
# class Config:
# extra = Extra.forbid
# ```
# with
# `model_config = ConfigDict(extra='forbid')`
# to avoid warnings when running pytest.
content = content.replace('class Config:', "model_config = ConfigDict(extra='forbid')")\
.replace(' extra = Extra.forbid', '')
# Save the new file content.
with open(path, 'w', encoding='utf-8') as file:
file.write(content)