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
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #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.