Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
payno
workflow_concepts
Commits
a08d8f44
Commit
a08d8f44
authored
Jun 12, 2021
by
Wout De Nolf
Browse files
esrftaskgraph: proper qualname for builtins
parent
b12489b5
Changes
1
Show whitespace changes
Inline
Side-by-side
esrftaskgraph/esrftaskgraph/utils.py
View file @
a08d8f44
import
importlib
def
qualname
(
_type
):
mod_name
=
_type
.
__module__
if
not
mod_name
or
mod_name
==
str
.
__module__
:
return
_type
.
__name__
# Avoid reporting builtins
else
:
return
mod_name
+
"."
+
_type
.
__name__
def
qualname
(
obj
):
return
obj
.
__module__
+
"."
+
obj
.
__name__
def
import_qualname
(
qualname
):
if
not
isinstance
(
qualname
,
str
):
raise
TypeError
(
qualname
,
type
(
qualname
))
module_name
,
dot
,
name
=
qualname
.
rpartition
(
"."
)
module_name
,
dot
,
obj_
name
=
qualname
.
rpartition
(
"."
)
if
not
module_name
:
raise
ImportError
(
f
"cannot import
{
qualname
}
"
)
module
=
importlib
.
import_module
(
module_name
)
try
:
return
getattr
(
module
,
name
)
return
getattr
(
module
,
obj_
name
)
except
AttributeError
:
raise
ImportError
(
f
"cannot import
{
name
}
from
{
module_name
}
"
)
raise
ImportError
(
f
"cannot import
{
obj_
name
}
from
{
module_name
}
"
)
def
import_method
(
qualname
):
...
...
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