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

Revert typing.Literal and import it outside the TYPE_CHECKING block #9232

Merged
merged 1 commit into from Apr 14, 2024

Conversation

frost-nzcr4
Copy link
Contributor

@frost-nzcr4 frost-nzcr4 commented Apr 12, 2024

Change Summary

In PR #7680 the typing.Literal was replaced with typing_extensions.Literal. I was curious enough to double-check the origin and found that the error was caused by importing from typing import Literal inside the TYPE_CHECKING block but then using it outside the scope.

I suggest to revert typing.Literal back, but importing it correctly at the module level. This meets the required Python 3.8+ limitation and works well with the example from the original issue:

import typing
from pydantic import BaseModel
typing.get_type_hints(BaseModel.model_copy)
typing.get_type_hints(BaseModel.model_dump)
typing.get_type_hints(BaseModel.dict)

Related issue number

refs #7623

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @dmontagu

@frost-nzcr4
Copy link
Contributor Author

please review

Copy link

codspeed-hq bot commented Apr 12, 2024

CodSpeed Performance Report

Merging #9232 will not alter performance

Comparing frost-nzcr4:7623-use-stdlib-literal (3dadce2) with main (6aab43e)

Summary

✅ 13 untouched benchmarks

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Apr 14, 2024
@sydney-runkle
Copy link
Member

Looks great, thanks!

@sydney-runkle sydney-runkle enabled auto-merge (squash) April 14, 2024 01:36
@sydney-runkle sydney-runkle merged commit 628f36b into pydantic:main Apr 14, 2024
52 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants