Skip to content

Inconsistent usage of warnings #2354

@stefan6419846

Description

@stefan6419846

warnings.warn is currently not being used in a consistent manner:

  • There is pypdf._utils.deprecate and pypdf._utils.deprecation, but some places use plain warnings.warn with the DeprecationWarning category.
    • pypdf/pypdf/_writer.py

      Lines 274 to 278 in 908797f

      warnings.warn(
      "The parameter 'ido' is depreciated and will be removed in "
      "pypdf 4.0.0.",
      DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 1286 to 1290 in 908797f

      warnings.warn(
      "Please use 'user_password' instead of 'user_pwd'. "
      "The 'user_pwd' argument is deprecated and "
      "will be removed in pypdf 4.0.0."
      )
    • pypdf/pypdf/_writer.py

      Lines 1305 to 1311 in 908797f

      warnings.warn(
      message=(
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf 4.0.0. Use {new_term} instead"
      ),
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 1745 to 1751 in 908797f

      warnings.warn(
      message=(
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf 4.0.0. Use {new_term} instead"
      ),
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 2038 to 2044 in 908797f

      warnings.warn(
      message=(
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf 4.0.0. Use {new_term} instead"
      ),
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 2083 to 2089 in 908797f

      warnings.warn(
      message=(
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf 4.0.0. Use {new_term} instead"
      ),
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 2321 to 2325 in 908797f

      warnings.warn(
      "The 'ignore_byte_string_object' argument of remove_images is "
      "deprecated and will be removed in pypdf 4.0.0.",
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 2363 to 2367 in 908797f

      warnings.warn(
      "The 'ignore_byte_string_object' argument of remove_images is "
      "deprecated and will be removed in pypdf 4.0.0.",
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_writer.py

      Lines 2405 to 2409 in 908797f

      warnings.warn(
      "The 'pagenum' argument of add_uri is deprecated and will be "
      "removed in pypdf 4.0.0. Use 'page_number' instead.",
      category=DeprecationWarning,
      )
    • pypdf/pypdf/_page.py

      Lines 361 to 367 in 908797f

      warnings.warn(
      (
      "indirect_ref is deprecated and will be removed in "
      "pypdf 4.0.0. Use indirect_reference instead of indirect_ref."
      ),
      DeprecationWarning,
      )
    • pypdf/pypdf/_page.py

      Lines 375 to 381 in 908797f

      warnings.warn(
      (
      "indirect_ref is deprecated and will be removed in pypdf 4.0.0"
      "Use indirect_reference instead of indirect_ref."
      ),
      DeprecationWarning,
      )
    • pypdf/pypdf/_page.py

      Lines 2281 to 2284 in 908797f

      warnings.warn(
      "parameters Tj_Sep, TJ_sep depreciated, and will be removed in pypdf 4.0.0.",
      DeprecationWarning,
      )
    • pypdf/pypdf/_merger.py

      Lines 163 to 169 in 908797f

      warnings.warn(
      (
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf=4.0.0. Use {new_term} instead"
      ),
      DeprecationWarning,
      )
    • pypdf/pypdf/_merger.py

      Lines 702 to 708 in 908797f

      warnings.warn(
      (
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf==4.0.0. Use {new_term} instead"
      ),
      DeprecationWarning,
      )
    • pypdf/pypdf/_merger.py

      Lines 809 to 815 in 908797f

      warnings.warn(
      (
      f"{old_term} is deprecated as an argument and will be "
      f"removed in pypdf==4.0.0. Use {new_term} instead"
      ),
      DeprecationWarning,
      )
  • There are some plain warnings.warn with a different category. I am not sure whether they are eligble for converting them to logger_warning instead as there is not much which can be done on the user side anyway (besides submitting a PR to implement it ;)):

I would like to see this harmonized and I am open to submit a corresponding PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-maintenanceAnything that is just internal: Simplifying code, syntax changes, updating docs, speed improvements

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions