Skip to content

Commit

Permalink
[docs] Enforce use of Args: over Attrs: in class docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
smackesey committed Aug 1, 2023
1 parent 41d9921 commit a46f596
Show file tree
Hide file tree
Showing 29 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/content/api/modules.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/content/api/searchindex.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/content/api/sections.json

Large diffs are not rendered by default.

Binary file modified docs/next/public/objects.inv
Binary file not shown.
23 changes: 16 additions & 7 deletions docs/sphinx/_ext/autodoc_dagster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import json
import textwrap
from typing import Any, List, Tuple, Type, Union, cast
from typing import Any, List, Sequence, Tuple, Type, Union, cast

import dagster._check as check
import docutils.nodes
Expand Down Expand Up @@ -170,6 +170,12 @@ def add_content(self, more_content) -> None:
super().add_content(more_content)


def record_error(self, env, message: str) -> None:
if not hasattr(env, "dagster_errors"):
env.dagster_errors = []
env.dagster_errors.append(message)


class DagsterClassDocumenter(ClassDocumenter):
"""Overrides the default autodoc ClassDocumenter to adds some extra options."""

Expand All @@ -184,11 +190,6 @@ def add_content(self, *args, **kwargs):
for alias in self.options.get("deprecated_aliases", []):
self.add_line(f"ALIAS: {alias}", source_name)

def record_error(self, message: str) -> None:
if not hasattr(self.env, "dagster_errors"):
self.env.dagster_errors = []
self.env.dagster_errors.append(message)

def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
_, unfiltered_members = super().get_object_members(want_all)
# Use form `is_public(self.object, attr_name) if possible, because to access a descriptor
Expand All @@ -210,13 +211,21 @@ def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
"All public methods and properties must have docstrings."
)
logger.info(msg)
self.record_error(msg)
self.record_error(self.env, msg)
return False, filtered_members


def has_attrs(docstring: Sequence[str]) -> bool:
return any(line.startswith(".. attribute::") for line in docstring)


# This is a hook that will be executed for every processed docstring. It modifies the lines of the
# docstring in place.
def process_docstring(app, what, name, obj, options, lines):
if has_attrs(lines):
message = f'Object {name} has "Attributes:" in docstring. Use "Args:" insetad.'
record_error(app.env, message)

# Insert a "deprecated" sphinx directive (this is built-in to autodoc) for objects flagged with
# @deprecated.
if is_deprecated(obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AssetIn(
):
"""Defines an asset dependency.
Attributes:
Args:
key_prefix (Optional[Union[str, Sequence[str]]]): If provided, the asset's key is the
concatenation of the key_prefix and the input name. Only one of the "key_prefix" and
"key" arguments should be provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AssetOut(
):
"""Defines one of the assets produced by a :py:func:`@multi_asset <multi_asset>`.
Attributes:
Args:
key_prefix (Optional[Union[str, Sequence[str]]]): If provided, the asset's key is the
concatenation of the key_prefix and the asset's name. When using ``@multi_asset``, the
asset name defaults to the key of the "outs" dictionary Only one of the "key_prefix" and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FreshnessPolicySensorContext(
):
"""The ``context`` object available to a decorated function of ``freshness_policy_sensor``.
Attributes:
Args:
sensor_name (str): the name of the sensor.
asset_key (AssetKey): the key of the asset being monitored
freshness_policy (FreshnessPolicy): the freshness policy of the asset being monitored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MultiAssetSensorAssetCursorComponent(
included in "unevaluated_partitioned_event_ids", because it's after the event that the cursor
for its partition has advanced to, but trails "latest_evaluated_event_id".
Attributes:
Args:
latest_consumed_event_partition (Optional[str]): The partition of the latest consumed event
for this asset.
latest_consumed_event_id (Optional[int]): The event ID of the latest consumed event for
Expand Down Expand Up @@ -183,7 +183,7 @@ class MultiAssetSensorEvaluationContext(SensorEvaluationContext):
To update the cursor to the latest materialization and clear the unconsumed events, call
`advance_all_cursors`.
Attributes:
Args:
monitored_assets (Union[Sequence[AssetKey], AssetSelection]): The assets monitored
by the sensor. If an AssetSelection object is provided, it will only apply to assets
within the Definitions that this sensor is part of.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class MultiPartitionsDefinition(PartitionsDefinition[MultiPartitionKey]):
A mapping of dimension name to partitions definition. The total set of partitions will
be the cross-product of the partitions from each PartitionsDefinition.
Attributes:
Args:
partitions_defs (Sequence[PartitionDimensionDefinition]):
A sequence of PartitionDimensionDefinition objects, each of which contains a dimension
name and a PartitionsDefinition. The total set of partitions will be the cross-product
Expand Down
14 changes: 6 additions & 8 deletions python_modules/dagster/dagster/_core/definitions/run_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SkipReason(NamedTuple("_SkipReason", [("skip_message", PublicAttr[Optional
"""Represents a skipped evaluation, where no runs are requested. May contain a message to indicate
why no runs were requested.
Attributes:
Args:
skip_message (Optional[str]): A message displayed in the Dagster UI for why this evaluation resulted
in no requested runs.
"""
Expand Down Expand Up @@ -112,7 +112,7 @@ class RunRequest(
"""Represents all the information required to launch a single run. Must be returned by a
SensorDefinition or ScheduleDefinition's evaluation function for a run to be launched.
Attributes:
Args:
run_key (Optional[str]): A string key to identify this launched run. For sensors, ensures that
only one run is created per run key across all sensor evaluations. For schedules,
ensures that one run is created per tick, across failure recoveries. Passing in a `None`
Expand Down Expand Up @@ -321,7 +321,7 @@ class DagsterRunReaction(
"""Represents a request that reacts to an existing dagster run. If success, it will report logs
back to the run.
Attributes:
Args:
dagster_run (Optional[DagsterRun]): The dagster run that originates this reaction.
error (Optional[SerializableErrorInfo]): user code execution error.
run_status: (Optional[DagsterRunStatus]): The run status that triggered the reaction.
Expand Down Expand Up @@ -359,14 +359,12 @@ class SensorResult(
):
"""The result of a sensor evaluation.
Attributes:
run_requests (Optional[Sequence[RunRequest]]): A list
of run requests to be executed.
Args:
run_requests (Optional[Sequence[RunRequest]]): A list of run requests to be executed.
skip_reason (Optional[SkipReason]): A skip message indicating why sensor evaluation was skipped.
cursor (Optional[str]): The cursor value for this sensor, which will be provided on the
context for the next sensor evaluation.
dynamic_partitions_requests (Optional[Sequence[Union[DeleteDynamicPartitionsRequest,
AddDynamicPartitionsRequest]]]): A list of dynamic partition requests to request dynamic
dynamic_partitions_requests (Optional[Sequence[Union[DeleteDynamicPartitionsRequest, AddDynamicPartitionsRequest]]]): A list of dynamic partition requests to request dynamic
partition addition and deletion. Run requests will be evaluated using the state of the
partitions with these changes applied.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __exit__(self, *exc) -> None:
class RunFailureSensorContext(RunStatusSensorContext):
"""The ``context`` object available to a decorated function of ``run_failure_sensor``.
Attributes:
Args:
sensor_name (str): the name of the sensor.
dagster_run (DagsterRun): the failed run.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SensorEvaluationContext:
`SensorEvaluationContext` for testing purposes, use :py:func:`dagster.
build_sensor_context`.
Attributes:
Args:
instance_ref (Optional[InstanceRef]): The serialized instance configured to run the schedule
cursor (Optional[str]): The cursor, passed back from the last sensor evaluation via
the cursor attribute of SkipReason and RunRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
class SourceAsset(ResourceAddable):
"""A SourceAsset represents an asset that will be loaded by (but not updated by) Dagster.
Attributes:
Args:
key (Union[AssetKey, Sequence[str], str]): The key of the asset.
metadata (Mapping[str, MetadataValue]): Metadata associated with the asset.
io_manager_key (Optional[str]): The key for the IOManager that will be used to load the contents of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TimeWindowPartitionMapping(
the upstream is hourly, then each daily partition in the downstream asset will map to the 24
hourly partitions in the upstream that occur on that day.
Attributes:
Args:
start_offset (int): If not 0, then the starts of the upstream windows are shifted by this
offset relative to the starts of the downstream windows. For example, if start_offset=-1
and end_offset=0, then the downstream partition "2022-07-04" would map to the upstream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class TimeWindow(NamedTuple):
"""An interval that is closed at the start and open at the end.
Attributes:
Args:
start (datetime): A pendulum datetime that marks the start of the window.
end (datetime): A pendulum datetime that marks the end of the window.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class OpVersionContext(NamedTuple):
"""Provides execution-time information for computing the version for an op.
Attributes:
Args:
op_def (OpDefinition): The definition of the op to compute a version for.
op_config (Any): The parsed config to be passed to the op during execution.
"""
Expand All @@ -25,7 +25,7 @@ class OpVersionContext(NamedTuple):
class ResourceVersionContext(NamedTuple):
"""Provides execution-time information for computing the version for a resource.
Attributes:
Args:
resource_def (ResourceDefinition): The definition of the resource whose version will be computed.
resource_config (Any): The parsed config to be passed to the resource during execution.
"""
Expand Down
2 changes: 1 addition & 1 deletion python_modules/dagster/dagster/_core/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class DagsterEvent(
Users should not instantiate this class.
Attributes:
Args:
event_type_value (str): Value for a DagsterEventType.
job_name (str)
node_handle (NodeHandle)
Expand Down
2 changes: 1 addition & 1 deletion python_modules/dagster/dagster/_core/executor/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InitExecutorContext(
):
"""Executor-specific initialization context.
Attributes:
Args:
job (IJob): The job to be executed.
executor_def (ExecutorDefinition): The definition of the executor currently being
constructed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OpSelectionData(
):
"""The data about op selection.
Attributes:
Args:
op_selection (List[str]): The queries of op selection.
resolved_op_selection (AbstractSet[str]): The names of selected ops.
parent_job_def (JobDefinition): The definition of the full job. This is used for constructing
Expand Down Expand Up @@ -90,7 +90,7 @@ class AssetSelectionData(
):
"""The data about asset selection.
Attributes:
Args:
asset_selection (FrozenSet[AssetKey]): The set of assets to be materialized within the job.
parent_job_def (JobDefinition): The definition of the full job. This is used for constructing
pipeline snapshot lineage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class AirbyteConnectionMetadata(
):
"""Contains information about an Airbyte connection.
Attributes:
Args:
name (str): The name of the connection.
stream_prefix (str): A prefix to add to all stream names.
has_basic_normalization (bool): Whether or not the connection has basic normalization enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AirbyteOutput(
):
"""Contains recorded information about the state of a Airbyte connection job after a sync completes.
Attributes:
Args:
job_details (Dict[str, Any]):
The raw Airbyte API response containing the details of the initiated job. For info
on the schema of this dictionary, see: https://airbyte-public-api-docs.s3.us-east-2.amazonaws.com/rapidoc-api-docs.html#post-/v1/jobs/get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CensusOutput(
):
"""Contains recorded information about the state of a Census sync after a sync completes.
Attributes:
Args:
sync_run (Dict[str, Any]):
The details of the specific sync run.
source (Dict[str, Any]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def wait_for_run_to_complete(
class DatabricksJobRunner:
"""Submits jobs created using Dagster config to Databricks, and monitors their progress.
Attributes:
Args:
host (str): Databricks host, e.g. https://uksouth.azuredatabricks.net
token (str): Databricks token
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DbtCloudOutput(DbtOutput):
Note that users should not construct instances of this class directly. This class is intended
to be constructed from the JSON output of dbt Cloud commands.
Attributes:
Args:
run_details (Dict[str, Any]): The raw dictionary data representing the run details returned
by the dbt Cloud API. For more info, see: https://docs.getdbt.com/dbt-cloud/api-v2#operation/getRunById
result (Dict[str, Any]): Dictionary containing dbt-reported result information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _raise_on_error(self) -> None:
class DbtCliResource(ConfigurableResource):
"""A resource used to execute dbt CLI commands.
Attributes:
Args:
project_dir (str): The path to the dbt project directory. This directory should contain a
`dbt_project.yml`. See https://docs.getdbt.com/reference/dbt_project.yml for more
information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DbtCliOutput(DbtOutput):
Note that users should not construct instances of this class directly. This class is intended
to be constructed from the JSON output of dbt commands.
Attributes:
Args:
command (str): The full shell command that was executed.
return_code (int): The return code of the dbt CLI process.
raw_output (str): The raw output (``stdout``) of the dbt CLI process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_group_name(cls, dbt_resource_props: Mapping[str, Any]) -> Optional[str]:
class KeyPrefixDagsterDbtTranslator(DagsterDbtTranslator):
"""A DagsterDbtTranslator that applies prefixes to the asset keys generated from dbt resources.
Attributes:
Args:
asset_key_prefix (Optional[Union[str, Sequence[str]]]): A prefix to apply to all dbt models,
seeds, snapshots, etc. This will *not* apply to dbt sources.
source_asset_key_prefix (Optional[Union[str, Sequence[str]]]): A prefix to apply to all dbt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FivetranOutput(
):
"""Contains recorded information about the state of a Fivetran connector after a sync completes.
Attributes:
Args:
connector_details (Dict[str, Any]):
The raw Fivetran API response containing the details of the sync'd connector. For info
on the schema of this dictionary, see: https://fivetran.com/docs/rest-api/connectors#retrieveconnectordetails
Expand Down

0 comments on commit a46f596

Please sign in to comment.