-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Mention PyObject (v1) moving to ImportString (v2) in migration doc #6456
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
Conversation
It seems like the equivalent of PyObject from v1 is the ImportString type in v2, but there's no mention of it in the migration docs. There's a "known limitation" note in the ImportString docs, not sure if I should mention it in the migration doc. BTW the doc also states: > This is actively being worked on. can this be tracked somewhere? Also, not sure if I should update `pydantic/_migration.py` too 🤔.
|
I think there are enough differences in the two types that I'm not sure it makes sense to document it as a pure move, but I do think it's worth adding a note to the migration docs about it. I pushed this change to this PR, if you disagree with it we can revert, otherwise I'm happy to merge this. |
|
Do I need to add in bump-pydantic? |
|
@dmontagu thanks, but wouldn't it make sense to still have the row in "Moved in Pydantic V2" table, but this time link to the note you added in the same migration doc? |
Interesting. Apart from the default value limitation, what else do you see as different between the two? |
|
Either way, I'm fine with the current version of this PR 👍. |
@Kludex that would be nice, but IMHO when there was a default value for |
|
Okay, actually, it's more similar than I thought (I thought it would require the input to validation be a string, but it doesn't). There are a handful of improvements, which isn't the case for most of the other things in those tables, but I don't necessarily think that means it shouldn't be included in the table. For example:
from pydantic import BaseModel, ImportString
class A(BaseModel):
x: ImportString[type[int]]
A(x='math.cos')
"""
pydantic_core._pydantic_core.ValidationError: 1 validation error for A
x
Input should be a subclass of int [type=is_subclass_of, input_value=<built-in function cos>, input_type=builtin_function_or_method]
"""The biggest breaking change is that class ImportStringModel(BaseModel):
module: ImportString = 'os.path'
m = ImportStringModel()
assert m.module == os.path # this will fail, as module will be the string literal `'os.path'`I don't know if there is an easy way to fix that though without changes to module = ImportString.import_string('os.path') # equivalent to `module = os.path`But I guess that's orthogonal to this PR. Not quite sure how to proceed, @Kludex thoughts? |
Right, so from the PyObject -> ImportString migration perspective this is still fine, right? In other words you could say there's nothing PyObject could do that ImportString can't (modulo the default value issue).
Right, and this is documented. Hence my
I agree. |
|
Okay, I think it makes sense to undo my docs changes then (which I have done, and restored yours), but I did add a change to @Kludex I think we should therefore address this in bump pydantic. |
|
I'll implement it there. 👍 |
Context
It seems like the equivalent of PyObject from v1
is the ImportString type in v2,
but there's no mention of it in the migration docs.
Change Summary
Add
pydantic.PyObject->pydantic.ImportStringrowin the "Moved in Pydantic V2" table.
Open questions
not sure if I should mention it in the migration doc.
pydantic/_migration.pytoo 🤔.Notes
BTW the doc also states:
can this be tracked somewhere?
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)