Document properties as attributes#7068
Document properties as attributes#7068flying-sheep wants to merge 28 commits intosphinx-doc:masterfrom
Conversation
|
Hi @tk0miya, my links are degrading more and more as other projects start compiling their docs with the buggy release. Could you please merge this soon and make a release? |
|
@flying-sheep I think this changes policy of python domain. So we have to design how to mark up whole of python object. So I can't merge this soon. I believe #7061 is a workaround to avoid the broken references. |
|
OK, no problem, #7061 circumvents the problem well enough for the time being. I’m happy to work on this PR in the meantime until it fullfills your requirements 😃 |
688ff7d to
184ee04
Compare
|
Let’s continue the discussion here. I agree about I’m not sure what we should go with, I think the first two of them have balanced pros and cons: A) IMHO the following would be the best and simplest option if sphinx was designed that way from the start. It just pains me to see But it would confuse the hell out of people accustomed to the old way of doing it! On the other hand just deprecating the old way for years to come is possible. .. py:method:: hello()
:abstract:
:async:
:return:
:rtype:
.. py:classmethod:: hello()
...
.. py:staticmethod:: hello()
...
.. py:attribute:: name
:abstract:
:property:
:type:
:value:B) If we decide to stay with .. py:method:: hello()
:abstractmethod:
:staticmethod:
:classmethod:
:async:
:return:
:rtype:
.. py:attribute:: name
:abstractmethod:
:property:
:type:
:value: |
|
At this moment, I vote to plan C. About A)
I don't think so. We usually see XXXmethod decorators and asyc keyword in python code. I believe writer of python docs must be a python programmer. So it is not inconsistent with python. To me, a characteristic of plan A is to use simple keywords to describe their behavior: abstract, async and etc. But they are different with keywords in python, Sphinx originals. IMO, this plan is not easy to understand. I prefer to learn less keywords. This is why I hesitate to choose plan A. About B)
I think abstractmethod is also same as python's decorator. AFAIK, we usually use abc.abstractmethod decorator to make an abstract method, right?
I think they can take different options. A property can take
|
|
One counter argument is that properties must end up as Say people have links like And if the correct way to refer to attributes and properties is via |
Why? If you worry about referencing role, type in object.inv is not related with it. As we did in 2.4 release, we can refer I think providing new role (Note: please post a new comment if you rewrite it. Updates are not emailed.) |
|
As said: Moving an API from property to attribute or the other way is a transparent act, that consumers of the API won’t notice. If Sphinx makes links break or behave in any way different beween attributes and properties, then Sphinx breaks this guarantee. Therefore |
|
Sorry, I'm confused. Adding |
|
OK, so you basically just want to introduce the |
|
Okay, done! |
tk0miya
left a comment
There was a problem hiding this comment.
Thank you for update. But it seems there are misunderstanding between us... I still don't understand what you meant API is.
|
The remaining mypy failures are not mine. No idea why they are there. |
|
Haha me neither. Let’s try this: My motivation is that when a developer changes attribute to a property or the other way round:
Therefore I propose that
|
I prefer your idea. It's nice for the default settings of autosummary. But it does not mean they are always grouped. It would be better that users can separate attributes and properties to different lists (using customized templates or other methods).
It's a difficult question. Surely, And I think directives and roles should be a pair (except Note: As discussed above, I agree to refer properties via
-1. I don't think so because they are different things. I think this is a root cause of this discussion. I consider they are different. And you consider they are same. I think both are correct. It's only different perspective. But it is difficult to get agreed. |
great, let’s do it that way then!
If we have a link role for most directives, it is only consistent to have one for every directive. I agree. My issue with having both is that if they’d do the same, they’d be purely cosmetic, see the next point:
I think that’s a great principle, but I think it refers to things with actual semantics attached to it, i.e. different behavior. If two or more things do exactly the same, then another principle applies: “There should be one – and preferably only one – obvious way to do it”
I don’t. They’re clearly different in implementation. I only consider them to be the same from a user/consumer perspective, i.e. for someone accessing an instance attribute/property ( Can we agree to give property links the If you really want both roles, there’s only one question left: should a |
Sorry. It's my lack of words. But nobody object to they're same in implementation if they knows python. So this is a concern about documentation (in Sphinx). I believe they are different (but similar). And you're thinking they should be the same, right? I think how to describe (author side) and how to represent (user/consumer side) is strongly coupled. So, based on user/consumer perspective you said, attributes and properties should be described as same in my idea. It means we should use
The another principle does not match this case because they are different.
Agreed. I think they are similar. So no reason to object that.
Hmm... it's a difficult question. +0 for the idea if we can keep consistent. Now we can refer a class entry via |
Documentation referring to them should be the same because using them from code is the same and the implementation can be transparently switched at any moment (i.e. without breaking anyone’s code). E.g.:
I don’t understand why in my use case my link should suddenly gain a |
What these expectations came from? About CSS rule was just proposed at above comment. Nothing determined. And who determines "more correct" way? I think both |
|
If there’s no correct way, there’s no reason to have two roles for the same job, no? |
|
My answer is always same. Because they are different. |
|
It's been a month since I've commented. I've read the discussions over the past month and my opinion has not changed. While documentation should be written for the reader, I believe it is important to be able to directly describe the representation of the implementation in order to accurately convey the information that the reader expects. In that sense, it is not appropriate for a reader to see the property as The problem of the above sample code is that it shows I think merging the implementation of #7298 would "directly describe the representation of the implementation and allow the reader to get the information without misunderstanding". It also solves the problem of adding My opinion summary:
|
|
OK, I’ll review it. |
py domain: Add py:property directive to describe a property (refs: #7068)
Subject: Properties are more like attributes than they’re like methods.
Feature or Bugfix
Purpose
Fixes regression introduced by #6320 which resulted in properties being filed in as
std:methodinstead ofstd:attributeand therefore people’s:py:attr:links to properties breaking.Detail
A method is a descriptor that returns a bound method on
__get__(a bound method is always callable, with the first argument fixed to the instance).A property is a descriptor that directly returns a value that’s usually not callable on
__get__.Therefore it makes no sense to view properties as “methods”. Besides, as said, #6320 broke links in many many projects.
You already list them as attributes in
generate_autosummary_contenttoo.Relates