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

Introduce docstring standards for Ruff #994

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/create_user_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def get_organization_id(server_config, label):
:param label: A string label that will be used when searching. Every
organization should have a unique label.
:returns: An organization ID. (Typically an integer.)

"""
response = requests.get(
f'{server_config["url"]}/katello/api/v2/organizations',
Expand Down
20 changes: 8 additions & 12 deletions nailgun/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def _content_type_is_json(kwargs):
:param kwargs: A ``dict``. The keyword args supplied to :func:`request` or
one of the convenience functions like it.
:returns: ``True`` or ``False``

"""
if 'headers' in kwargs and 'content-type' in kwargs['headers']:
return kwargs['headers']['content-type'].lower() == 'application/json'
Expand All @@ -75,7 +74,6 @@ def _set_content_type(kwargs):
:param kwargs: A ``dict``. The keyword args supplied to :func:`request` or
one of the convenience functions like it.
:return: Nothing. ``kwargs`` is modified in-place.

"""
if 'files' in kwargs:
return # requests will automatically set the content-type
Expand All @@ -85,7 +83,7 @@ def _set_content_type(kwargs):


def _truncate_data(data, max_len=500):
"""Truncate data to a max length"""
"""Truncate data to a max length."""
if isinstance(data, str | bytes):
if len(data) > max_len:
return f"{data[:max_len - 3]}..."
Expand All @@ -103,7 +101,6 @@ def _log_request(method, url, kwargs, data=None, params=None):
one can pass to ``requests.request``.

:return: Nothing is returned.

"""
logger.debug(
'Making HTTP %s request to %s with %s, %s and %s.',
Expand All @@ -123,7 +120,6 @@ def _log_response(response):
the object returned is logged.

:return: Nothing is returned.

"""
message = f'Received HTTP {response.status_code} response: {response.text}'
if not response.ok:
Expand All @@ -133,7 +129,7 @@ def _log_response(response):


def request(method, url, **kwargs):
"""A wrapper for ``requests.request``."""
"""Wrap ``requests.request``."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and kwargs.get('data') is not None:
kwargs['data'] = dumps(kwargs['data'])
Expand All @@ -144,7 +140,7 @@ def request(method, url, **kwargs):


def head(url, **kwargs):
"""A wrapper for ``requests.head``."""
"""Wrap ``requests.head``."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and kwargs.get('data') is not None:
kwargs['data'] = dumps(kwargs['data'])
Expand All @@ -155,7 +151,7 @@ def head(url, **kwargs):


def get(url, params=None, **kwargs):
"""A wrapper for ``requests.get``."""
"""Wrap ``requests.get``."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and kwargs.get('data') is not None:
kwargs['data'] = dumps(kwargs['data'])
Expand All @@ -166,7 +162,7 @@ def get(url, params=None, **kwargs):


def post(url, data=None, json=None, **kwargs):
"""A wrapper for ``requests.post``."""
"""Wrap ``requests.post``."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and data is not None:
data = dumps(data)
Expand All @@ -177,7 +173,7 @@ def post(url, data=None, json=None, **kwargs):


def put(url, data=None, **kwargs):
"""A wrapper for ``requests.put``. Sends a PUT request."""
"""Wrap ``requests.put``. Sends a PUT request."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and data is not None:
data = dumps(data)
Expand All @@ -188,7 +184,7 @@ def put(url, data=None, **kwargs):


def patch(url, data=None, **kwargs):
"""A wrapper for ``requests.patch``. Sends a PATCH request."""
"""Wrap ``requests.patch``. Sends a PATCH request."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and data is not None:
data = dumps(data)
Expand All @@ -199,7 +195,7 @@ def patch(url, data=None, **kwargs):


def delete(url, **kwargs):
"""A wrapper for ``requests.delete``. Sends a DELETE request."""
"""Wrap ``requests.delete``. Sends a DELETE request."""
_set_content_type(kwargs)
if _content_type_is_json(kwargs) and kwargs.get('data') is not None:
kwargs['data'] = dumps(kwargs['data'])
Expand Down
5 changes: 1 addition & 4 deletions nailgun/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ConfigFileError(Exception):
.. WARNING:: This class will likely be moved to a separate Python package
in a future release of NailGun. Be careful about making references to
this class, as those references will likely need to be changed.

"""


Expand All @@ -40,7 +39,6 @@ def _get_config_file_path(xdg_config_dir, xdg_config_file):
:returns: A ``str`` path to a configuration file.
:raises nailgun.config.ConfigFileError: When no configuration file can be
found.

"""
for config_dir in BaseDirectory.load_config_paths(xdg_config_dir):
path = join(config_dir, xdg_config_file)
Expand Down Expand Up @@ -91,7 +89,6 @@ class BaseServerConfig:
.. WARNING:: This class will likely be moved to a separate Python package
in a future release of NailGun. Be careful about making references to
this class, as those references will likely need to be changed.

"""

# Used to lock access to the configuration file when performing certain
Expand All @@ -110,6 +107,7 @@ def __init__(self, url, auth=None, version=None):
self.version = parse(version)

def __repr__(self):
"""Return a string representation of the object."""
attrs = vars(self).copy()
if "version" in attrs:
attrs["version"] = str(attrs.pop("version"))
Expand Down Expand Up @@ -228,7 +226,6 @@ class ServerConfig(BaseServerConfig):

:param verify: A boolean. Should SSL be verified when communicating with
the server? No instance attribute is created if no value is provided.

"""

# It's OK that this class has only one public method. This class is
Expand Down
Loading
Loading