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

feature: Add "value" column to tables for Attributes docstring sections #533

Open
quantfreedom opened this issue Feb 22, 2023 · 11 comments
Open
Labels
extractor: griffe Related to griffe feature New feature or request

Comments

@quantfreedom
Copy link

quantfreedom commented Feb 22, 2023

Is there a way to make it so that the enums or at least the way i have my enums setup, to auto update every time i update a default value for a variable in a tuple?

Right now if i make a change to a value i have to also make the change in the doc string ... but what i want it to do is grab the default value like it does if it is a function.

Here is example of my code

class OrderTypeT_QF(tp_qf.NamedTuple):
    """
    Define if you want to do an entry or exit trade.

    !!! tip
        A quick exmaple would be something like this `order_type=OrderType.LongTP`.

        This is the same as saying `order_type=3.` and would set your order type to a long take profit.

    Attributes:
        LongEntry: `0.` Long Entry
        LongSL: `1.` Long Stop Loss
        LongTSL: `2.` Long Trailing Stop Loss
        LongTP: `3.` Long Take Profit
        LongLiq: `4.` Long Liquidation
        ShortEntry: `5.` Short Entry
        ShortSL: `6.` Short Stop Loss
        ShortTSL: `7.` Short Trailing Stop Loss
        ShortTP: `8.` Short Take Profit
        ShortLiq: `9.` Short Liquidation
    """
    LongEntry: float = 0.
    LongSL: float = 1.
    LongTSL: float = 2.
    LongTP: float = 3.
    LongLiq: float = 4.
    ShortEntry: float = 5.
    ShortSL: float = 6.
    ShortTSL: float = 7.
    ShortTP: float = 8.
    ShortLiq: float = 9.

but this guy that i am forking my project from does it in a way that grabs the values automatically and he doesn't have to type any of the changes out

class CallSeqTypeT(tp.NamedTuple):
    Default: int = 0
    Reversed: int = 1
    Random: int = 2
    Auto: int = 3


CallSeqType = CallSeqTypeT()
"""_"""

__pdoc__['CallSeqType'] = f"""Call sequence type.
```json
{to_doc(CallSeqType)}
```json
Attributes:
    Default: Place calls from left to right.
    Reversed: Place calls from right to left.
    Random: Place calls randomly.
    Auto: Place calls dynamically based on order value.
"""

https://vectorbt.dev/api/portfolio/enums/#vectorbt.portfolio.enums.CallSeqType

Is there some type of way of doing this is mkdocstrings and if not is there some type of function i could create that would do something like vectorbt ... because it is going to be a nightmare every time i add and remove things from these tuples

@quantfreedom
Copy link
Author

same thing with this numpy data type
https://vectorbt.dev/api/portfolio/enums/#vectorbt.portfolio.enums.log_dt
https://github.com/polakowo/vectorbt/blob/9155bddebc634846b419e261f9058cbda708bbdc/vectorbt/portfolio/enums.py#L1645-L1694

i am doing the same thing and there is no way i want to have to keep typing all of this stuff out lol

@quantfreedom quantfreedom changed the title Auto Update Enums Auto Update Enums AKA Tuples and Variables Feb 22, 2023
@quantfreedom
Copy link
Author

Also i am noticing that the mkdocstrings doesn't seem to allow you to do something like

f"""
Hey
"""

If i do that then it doesn't read anything ... so is it even possible to do a f""" ?

@quantfreedom
Copy link
Author

@pawamoy .... wanted to check back in on this and see if you had any ideas?

@pawamoy
Copy link
Member

pawamoy commented Feb 24, 2023

Hey @QuantFreedom1022, that's a good suggestion yes. I think other users asked for the "default" column for attributes tables, and I believe it's possible to have it (though I'd probably call it "value" more than "default").

Now, the vectorbt library you mentioned seems to use pdoc, and pdoc runs the code (inspects/introspects it) to get the data. This is why they can use some magic __pdoc__ variable, and modify docstrings dynamically, and this is why they support f-strings for docstrings and we don't: f-strings are dynamic, they need to be executed to get their final value, which we do not want to do within our static parser/visitor.

But there's a workaround: Griffe (the tool that collects info about your Python code), is also able to inspect (not visit) your code, and it provides a builtin extension that lets you choose which object to inspect, additionally to visiting it. It's the "hybrid" extension (and it's experimental). I'll try to come up with an example on how to use it a bit later 🙂

@quantfreedom
Copy link
Author

@pawamoy hey man thanks for getting back to me on this ... and yeah I agree with u about the default column ... I am sure tons and tons of users would love this and I also agree that it could be called value instead of default

And I kind of feel bad having you have to look up all this information yourself and figure it out and then get back to me. I would be open to making this a collaborative effort where maybe we could jump on a screen sharing call and talk about possible solutions and then work on the solution together so that way you don't have to do this by yourself

@pawamoy
Copy link
Member

pawamoy commented Feb 24, 2023

That's very kind @QuantFreedom1022, I appreciate your willingness to help, but don't worry, this is my project, I enjoy helping people using it 😄 I have started playing with Griffe extensions more, and I want them to work well before I advertise them, so it's good that I try them myself!

I also much prefer asynchronous collaboration rather than getting on a screen sharing call. I believe everything can be accomplished with async messages, even if it can sometimes takes more time. So helping each other in this very issue is absolutely fine!

Thank you again for such kindness, this is a great thing to have in open source communities ❤️

@quantfreedom
Copy link
Author

@pawamoy yeah no problem ... and when you think you have it done i would be more than happy to be the test dummy

@quantfreedom
Copy link
Author

@pawamoy is there any update on this? do you need me to do anything? or how do i get setup with some type of notification that you completed this or are looking for it to be tested?

@pawamoy
Copy link
Member

pawamoy commented Mar 3, 2023

You'll be notified of any progress on this ticket if you've subscribed to it (which is the case by default when you create a ticket) 😉

@pawamoy pawamoy added feature New feature or request and removed question labels Mar 5, 2023
@quantfreedom
Copy link
Author

@pawamoy ... hey i have a question ... was wondering if you were able to implement this yet ... and also was wondering if it would be possible to get some one on one lessons for like an hour or two on how to use mkdocstrings ... i have a strong enough understanding to use it but i just want to skip all the learning curve and be able to ask you questions in real time ... willing to pay you for your time

@pawamoy
Copy link
Member

pawamoy commented Apr 1, 2023

@QuantFreedom1022 I did not have a lot of time to work a lot on mkdocstrings these last months. Development was very slow. But my professional situation changed very recently and I'll be able to dedicate a lot more time to mkdocstrings. Keep watching the organization and its repositories and you should see much more activity 😉

I'm not ready yet to offer one-on-one support calls, but since you mention financial compensation, please know that the project now relies more than ever onto sponsors. We can also chat in real time on the Gitter channel.

@pawamoy pawamoy changed the title Auto Update Enums AKA Tuples and Variables Add "value" column to tables for Attributes docstring sections Apr 27, 2024
@pawamoy pawamoy changed the title Add "value" column to tables for Attributes docstring sections feature: Add "value" column to tables for Attributes docstring sections Apr 27, 2024
@pawamoy pawamoy added the extractor: griffe Related to griffe label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extractor: griffe Related to griffe feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants