Skip to content

Commit

Permalink
📝(project) unify infinitive use in docstrings
Browse files Browse the repository at this point in the history
In ralph, it has been established that all docstrings shall begin with an
infinitive verb. Some typos remaining are now unified.
  • Loading branch information
quitterie-lcs committed Oct 30, 2023
1 parent 06d2038 commit 7aa8f45
Show file tree
Hide file tree
Showing 37 changed files with 124 additions and 99 deletions.
2 changes: 1 addition & 1 deletion gitlint/gitlint_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GitmojiTitle(LineRule):
target = CommitMessageTitle

def validate(self, title, _commit):
"""Validates Gitmoji title rule.
"""Validate Gitmoji title rule.
Downloads the list possible gitmojis from the project's GitHub
repository and check that title contains one of them.
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/api/auth/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_basic_auth_user(
credentials: Optional[HTTPBasicCredentials] = Depends(security),
security_scopes: SecurityScopes = SecurityScopes([]),
) -> AuthenticatedUser:
"""Checks valid auth parameters.
"""Check valid auth parameters.
Get the basic auth parameters from the Authorization header, and checks them
against our own list of hashed credentials.
Expand Down
4 changes: 2 additions & 2 deletions src/ralph/api/routers/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
async def lbheartbeat() -> None:
"""Load balancer heartbeat.
Returns a 200 when the server is running.
Return a 200 when the server is running.
"""
return

Expand All @@ -34,7 +34,7 @@ async def lbheartbeat() -> None:
async def heartbeat() -> JSONResponse:
"""Application heartbeat.
Returns a 200 if all checks are successful.
Return a 200 if all checks are successful.
"""
content = {"database": (await await_if_coroutine(BACKEND_CLIENT.status())).value}
status_code = (
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/api/routers/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,5 +588,5 @@ async def post(

logger.info("Indexed %d statements with success", success_count)

# Returns the list of IDs in the same order they were stored
# Return the list of IDs in the same order they were stored
return list(statements_dict)
2 changes: 1 addition & 1 deletion src/ralph/backends/data/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def read(
ignore_errors: bool = False,
) -> Iterator[Union[bytes, dict]]:
# pylint: disable=too-many-arguments
"""Read an object matching the `query` in the `target` bucket and yields it.
"""Read an object matching the `query` in the `target` bucket and yield it.
Args:
query: (str or BaseQuery): The ID of the object to read.
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/backends/data/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def read(
ignore_errors: bool = False,
) -> Iterator[Union[bytes, dict]]:
# pylint: disable=too-many-arguments
"""Read objects matching the `query` in the `target` container and yields them.
"""Read objects matching the `query` in the `target` container and yield them.
Args:
query: (str or BaseQuery): The query to select objects to read.
Expand Down
4 changes: 2 additions & 2 deletions src/ralph/backends/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def append_to_history(self, event):
self.write_history(self.history + [event])

def get_command_history(self, backend_name, command):
"""Extracts entry ids from the history for a given command and backend_name."""
"""Extract entry ids from the history for a given command and backend_name."""

def filter_by_name_and_command(entry):
"""Checks whether the history entry matches the backend_name and command."""
"""Check whether the history entry matches the backend_name and command."""
return entry.get("backend") == backend_name and (
command in [entry.get("command"), entry.get("action")]
)
Expand Down
18 changes: 9 additions & 9 deletions src/ralph/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CommaSeparatedTupleParamType(click.ParamType):
name = "value1,value2,value3"

def convert(self, value, param, ctx):
"""Splits the value by comma to return a tuple of values."""
"""Split the value by comma to return a tuple of values."""
if isinstance(value, str):
return tuple(value.split(","))

Expand All @@ -76,9 +76,9 @@ class CommaSeparatedKeyValueParamType(click.ParamType):
name = "key=value,key=value"

def convert(self, value, param, ctx):
"""Splits the values by comma and equal sign.
"""Split the values by comma and equal sign.
Returns a dictionary build with key/value pairs.
Return a dictionary build with key/value pairs.
"""
if isinstance(value, dict):
return value
Expand Down Expand Up @@ -116,17 +116,17 @@ class ClientOptionsParamType(CommaSeparatedKeyValueParamType):
"""Comma separated key=value parameter type for client options."""

def __init__(self, client_options_type: Any) -> None:
"""Instantiates ClientOptionsParamType for a client_options_type.
"""Instantiate ClientOptionsParamType for a client_options_type.
Args:
client_options_type (any): Pydantic model used for client options.
"""
self.client_options_type = client_options_type

def convert(self, value, param, ctx):
"""Splits the values by comma and equal sign.
"""Split the values by comma and equal sign.
Returns an instance of client_options_type build with key/value pairs.
Return an instance of client_options_type build with key/value pairs.
"""
if isinstance(value, self.client_options_type):
return value
Expand All @@ -138,17 +138,17 @@ class HeadersParametersParamType(CommaSeparatedKeyValueParamType):
"""Comma separated key=value parameter type for headers parameters."""

def __init__(self, headers_parameters_type: Any) -> None:
"""Instantiates HeadersParametersParamType for a headers_parameters_type.
"""Instantiate HeadersParametersParamType for a headers_parameters_type.
Args:
headers_parameters_type (any): Pydantic model used for headers parameters.
"""
self.headers_parameters_type = headers_parameters_type

def convert(self, value, param, ctx):
"""Splits the values by comma and equal sign.
"""Split the values by comma and equal sign.
Returns an instance of headers_parameters_type build with key/value pairs.
Return an instance of headers_parameters_type build with key/value pairs.
"""
if isinstance(value, self.headers_parameters_type):
return value
Expand Down
6 changes: 3 additions & 3 deletions src/ralph/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Config: # pylint: disable=missing-class-docstring # noqa: D106
_class_path: str = None

def get_instance(self, **init_parameters):
"""Returns an instance of the settings item class using its `_class_path`."""
"""Return an instance of the settings item class using its `_class_path`."""
return import_string(self._class_path)(**init_parameters)


Expand Down Expand Up @@ -208,12 +208,12 @@ class AuthBackends(Enum):

@property
def APP_DIR(self) -> Path: # pylint: disable=invalid-name
"""Returns the path to Ralph's configuration directory."""
"""Return the path to Ralph's configuration directory."""
return self._CORE.APP_DIR

@property
def LOCALE_ENCODING(self) -> str: # pylint: disable=invalid-name
"""Returns Ralph's default locale encoding."""
"""Return Ralph's default locale encoding."""
return self._CORE.LOCALE_ENCODING

@root_validator(allow_reuse=True)
Expand Down
6 changes: 3 additions & 3 deletions src/ralph/models/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class BaseConversionSet(ABC):
__dest__: BaseModel

def __init__(self) -> None:
"""Initializes BaseConversionSet."""
"""Initialize BaseConversionSet."""
self._conversion_items = self._get_conversion_items()

@abstractmethod
def _get_conversion_items(self) -> Set[ConversionItem]:
"""Returns a set of ConversionItems used for conversion."""
"""Return a set of ConversionItems used for conversion."""

def __iter__(self) -> Iterator[ConversionItem]: # noqa: D105
return iter(self._conversion_items)
Expand Down Expand Up @@ -172,7 +172,7 @@ def __init__(
module: str = "ralph.models.edx.converters.xapi",
**conversion_set_kwargs: Any,
) -> None:
"""Initializes the Converter."""
"""Initialize the Converter."""
self.model_selector = model_selector
self.src_conversion_set = self.get_src_conversion_set(
import_module(module), **conversion_set_kwargs
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/models/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ModelSelector:
"""

def __init__(self, module: str = "ralph.models.edx") -> None:
"""Instantiates ModelSelector."""
"""Instantiate ModelSelector."""
self.model_rules = ModelSelector.build_model_rules(import_module(module))
self.decision_tree = self.get_decision_tree(self.model_rules)

Expand Down
6 changes: 3 additions & 3 deletions src/ralph/models/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Validator:
"""Events validator using pydantic models."""

def __init__(self, model_selector: ModelSelector):
"""Initializes Validator."""
"""Initialize Validator."""
self.model_selector = model_selector

def validate(
self, input_file: TextIO, ignore_errors: bool, fail_on_unknown: bool
) -> Generator:
"""Validates JSON event strings line by line."""
"""Validate JSON event strings line by line."""
total = 0
success = 0
for event_str in input_file:
Expand All @@ -48,7 +48,7 @@ def validate(
logger.info("Total events: %d, Invalid events: %d", total, total - success)

def get_first_valid_model(self, event: dict) -> Any:
"""Returns the first successfully instantiated model for the event.
"""Return the first successfully instantiated model for the event.
Raises:
UnknownEventException: When the event does not match any model.
Expand Down
4 changes: 2 additions & 2 deletions src/ralph/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GELFParser(BaseParser):
name = "gelf"

def parse(self, input_file: Union[TextIO, BinaryIO]) -> Generator:
"""Parses GELF formatted logs (one JSON string event per row).
"""Parse GELF formatted logs (one JSON string event per row).
Args:
input_file (file-like): The log file to parse.
Expand Down Expand Up @@ -67,7 +67,7 @@ class ElasticSearchParser(BaseParser):
name = "es"

def parse(self, input_file: Union[TextIO, BinaryIO]) -> Generator:
"""Parses Elasticsearch JSON documents.
"""Parse Elasticsearch JSON documents.
Args:
input_file (file-like): The file containing Elasticsearch JSON documents.
Expand Down
2 changes: 1 addition & 1 deletion tests/api/auth/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_get_whoami_wrong_password(basic_auth_test_client, fs):
def test_get_whoami_correct_credentials(basic_auth_test_client, fs):
"""Whoami returns a 200 response when the credentials are correct.
Returns the username and associated scopes.
Return the username and associated scopes.
"""
credential_bytes = base64.b64encode("ralph:admin".encode("utf-8"))
credentials = str(credential_bytes, "utf-8")
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_forwarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def raise_for_status():
raise RequestError("Failure during request.")

async def post_fail(*args, **kwargs): # pylint: disable=unused-argument
"""Returns a MockUnsuccessfulResponse instance."""
"""Return a MockUnsuccessfulResponse instance."""
return MockUnsuccessfulResponse()

monkeypatch.setattr("ralph.api.forwarding.AsyncClient.post", post_fail)
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def test_api_statements_backend_instance_with_runserver_backend_env(monkeypatch):
"""Tests that given the RALPH_RUNSERVER_BACKEND environment variable, the backend
"""Test that given the RALPH_RUNSERVER_BACKEND environment variable, the backend
instance `BACKEND_CLIENT` should be updated accordingly.
"""
# Default backend
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_statements_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def insert_mongo_statements(mongo_client, statements):


def insert_clickhouse_statements(statements):
"""Inserts a bunch of example statements into ClickHouse for testing."""
"""Insert a bunch of example statements into ClickHouse for testing."""
settings = ClickHouseDataBackend.settings_class(
HOST=CLICKHOUSE_TEST_HOST,
PORT=CLICKHOUSE_TEST_PORT,
Expand All @@ -90,7 +90,7 @@ def insert_statements_and_monkeypatch_backend(
# pylint: disable=invalid-name,unused-argument

def _insert_statements_and_monkeypatch_backend(statements):
"""Inserts statements once into each backend."""
"""Insert statements once into each backend."""
backend_client_class_path = "ralph.api.routers.statements.BACKEND_CLIENT"
if request.param == "async_es":
insert_es_statements(es, statements)
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_statements_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ async def test_api_statements_post_with_failure_during_storage(
# pylint: disable=invalid-name,unused-argument,too-many-arguments

async def write_mock(*args, **kwargs):
"""Raises an exception. Mocks the database.write method."""
"""Raise an exception. Mocks the database.write method."""
raise BackendException()

backend_instance = backend()
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_statements_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async def test_api_statements_put_with_failure_during_storage(
# pylint: disable=invalid-name,unused-argument,too-many-arguments

def write_mock(*args, **kwargs):
"""Raises an exception. Mocks the database.write method."""
"""Raise an exception. Mocks the database.write method."""
raise BackendException()

backend_instance = backend()
Expand Down
5 changes: 3 additions & 2 deletions tests/backends/http/test_async_lrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ async def test_backends_http_lrs_write_with_invalid_parameters(
@pytest.mark.anyio
async def test_backends_http_lrs_write_without_target(httpx_mock: HTTPXMock, caplog):
"""Test the LRS backend `write` method without target parameter value writes
statements to '/xAPI/statements' default endpoint."""
statements to '/xAPI/statements' default endpoint.
"""

base_url = "http://fake-lrs.com"

Expand Down Expand Up @@ -872,7 +873,7 @@ async def test_backends_http_lrs_write_backend_exception(
httpx_mock: HTTPXMock,
caplog,
):
"""Test the `LRSHTTP.write` method with HTTP error"""
"""Test the `LRSHTTP.write` method with HTTP error."""
base_url = "http://fake-lrs.com"
target = "/xAPI/statements"

Expand Down
2 changes: 1 addition & 1 deletion tests/backends/lrs/test_async_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ async def mock_read(**_):
async def test_backends_lrs_mongo_lrs_backend_query_statements_by_ids_two_collections(
mongo, mongo_forwarding, async_mongo_lrs_backend
):
"""Tests the `AsyncMongoLRSBackend.query_statements_by_ids` method, given a valid
"""Test the `AsyncMongoLRSBackend.query_statements_by_ids` method, given a valid
search query, should execute the query only on the specified collection and return
the expected results.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/lrs/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def mock_read(**_):
def test_backends_lrs_mongo_lrs_backend_query_statements_by_ids_with_two_collections(
mongo, mongo_forwarding, mongo_lrs_backend
):
"""Tests the `MongoLRSBackend.query_statements_by_ids` method, given a valid search
"""Test the `MongoLRSBackend.query_statements_by_ids` method, given a valid search
query, should execute the query only on the specified collection and return the
expected results.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/stream/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GoodStream(BaseStreamBackend):
name = "good"

def stream(self, target):
"""Fakes the stream method."""
"""Fake the stream method."""

GoodStream()

Expand Down
Loading

0 comments on commit 7aa8f45

Please sign in to comment.