Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pablo Piskunow
kwant
Commits
3cacf427
Commit
3cacf427
authored
Feb 13, 2020
by
Christoph Groth
Browse files
ensure_isinstance: fix message when a tuple of types is given
parent
8beaa8c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
kwant/_common.py
View file @
3cacf427
...
...
@@ -101,11 +101,15 @@ def interleave(seq):
return
zip
(
iseq
,
iseq
)
def
ensure_isinstance
(
obj
,
typ
,
msg
=
None
):
if
isinstance
(
obj
,
typ
):
def
ensure_isinstance
(
obj
,
class_or_tuple
,
msg
=
None
):
if
isinstance
(
obj
,
class_or_tuple
):
return
if
msg
is
None
:
msg
=
"Expecting an instance of {}."
.
format
(
typ
.
__name__
)
if
isinstance
(
class_or_tuple
,
tuple
):
names
=
", or "
.
join
(
t
.
__name__
for
t
in
class_or_tuple
)
else
:
names
=
class_or_tuple
.
__name__
msg
=
"Expecting an instance of {}."
.
format
(
names
)
raise
TypeError
(
msg
)
def
ensure_rng
(
rng
=
None
):
...
...
Write
Preview
Supports
Markdown
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