tangui
Hi all,
I’ve been playing with Specify lately and I’m trying to get the @type module attribute like the @doc one, so as to link to that type in my documentation.
Configuration looks like this:
Specify.defconfig do
@doc "there are no floors for me to sweep"
@type floors_to_sweep :: non_neg_integer()
field :floors_to_sweep, default: 0
end
Trying to get the @type module attribute always results in a nil value:
field_documentation = Module.delete_attribute(__MODULE__, :doc)
IO.inspect(Module.delete_attribute(__MODULE__, :type))
The :doc is retrieved, but not the :type module attribute.
I suspect the @type is processed in a particular way. Is there any way to retrieve it?
Cheers
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #security
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
Yeah, you can’t get @type, @spec, @callback and friends because they have special semantics. Usually, what is stored in a module attribute is evaluated, if you do
@foo 1 + 1, the value of@foois the result of1 + 1. For typespecs, we actually receive an AST that we process, and returning that would leak some implementation details.Qqwy
Interesting use case!
Currently, when you add
@type-annotations inside thedefconfig, they will end up being shown in the documentation just as if they were written outside of thedefconfig.So
t YourModule.floors_to_sweepwould work in IEx, and in the compiled HTML documentation, the type would also be listed.If you want to fully link to a type, what about writing a parser function and adding a
@specto that one? The field documentation will link to its parser function’s documentation, and in that way you can keep the semantics together. (The other advantage is that you can re-use the same type/parser for multiple fields).tangui
Thanks for your answers.
@Qqwy: not sure to understand and if it’s the same use case
. Mine is mainly about documenting hundreds (if not more) configuration options including many callbacks with most of the time different signatures, and linking between them (config option ↔ type), and also to help dialyzer with detecting type errors. Nice lib by the way!
Qqwy
I think this part is already covered by the existing functionality. Every module that uses
defconfigwill have, for every field in the documentation, the following part in their docs:Example here.
This is indeed not something that Specify currently helps you with. It definitely would be interesting to automate the generation of a ‘config typespec’ in some way. Maybe the field types can be inferred from the parser function’s spec, and we can then define a type for the config struct as a whole.
…
Thanks!
tangui
I’ve tried it and it’s somehow difficult to generate some specs because of the special syntaxes of @type and @spec (
::, etc.). See also: Dynamically generate typespecs from module attribute listQqwy
I’m fairly certain this is what Code.Typespec is meant to be used for.
We could (as long as the parser function is readable as an invocation of a certain MFA) call
Code.Typespec.fetch_specs(module), find the appropriate function’s spec in the response, and then useCode.Typespec.spec_to_quotedto turn it back into Elixir AST, which, assuming that it has the formatsome_fun(maybe, some, arguments) :: {:ok, result_type} | {:error, problem}means that we should be able to extract theresult_typefrom here.The one thing I haven’t figured out yet is how to disambugate remote types from local and built-in ones.
tangui
I’m now trying to get the
@moduledocmodule attribute in a__using__macro but in:Module.delete_attribute/2always returnsnil(although the@moduledocis set) andModule.put_attribute/3doesn’t set it (nothing in generated doc).Is there an exception with
@moduledoc? I suspect it is not set yet when callingModule.delete_attribute/2. AlsoModule.put_attribute/3is later erased by the plain@moduledoc(I’ve tested it - no@moduledocin the target module results inadditional_docbeing displayed).jackalcooper
Is this still true today? Or there are ways to get the type specs for functions now.
josevalim
Afaik there is still no public API for doing so.