Skip to content

Add docstrings to public APIs in dictknife.loading and submodules - #213

Merged
podhmo merged 6 commits into
masterfrom
add-docstrings-to-loading-api
Jul 5, 2025
Merged

Add docstrings to public APIs in dictknife.loading and submodules#213
podhmo merged 6 commits into
masterfrom
add-docstrings-to-loading-api

Conversation

@podhmo

@podhmo podhmo commented Jul 4, 2025

Copy link
Copy Markdown
Owner

This commit adds comprehensive English docstrings to all public functions and classes within the src/dictknife/loading/ directory and its submodules.

Key changes include:

  • Docstrings for Loader, Dumper, Dispatcher classes and their methods in __init__.py.
  • Docstrings for shortcut functions (load, loads, dump, dumps, etc.) in __init__.py.
  • Docstrings for load and dump (where applicable) in format-specific modules (json, yaml, toml, csv, tsv, md, raw, env, spreadsheet).
  • Mention of required optional dependencies (e.g., ruamel.yaml for yaml, tomlkit for toml, google-api-python-client for spreadsheet) and how to install them (e.g., pip install dictknife[load]).
  • Clarification of behavior for specific arguments (e.g., sort_keys for TOML, errors for CSV).
  • Improved error handling and robustness in some loaders (e.g., env.py, md.py, csv.py).
  • Type hints were added or refined in several places for clarity.

This commit adds comprehensive English docstrings to all public functions and classes within the `src/dictknife/loading/` directory and its submodules.

Key changes include:
- Docstrings for `Loader`, `Dumper`, `Dispatcher` classes and their methods in `__init__.py`.
- Docstrings for shortcut functions (`load`, `loads`, `dump`, `dumps`, etc.) in `__init__.py`.
- Docstrings for `load` and `dump` (where applicable) in format-specific modules (json, yaml, toml, csv, tsv, md, raw, env, spreadsheet).
- Mention of required optional dependencies (e.g., `ruamel.yaml` for yaml, `tomlkit` for toml, `google-api-python-client` for spreadsheet) and how to install them (e.g., `pip install dictknife[load]`).
- Clarification of behavior for specific arguments (e.g., `sort_keys` for TOML, `errors` for CSV).
- Improved error handling and robustness in some loaders (e.g., `env.py`, `md.py`, `csv.py`).
- Type hints were added or refined in several places for clarity.
…rings

This commit refactors the docstrings related to optional dependencies.

- Detailed information about optional dependencies and their installation
  (e.g., using `pip install dictknife[extra]`) is now primarily
  located in the `Loader` and `Dumper` class docstrings in
  `src/dictknife/loading/__init__.py`.
- Docstrings in format-specific modules (yaml, toml, spreadsheet) and
  for shortcut functions (`loadfile`, `dumpfile` in `__init__.py`)
  have been simplified. They now only mention the direct package
  dependency (e.g., "requires `ruamel.yaml`") and refer to the
  `Loader`/`Dumper` class docstrings or project documentation for
  more detailed installation instructions.

This approach reduces redundancy and centralizes the information about
optional dependencies, making it easier for users to understand the
requirements for different file formats.
This commit further refines the documentation of optional dependencies:

- Information about optional dependencies (e.g., for YAML, TOML, Spreadsheets)
  and their installation (e.g., `pip install dictknife[extra]`) is primarily
  consolidated within the `Loader` and `Dumper` class docstrings in
  `src/dictknife/loading/__init__.py`.
- Docstrings in format-specific submodules (`yaml.py`, `toml.py`, `spreadsheet.py`)
  now omit direct mentions of required packages (e.g., "requires `ruamel.yaml`").
  Users should rely on import statements or the centralized `Loader`/`Dumper`
  documentation for such details.
- Shortcut functions `loadfile` and `dumpfile` in `__init__.py` have their
  docstrings updated to clearly direct users to the `Loader`/`Dumper` class
  docstrings or the project's main documentation for information on optional
  dependencies.

This approach centralizes dependency information, reduces redundancy, and clarifies
that submodules focus on API usage rather than repeating installation details better
covered by `pyproject.toml` and centralized documentation.
This commit includes two main changes:

1.  Refactor docstrings for optional dependencies:
    *   Information about optional dependencies (e.g., for YAML, TOML,
        Spreadsheets) and their installation (e.g., `pip install dictknife[extra]`)
        is now primarily consolidated within the `Loader` and `Dumper` class
        docstrings in `src/dictknife/loading/__init__.py`.
    *   Docstrings in format-specific submodules (`yaml.py`, `toml.py`,
        `spreadsheet.py`) now omit direct mentions of required packages.
    *   Shortcut functions `loadfile` and `dumpfile` in `__init__.py` have their
        docstrings updated to clearly direct users to the `Loader`/`Dumper` class
        docstrings or the project's main documentation for information on optional
        dependencies.

2.  Fix Markdown dump behavior in `src/dictknife/loading/md.py`:
    *   Ensures that `None` values in the input data are rendered as the string
        specified by the `null_value` parameter (defaults to "null").
    *   Ensures that empty string `""` values in the input data are rendered as
        empty strings (empty cells) in the Markdown table.
    *   This change addresses a test failure where the Markdown output for `None`
        and empty strings was inconsistent with previous behavior or expectations.
This commit includes two main sets of changes:

1.  Refactor docstrings for optional dependencies:
    *   Information about optional dependencies (e.g., for YAML, TOML,
        Spreadsheets) and their installation (e.g., `pip install dictknife[extra]`)
        is now primarily consolidated within the `Loader` and `Dumper` class
        docstrings in `src/dictknife/loading/__init__.py`.
    *   Docstrings in format-specific submodules (`yaml.py`, `toml.py`,
        `spreadsheet.py`) now omit direct mentions of required packages.
        Users should rely on import statements or the centralized `Loader`/`Dumper`
        documentation for such details.
    *   Shortcut functions `loadfile` and `dumpfile` in `__init__.py` have their
        docstrings updated to clearly direct users to the `Loader`/`Dumper` class
        docstrings or the project's main documentation for information on optional
        dependencies.

2.  Fix Markdown dump behavior in `src/dictknife/loading/md.py`:
    *   Ensures that if a key is not present in a row, it's rendered as an
        empty cell (`""`).
    *   If a key is present and its value is `None`, it's rendered as the string
        specified by the `null_value` parameter (defaults to "null").
    *   If a key is present and its value is an empty string `""`, it's rendered
        as an empty cell (`""`).
    *   Other values are rendered as their string representation.
    *   This addresses a test failure and aligns the output with the expected
        behavior for different types of missing/empty data.
This commit includes three main sets of changes:

1.  Refactor docstrings for optional dependencies:
    *   Information about optional dependencies (e.g., for YAML, TOML,
        Spreadsheets) and their installation (e.g., `pip install dictknife[extra]`)
        is now primarily consolidated within the `Loader` and `Dumper` class
        docstrings in `src/dictknife/loading/__init__.py`.
    *   Docstrings in format-specific submodules (`yaml.py`, `toml.py`,
        `spreadsheet.py`) now omit direct mentions of required packages.
    *   Shortcut functions `loadfile` and `dumpfile` in `__init__.py` have their
        docstrings updated to clearly direct users to the `Loader`/`Dumper` class
        docstrings or the project's main documentation for information on optional
        dependencies.

2.  Fix Markdown dump behavior in `src/dictknife/loading/md.py`:
    *   Ensures that if a key is not present in a row, it's rendered as an
        empty cell (`""`).
    *   If a key is present and its value is `None`, it's rendered as the string
        specified by the `null_value` parameter (defaults to "null").
    *   If a key is present and its value is an empty string `""`, it's rendered
        as an empty cell (`""`).
    *   Other values are rendered as their string representation.

3.  Apply code formatting using `black`.
    *   Relevant source files in `src/dictknife/loading/` were reformatted.
@podhmo

podhmo commented Jul 5, 2025

Copy link
Copy Markdown
Owner Author

@podhmo
podhmo merged commit d3a6818 into master Jul 5, 2025
4 checks passed
@podhmo
podhmo deleted the add-docstrings-to-loading-api branch July 5, 2025 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant