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

Add lenient_issubclass and lenient_isinstance to DEPRECATED_MOVED_IN_V2 #5916

Merged
merged 1 commit into from
May 29, 2023

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented May 29, 2023

This PR moves lenient_is* functions from "removed" to "deprecated" on the migration module.

Packages like FastAPI depends on those methods (actually only the lenient_issubclass), see:

❯ grep -r 'lenient_'                          
./fastapi/dependencies/utils.py:from pydantic.utils import lenient_issubclass
./fastapi/dependencies/utils.py:        and not lenient_issubclass(field.type_, BaseModel)
./fastapi/dependencies/utils.py:        and not lenient_issubclass(field.type_, sequence_types + (dict,))
./fastapi/dependencies/utils.py:    if (field.shape in sequence_shapes) and not lenient_issubclass(
./fastapi/dependencies/utils.py:    if lenient_issubclass(field.type_, sequence_types):
./fastapi/dependencies/utils.py:    if lenient_issubclass(type_annotation, Request):
./fastapi/dependencies/utils.py:    elif lenient_issubclass(type_annotation, WebSocket):
./fastapi/dependencies/utils.py:    elif lenient_issubclass(type_annotation, HTTPConnection):
./fastapi/dependencies/utils.py:    elif lenient_issubclass(type_annotation, Response):
./fastapi/dependencies/utils.py:    elif lenient_issubclass(type_annotation, BackgroundTasks):
./fastapi/dependencies/utils.py:    elif lenient_issubclass(type_annotation, SecurityScopes):
./fastapi/dependencies/utils.py:    if lenient_issubclass(
./fastapi/dependencies/utils.py:            if lenient_issubclass(field.type_, UploadFile):
./fastapi/dependencies/utils.py:                and lenient_issubclass(field.type_, bytes)
./fastapi/dependencies/utils.py:                and lenient_issubclass(field.type_, bytes)
./fastapi/openapi/utils.py:from pydantic.utils import lenient_issubclass
./fastapi/openapi/utils.py:                if lenient_issubclass(current_response_class, JSONResponse):
./fastapi/utils.py:from pydantic.utils import lenient_issubclass
./fastapi/utils.py:    if lenient_issubclass(original_type, BaseModel):
./fastapi/routing.py:from pydantic.utils import lenient_issubclass
./fastapi/routing.py:            if lenient_issubclass(return_annotation, Response):

Questions

  • Should I move lenient_isinstance to the deprecated subpackge?

@Kludex Kludex requested a review from hramezani May 29, 2023 09:16
@Kludex Kludex merged commit 5faa820 into main May 29, 2023
53 checks passed
@Kludex Kludex deleted the migrate-lenient-functions branch May 29, 2023 09:52
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

Also, we should probably so a few more:

image

(From searching sourcegraph for context:global from\ pydantic\.utils\ import\ (?:(\w+),? *)+)

Comment on lines +25 to +26
'pydantic.utils:lenient_isinstance': 'pydantic._internal._utils:lenient_isinstance',
'pydantic.utils:lenient_issubclass': 'pydantic._internal._utils:lenient_issubclass',
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to import from pydantic.v1.utils, then remove them from pydantic._internal._utils?

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.

None yet

3 participants