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

[docs] Enforce use of Args: over Attrs: in class docstrings #15404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smackesey
Copy link
Collaborator

@smackesey smackesey commented Jul 20, 2023

Summary & Motivation

Currently in the codebase, some classes use Attributes: and others use Args: to list class parameters in docstrings. While the semantics between these are technically different (in principle class attributes need not correspond to constructor params at all), in practice I believe that everywhere we use "Attributes" we are really documenting constructor params. In any case we have no need to directly document attributes since we expose them through @property.

"Attributes" and "Args" cases render quite differently (see screenshots). This PR:

  • converts all existing uses of Attributes to Args (which renders more compactly and consistently with functions)
  • adds a check to the API doc build that causes a failure if use of Attributes: is detected.

"Args" style (preferred, enforced by this PR):

image

"Attributes" style:

image

How I Tested These Changes

Built docs.

@smackesey
Copy link
Collaborator Author

smackesey commented Jul 20, 2023

@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from dbb83ba to a0ae028 Compare July 20, 2023 09:56
@github-actions
Copy link

github-actions bot commented Jul 20, 2023

Deploy preview for dagster ready!

Preview available at https://dagster-gm5422dvj-elementl.vercel.app

Direct link to changed pages:

@sryza
Copy link
Contributor

sryza commented Jul 20, 2023

I agree that the way that "Args" gets rendered looks a lot nicer. However, I think that "Attrs" is more representative of what we're trying to communicate, i.e. that these are the attributes of this class. I wonder if there's some way to address the rendering issues.

Also see: https://stackoverflow.com/questions/46569163/sphinx-document-an-attribute-that-is-same-as-a-parameter

@smackesey
Copy link
Collaborator Author

I agree that the way that "Args" gets rendered looks a lot nicer. However, I think that "Attrs" is more representative of what we're trying to communicate, i.e. that these are the attributes of this class. I wonder if there's some way to address the rendering issues.

Disagree that "Attrs" is more representative of what we're communicating, because the way most of our public classes are written we don't expose attributes-- we expose properties, which are documented separately. At the level of the class docstring itself, the public API we are documenting is the constructor parameters, not the attributes, which are typically private. Also, often the constructor parameters are going to differ from the attributes-- this happens whenever there is a deprecated param, but also in other cases where there is some logic in the constructor. It's clear that we need to document such deprecated constructor params but it would be incorrect to call them "attributes".

Now for NamedTuple classes, we actually do expose attributes via PublicAttr. Most of the time these are identical to the constructor params, but not always. To be technically correct we would have separate documentation of the constructor params and the attributes, but that seems like overkill when they are the same 95% of the time. There is probably something we can do in sphinx to solve this, I have to think about it.

@smackesey smackesey force-pushed the sean/param-warning-decorators branch from b2a509c to d374213 Compare July 20, 2023 21:36
@sryza
Copy link
Contributor

sryza commented Jul 21, 2023

In a google search on "python properties vs attributes", most results claim that properties are a special kind of attribute.

In many cases, the types that a constructor accepts will be more permissive than the class's attributes, or constructors will include deprecated parameters that get converted to canonical attributes. It's useful to have documentation for the canonical attributes because they describe what the class is, rather than just what arguments are required to construct it.

@sryza
Copy link
Contributor

sryza commented Jul 21, 2023

Might be worth collecting other opinions from the team? Not a hill that I'm going to die on.

@smackesey smackesey force-pushed the sean/param-warning-decorators branch from d374213 to d131026 Compare July 21, 2023 17:36
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 47a90c4 to 2c5c5e4 Compare July 21, 2023 17:36
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from d131026 to 35aae90 Compare July 21, 2023 18:44
Copy link
Contributor

@erinkcochran87 erinkcochran87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it to others to stamp on code, but stylistically this is a great improvement. Thank you Sean!

@smackesey smackesey force-pushed the sean/param-warning-decorators branch from 35aae90 to 19afff1 Compare July 24, 2023 14:05
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 6cfb676 to c97860e Compare July 29, 2023 16:43
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from 7d507e5 to b446704 Compare July 29, 2023 16:55
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from c97860e to 0cd2011 Compare July 29, 2023 16:55
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from b446704 to 8df9d08 Compare July 30, 2023 15:36
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 0cd2011 to 9d35d69 Compare July 30, 2023 15:36
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from 8df9d08 to c29dd24 Compare July 31, 2023 19:10
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 9d35d69 to ef69f9a Compare July 31, 2023 19:10
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from c29dd24 to af5089f Compare August 1, 2023 15:06
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from ef69f9a to 92de7ff Compare August 1, 2023 15:06
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from af5089f to e4b55ba Compare August 1, 2023 16:25
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 92de7ff to 9c0a2cf Compare August 1, 2023 16:25
@smackesey smackesey force-pushed the sean/param-warning-decorators branch from e4b55ba to 8857f68 Compare August 1, 2023 17:34
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from 9c0a2cf to 46fc155 Compare August 1, 2023 17:34
@smackesey
Copy link
Collaborator Author

smackesey commented Aug 1, 2023

Might be worth collecting other opinions from the team? Not a hill that I'm going to die on.

pinging @dpeng817 @yuhan

Base automatically changed from sean/param-warning-decorators to master August 1, 2023 18:00
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch 2 times, most recently from e1144f9 to a46f596 Compare August 1, 2023 20:00
@smackesey smackesey force-pushed the sean/docs-enforce-args-in-classes branch from a46f596 to bd3c839 Compare August 1, 2023 23:08
@smackesey
Copy link
Collaborator Author

@sryza ping for response to above

AFAICT this is straightforwardly correct for non-NamedTuple classes for the reasons I wrote.

@yuhan
Copy link
Contributor

yuhan commented Aug 17, 2023

im on team Args but im not a super python expert. my reason is mostly the api docs generated via args look a lot better.

however, i did a quick research in popular python libs:

where some list those as "parameters" and some are "attributes". wonder if we could leave things as "parameters" and not differentiate them?

im fine either way. if we want to be right, it's worth checking with other folks who have more core python understanding.

@dpeng817
Copy link
Contributor

dpeng817 commented Dec 5, 2023

What's the status here? Requesting changes to get this out of my queue.

FWIW, I'm in favor of the args approach. Formatting is clearly a step function improvement over attrs.

Copy link
Contributor

@dpeng817 dpeng817 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

back to q

@graphite-app graphite-app bot added the area: docs Related to documentation in general label Sep 28, 2024
Copy link

graphite-app bot commented Sep 28, 2024

Graphite Automations

"Label and add CE on all Docs" took an action on this PR • (09/28/24)

3 reviewers were added and 1 label was added to this PR based on Pedram Navid's automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Related to documentation in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants