-
-
Notifications
You must be signed in to change notification settings - Fork 61
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 explicit type hint to BaseSettings.model_config
#97
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #97 +/- ##
=======================================
Coverage 97.42% 97.42%
=======================================
Files 5 5
Lines 311 311
Branches 68 68
=======================================
Hits 303 303
Misses 6 6
Partials 2 2
☔ View full report in Codecov by Sentry. |
I think the if typing.TYPE_CHECKING:
# Here we provide annotations for the attributes of BaseModel.
# Many of these are populated by the metaclass, which is why this section is in a `TYPE_CHECKING` block.
# However, for the sake of easy review, we have included type annotations of all class and instance attributes
# of `BaseModel` here:
# Class attributes
model_config: ClassVar[ConfigDict] And later on: __slots__ = '__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__'
model_config = ConfigDict()
__pydantic_complete__ = False
__pydantic_root_model__ = False Would it be safe to remove the first one in the |
Thanks @Viicos for this patch. Yeah, seems the mypy error will be fixed by the change you mentioned on You have to create a PR on pydantic and suggest the change. We(other people on the team and I) will review the PR. they may have different opinions on that. |
I noticed the lint is using pydantic 2.0b3 and since beta 3 we had pydantic/pydantic#6260 which added the type annotation to Perhaps there is no change needed in pydantic and the mypy issue will be resolved by updating the linting requirements to 2.0? We could merge #99 and then rebase this PR to confirm. |
@davidhewitt Good catch, I will rebase once #99 gets merged. It seems to work with a MRE: https://mypy-play.net/?mypy=latest&python=3.11&gist=ba7caebef09f0b3aa5397d05dfef4541 (the error appears if you remove the |
Rebasing fixed it. Please review |
Thanks @Viicos |
Noticed this small issue when working inside
settings_customise_sources
. Before this PR (by using eithercls
orsettings_cls
):After:
What's weird is that my IDE seems to infer the type correctly in other places, even without this improvement:
By the way, is the
settings_cls
argument necessary, assettings_customise_sources
is already a class method and we have access tocls
?Selected Reviewer: @dmontagu