mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
c24d33e5f1
* Generate docs exampels for Python 3.10 and above Code quality is not great and main intent here is to show the result. * Fix docs build on 3.9 * Build docs on 3.10 * What's Python 3.1? * Create temp dir if not exists * Refactor and improve imlementetion * Keep runtime typing in examples * Revert unrelated formatting changes * Add changes file * Allow specifying requirements in examples * Pin autoflake and pyupgrade * Add docs/build to Makefile lint/format/mypy * ignore_missing_imports for ansi2html and devtools * Add .tmp-projections to .gitignore * Remove dont-upgrade now when Pattern is supported * Update postponed evaluation examples Co-authored-by: Samuel Colvin <s@muelcolvin.com>
33 lines
793 B
Python
33 lines
793 B
Python
class Connection:
|
|
async def execute(self, sql, *args):
|
|
return 'testing@example.com'
|
|
|
|
|
|
conn = Connection()
|
|
# ignore-above
|
|
import asyncio
|
|
from pydantic import PositiveInt, ValidationError, validate_arguments
|
|
|
|
|
|
@validate_arguments
|
|
async def get_user_email(user_id: PositiveInt):
|
|
# `conn` is some fictional connection to a database
|
|
email = await conn.execute('select email from users where id=$1', user_id)
|
|
if email is None:
|
|
raise RuntimeError('user not found')
|
|
else:
|
|
return email
|
|
|
|
|
|
async def main():
|
|
email = await get_user_email(123)
|
|
print(email)
|
|
try:
|
|
await get_user_email(-4)
|
|
except ValidationError as exc:
|
|
print(exc.errors())
|
|
|
|
|
|
asyncio.run(main())
|
|
# requires: `conn.execute()` that will return `'testing@example.com'`
|