Skip to content

Commit

Permalink
remove data.json, fix pydantic#1992 (pydantic#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Oct 11, 2020
1 parent e8326f8 commit 8ccc570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/build/exec_examples.py
Expand Up @@ -207,6 +207,13 @@ def error(desc: str):
else:
lines = lines[ignore_above + 1 :]

try:
ignore_below = lines.index('# ignore-below')
except ValueError:
pass
else:
lines = lines[:ignore_below]

lines = '\n'.join(lines).split('\n')
if any(len(l) > MAX_LINE_LENGTH for l in lines):
error(f'lines longer than {MAX_LINE_LENGTH} characters')
Expand Down
10 changes: 7 additions & 3 deletions docs/examples/models_parse.py
@@ -1,5 +1,7 @@
import pickle
from datetime import datetime
from pathlib import Path

from pydantic import BaseModel, ValidationError


Expand Down Expand Up @@ -31,8 +33,10 @@ class User(BaseModel):
)
print(m)

path = 'data.json'
with open(path, 'w') as f:
f.write('{"id": 123, "name": "James"}')
path = Path('data.json')
path.write_text('{"id": 123, "name": "James"}')
m = User.parse_file(path)
print(m)
# ignore-below
if path.exists():
path.unlink()

0 comments on commit 8ccc570

Please sign in to comment.