Comments (6)
Hey! So, I just pushed version 0.17.0 which brings more labels based on decorators
@property
givesproperty
label- if there's a property setter,
writable
label is added - if there's a property deleter,
deletable
label is added @staticmethod
givesstaticmethod
label@classmethod
givesclassmethod
label@functools.cache
,@functools.cached_property
and@functools.lru_cache
givecached
label (and I realize I forgot to add aproperty
label when the decorator iscached_property
, will add later). It works with brief and full path (@functools....
and@...
)@abc.abstractmethod
givesabstract
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.
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.
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.
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.
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.
Thanks! I hope I'll be able to get to it soon so I can give you some feedback!
from griffe.
Related Issues (20)
- Subprocess error when checking project with no tags
- AliasResolutionError when checking project
- False positive when object becomes alias to object of the same type HOT 1
- Finder: use importlib.util._find_spec? HOT 1
- Unhandled case of a walrus operator in the output part of a list comprehension HOT 1
- Make inheritance of members from the parent class configurable when inspecting HOT 1
- Griffe with scikit-build-core does not work in editable mode HOT 17
- Infinite recursion, while loading `numpy` modules HOT 9
- docs for compiled modules contain all attributes HOT 10
- KeyError: 'python3' HOT 5
- Handling modules with dots in name HOT 9
- Error parsing the following code in a `.pyi` file, where types are marked as strings HOT 2
- Regression in 0.28 HOT 6
- Duplicate entries when checking project
- Expression.full() errors if any Expressions inside it HOT 2
- Fails to recognize optional arguments in NamedTuple HOT 2
- griffe fails to unparse `ast.Call ` at `ast.NamedExpr` (containing an assignment expression) HOT 4
- numpy parser parameter table breaks if there is an empty line between parameters HOT 5
- understand and document `typing/typing_extensions.deprecated` HOT 8
- temporary_visited_module requires manually running patch_ast beforehand HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from griffe.