Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
9f58becc
Unverified
Commit
9f58becc
authored
Oct 06, 2021
by
David del Río Medina
Committed by
GitHub
Oct 05, 2021
Browse files
Replace assert statements with exceptions (#13871)
parent
155b2300
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
src/transformers/file_utils.py
src/transformers/file_utils.py
+4
-4
No files found.
src/transformers/file_utils.py
View file @
9f58becc
...
...
@@ -1896,10 +1896,10 @@ class ModelOutput(OrderedDict):
class_fields
=
fields
(
self
)
# Safety and consistency checks
asser
t
len
(
class_fields
)
,
f
"
{
self
.
__class__
.
__name__
}
has no fields."
assert
all
(
field
.
default
is
None
for
field
in
class_fields
[
1
:]
),
f
"
{
self
.
__class__
.
__name__
}
should not have more than one required field."
if
no
t
len
(
class_fields
)
:
raise
ValueError
(
f
"
{
self
.
__class__
.
__name__
}
has no fields."
)
if
not
all
(
field
.
default
is
None
for
field
in
class_fields
[
1
:]
):
raise
ValueError
(
f
"
{
self
.
__class__
.
__name__
}
should not have more than one required field."
)
first_field
=
getattr
(
self
,
class_fields
[
0
].
name
)
other_fields_are_none
=
all
(
getattr
(
self
,
field
.
name
)
is
None
for
field
in
class_fields
[
1
:])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment