Stream: helpdesk (published)

Topic: ✔ What's a good way to get a fully qualified type.


view this post on Zulip Timothy (Apr 05 2022 at 09:59):

I'm trying to turn a type into its fully qualified name, as a string. I was hoping this would work "$(t.name.module).$(t.name.name)", but while for say t=IO or t=DataFrame it works, in other case such as t=Dict it doesn't.

Is there a good general solution for this?

view this post on Zulip Michael Hatherly (Apr 05 2022 at 10:02):

"$(parentmodule(t)).$(nameof(t))" perhaps? Seems to at least cover Dict as well.

view this post on Zulip Sebastian Pfitzner (Apr 05 2022 at 10:03):

otherwise, Base.unwrap_unionall first

view this post on Zulip Timothy (Apr 05 2022 at 10:03):

That seems to work well, thanks! Are there any caveats I should be aware of with parentmodule / nameof ?

view this post on Zulip Timothy (Apr 05 2022 at 10:04):

The documentation seems to indicate they unwrap unionall for us.

view this post on Zulip Sebastian Pfitzner (Apr 05 2022 at 10:04):

yes

view this post on Zulip Sebastian Pfitzner (Apr 05 2022 at 10:04):

those two are public API (I think) and should be used over manually accessing the type's internals

view this post on Zulip Timothy (Apr 05 2022 at 10:07):

Looks like I'm sorted then.

view this post on Zulip Notification Bot (Apr 05 2022 at 10:07):

Timothy has marked this topic as resolved.


Last updated: Nov 06 2024 at 04:40 UTC