Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple constructors #396

Open
dpsanders opened this issue Dec 31, 2016 · 7 comments
Open

Multiple constructors #396

dpsanders opened this issue Dec 31, 2016 · 7 comments

Comments

@dpsanders
Copy link
Contributor

I am trying to document multiple constructors for BigFloat added in https://github.com/JuliaLang/julia/pull/17217/files

The only way to do this seems to be to list them manually one by one. However, all docstrings for setprecision are included with one single line in numbers.md.

Is there a way to do the same for the BigFloat constructors?

@dpsanders
Copy link
Contributor Author

They also do not seem to be seen by ?BigFloat at the REPL.

@MichaelHatherly
Copy link
Member

setprecision docs are concatenated since there isn't a specific one that matches the signature Base.setprecision. BigFloat does have an exact match for Base.MPFR.BigFloat so that one is picked.

Solution might be to reorganise the docs for all BigFloat docstrings so that the BigFloat(x) docstring isn't attached to the type definition since there are no inner constructors there that match BigFloat(x). So either moving that main docstring to a BigFloat(x) def further down, or rewording that docstring so that it isn't specific to the single argument constructor.

(This is just from a very quick scan over that code, I'll have some more time in tomorrow/day after to look more closely.)

@fjarri
Copy link
Contributor

fjarri commented Nov 1, 2018

Any decision on this? Automatically collecting docstrings for all constructors of a type (the same way REPL does it) would be very convenient.

@rayegun
Copy link

rayegun commented Nov 10, 2021

Can I bump this? This would be super useful.

@mgkurtz
Copy link
Contributor

mgkurtz commented May 4, 2022

I just had kind of the same problem the other way round. When aliasing a type, say

"    Foo <: Any"
struct Foo end
"    Foo(x)"
Foo(x) = Foo()
"    (::Foo)()"
(::Foo)() = 42

AliasOfFoo = Foo

then

```@docs
AliasOfFoo
```

produces all the docstrings (with somewhat wrong heading “AliasOfFoo — Type”), although I only want the type. Maybe a syntax like

```@docs
Foo :: Type  # the type
Foo(...)  # all the constructor methods
::Foo  # all the methods of callables
```

would be a nice solution for my problem and that described above?

@mgkurtz
Copy link
Contributor

mgkurtz commented May 4, 2022

Looking into the code, it seems like signature in Julia Base only produces Union{} for types. And callable methods and constructors are not differentiated at all. So (::Foo)(x) and Foo(x) both get signature Tuple{Any}. So, implementing my idea above would need changes in Base.Docs.

The strange behavior of AliasOfFoo stems from getdocs not finding AliasOfFoo via getmeta and thus relaxing the type comparison from == to <:. As AliasOfFoo still cannot be found, getdocs tries Foo = aliasof(AliasOfFoo), but now with <: instead of ==. So we get all docstrings now.

@mortenpi
Copy link
Member

mortenpi commented May 4, 2022

@mgkurtz I think you've run into #558 (comment). The aliasing observations are useful though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants