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

3.9: Remove docstring shenanigans from events #3837

Open
AstraLuma opened this issue Oct 5, 2020 · 7 comments
Open

3.9: Remove docstring shenanigans from events #3837

AstraLuma opened this issue Oct 5, 2020 · 7 comments
Labels

Comments

@AstraLuma
Copy link
Member

Python 3.9.0 changed the way docstrings are searched, which I believe means we no longer need the dynamic type shenanigans in xonsh.events.

@scopatz
Copy link
Member

scopatz commented Oct 6, 2020

Oh, that would be nice!

@anki-code anki-code added the py39 label Feb 6, 2021
@jnoortheen
Copy link
Member

@AstraLuma could you explain what has been changed a bit?

@AstraLuma
Copy link
Member Author

From the 3.9 changes:

The documentation string is now shown not only for class, function, method etc, but for any object that has its own doc attribute. (Contributed by Serhiy Storchaka in bpo-40257.)

@jnoortheen
Copy link
Member

jnoortheen commented Dec 21, 2021

Ok. I don't see dropping 3.8 anytime soon. Though I find this following pattern very easier to read and reason with.

# any new event can create an empty function with the correct signature
def autovox_policy(path: "Path") -> "str|Path|None":
    """
    Register a policy with autovox.
    Parameters
    -----------
    ...
    """

# we can then use this register function to wrap `EventManager.doc`
    def register(self, func):
        """
            wraps ``EventManager.doc``

        Parameters
        ----------
        func
            extract name and doc from the function
        """

        name = func.__name__
        doc = inspect.getdoc(func)
        sign = inspect.signature(func)
        return self.doc(name, f"{name}{sign}\n\n{doc}")

I have this locally and planning to create a PR later.

@AstraLuma
Copy link
Member Author

AstraLuma commented Dec 23, 2021

Yeah, I thought about doing a function-based version of event definition as well. But the existing system was already established and I didn't think the incremental improvement over it was worth it.

@jnoortheen
Copy link
Member

I want to create an entrypoint based xontrib loading mechanism. Where I want to remove any global access. It would be helpful in that time.

@AstraLuma
Copy link
Member Author

Not all event handlers come from xontribs.

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

No branches or pull requests

4 participants