Skip to content

Conversation

@zeke
Copy link
Member

@zeke zeke commented Sep 23, 2025

This PR adds backward compatibility for users importing exceptions from replicate.exceptions instead of directly from the replicate module.

Changes

  • Added new src/replicate/exceptions.py module that re-exports all exception classes from the internal _exceptions module
  • Added comprehensive tests to verify the legacy import patterns work correctly
  • Ensures both import patterns work:
    • from replicate import ModelError (existing)
    • from replicate.exceptions import ModelError (legacy compatibility)

This maintains backward compatibility with code that uses the legacy import pattern shown in documentation examples.

Testing locally

gh repo clone replicate/replicate-python-stainless
cd replicate-python-stainless
gh pr checkout 70
scripts/bootstrap
scripts/test

Linear ticket

https://linear.app/replicate/issue/DP-658/add-legacy-exception-compatibility-aliases

Prompts

work on this issue: https://linear.app/replicate/issue/DP-658/add-legacy-exception-compatibility-aliases

@zeke zeke requested a review from a team as a code owner September 23, 2025 15:04
@zeke zeke requested a review from dgellow September 23, 2025 16:14
This adds backward compatibility for users importing exceptions from
`replicate.exceptions` instead of directly from the `replicate` module.

The new `replicate/exceptions.py` module re-exports all exception classes
from the internal `_exceptions` module, allowing both import patterns to work:
- `from replicate import ModelError` (existing)
- `from replicate.exceptions import ModelError` (legacy compatibility)

This ensures backward compatibility with code that uses the legacy import
pattern shown in documentation examples.

Includes comprehensive tests to verify all exception classes are available
through the legacy import path.
@zeke zeke force-pushed the legacy-exception-compatibility-aliases branch from 610353e to 54271d2 Compare September 24, 2025 16:22
Copy link
Collaborator

@dgellow dgellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zeke zeke merged commit 1a66fc8 into main Sep 25, 2025
8 checks passed
@zeke zeke deleted the legacy-exception-compatibility-aliases branch September 25, 2025 16:28
@stainless-app stainless-app bot mentioned this pull request Sep 25, 2025
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.

3 participants