fix(python): only add pydantic-core dependency for explicit v2 mode #11759
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug where
pydantic-corewas unconditionally added as a dependency to all generated Python SDKs, breaking compatibility for users who want to use Pydantic v1.Link to Devin run: https://app.devin.ai/sessions/28614b85508c4423a875ee8848ab1fca
Requested by: @jsklan
Changes Made
pydantic-coreas a dependency when the Pydantic version is explicitly set tov2pydantic-coreis a transitive dependency ofpydantic>=2.0and doesn't need to be explicitly listedpydantic-coredoesn't existpydantic.v1compatibility layerUpdates since last revision
Fixed mypy type-checking errors that occurred because mypy tries to resolve imports at type-checking time even when they're inside runtime conditionals:
# type: ignore[import-not-found]comments to allpydantic_coreimports in the core utilitiesPydanticUndefinedimport inunchecked_base_model.pyconditional with aNonefallback for non-v2 modeTesting
Human Review Checklist
self._versionin SDK vsself._pydantic_compatibilityin others)PydanticUndefined = Nonefallback inunchecked_base_model.pyis safe (it's only used insideif IS_PYDANTIC_V2:blocks)