Coder Social home page Coder Social logo

Comments (6)

pawamoy avatar pawamoy commented on May 17, 2024 3

Hey! So, I just pushed version 0.17.0 which brings more labels based on decorators 🙂

  • @property gives property label
  • if there's a property setter, writable label is added
  • if there's a property deleter, deletable label is added
  • @staticmethod gives staticmethod label
  • @classmethod gives classmethod label
  • @functools.cache, @functools.cached_property and @functools.lru_cache give cached label (and I realize I forgot to add a property label when the decorator is cached_property, will add later). It works with brief and full path (@functools.... and @...)
  • @abc.abstractmethod gives abstract label (mkdocstrings/mkdocstrings#349)

I think we can close this issue, but please do open issues if you have other ideas for properties! Now that there's basic support it should not be difficult to add more.

from griffe.

pawamoy avatar pawamoy commented on May 17, 2024 2

Great, your help offering is appreciated 🙂
Let me handle a few decorators/labels first, and once I'm confident this can be further improved, I'll let you know 🙂

from griffe.

pedrolabonia avatar pedrolabonia commented on May 17, 2024 1

Also passing by to show my interest. If you have any feel for how this could be implemented, I could also give it a go :)

from griffe.

pawamoy avatar pawamoy commented on May 17, 2024

Hello @wxdrizzle!

You're right, I didn't reapply the same logic for properties in Griffe. The "labels?" item in the TODO list just means: "what labels can we have on each type of object?". For example, we could have staticmethod, like before, but maybe it should be called static instead? Since it's a decorator, will every decorator become a label on an object? Or just the ones that are built-in or in the standard library? How to let users extend that?

Griffe already sets labels on attributes (module-attribute, class-attribute and instance-attribute), because it was easy to do, but for methods it's a bit more complicated. Well, not really for the classic staticmethod, classmethod and property: the decorator is a single name that we can easily match. But others, like @property_name.setter or @abc.abstractmethod need a bit more of work.

If you are interested in contributing something, I can give you some guidance, otherwise I'll eventually get to it 😄

from griffe.

wxdrizzle avatar wxdrizzle commented on May 17, 2024

Hi again @pawamoy !

I think staticmethod and classmethod will be good features to distinguish those methods from other regular methods, although one can directly get that from whether the signature contains no self or contains cls. For me, both staticmethod and static are good.

Adding the label property is also important, but instead we can also simply remove (self) from a property's signature to tell users that they can just use it without a (). For @property_name.setter, maybe the best way is to add a label readonly, but since you said that would need more work, so currently it is sufficient for users to just add "readonly" information in the docstring.

Personally I think Other non-built-in decorators may be another issue, as it may require a context for both users and readers to know what the decorator means. So it may be better if we can provide an option to enable or disable the labels. That could be a long-term plan.

In a nutshell, I'm happy if I can contribute something. I can help add the classic staticmethod, classmethod and property recently, as you said it is not very complicated. For setter and abstractmethod, I'm just not sure if my knowledge is good enough to handle that, but you can also consider to provide some quick guidance and I'm willing to read some tutorials as well. 😉

from griffe.

pawamoy avatar pawamoy commented on May 17, 2024

Thanks! I hope I'll be able to get to it soon so I can give you some feedback!

from griffe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.