Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Learn pydantic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oleksiy Kashuba
Learn pydantic
Commits
7e394f43
Commit
7e394f43
authored
2 months ago
by
Alex Kashuba
Browse files
Options
Downloads
Patches
Plain Diff
Removed Type, used Optional
parent
d63cbcf9
Branches
main
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/fixtures_domain2.py
+2
-2
2 additions, 2 deletions
tests/fixtures_domain2.py
tests/test_domain2.py
+13
-1
13 additions, 1 deletion
tests/test_domain2.py
with
15 additions
and
3 deletions
tests/fixtures_domain2.py
+
2
−
2
View file @
7e394f43
from
typing
import
List
,
TypeVar
from
typing
import
List
,
Optional
from
domain2
import
DomainObject
,
annotate
from
domain2
import
DomainObject
,
annotate
...
@@ -22,7 +22,7 @@ class DomainEntryB(DomainObject):
...
@@ -22,7 +22,7 @@ class DomainEntryB(DomainObject):
class
DomainEntryC
(
DomainObject
):
class
DomainEntryC
(
DomainObject
):
"""
B class
"""
"""
B class
"""
ref
:
'
_FieldDomainEntryA
'
ref
:
Optional
[
'
_FieldDomainEntryA
'
]
refs
:
List
[
'
_FieldDomainEntryB
'
]
=
[]
refs
:
List
[
'
_FieldDomainEntryB
'
]
=
[]
...
...
This diff is collapsed.
Click to expand it.
tests/test_domain2.py
+
13
−
1
View file @
7e394f43
...
@@ -63,3 +63,15 @@ def test_int_ref_chain():
...
@@ -63,3 +63,15 @@ def test_int_ref_chain():
DomainEntryB
.
model_construct
(
id
=
2
,
refs
=
[
12
,
13
])
DomainEntryB
.
model_construct
(
id
=
2
,
refs
=
[
12
,
13
])
]
]
assert
container2
.
ref
==
DomainEntryA
.
model_construct
(
id
=
3
,
name
=
'
Name 3
'
)
assert
container2
.
ref
==
DomainEntryA
.
model_construct
(
id
=
3
,
name
=
'
Name 3
'
)
def
test_ref_optional
():
container
=
DomainEntryC
.
model_construct
(
id
=
4
,
ref
=
None
,
refs
=
[
1
,
2
])
container2
=
DomainEntryC
.
model_validate
(
container
,
strict
=
True
)
assert
container
.
ref
is
None
assert
container2
.
ref
is
None
def
test_ref_optional_2
():
container
=
DomainEntryC
.
model_construct
(
id
=
4
,
refs
=
[
1
,
2
])
with
pytest
.
raises
(
ValidationError
,
match
=
"
1 validation error for DomainEntryC
"
):
DomainEntryC
.
model_validate
(
container
,
strict
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment