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
Enhancing editor completion for BaseModel.__init__ #3475
Comments
This would be wonderful, dataclasses do this and it's incredibly helpful |
Do you have a working PoC? I don't think the approach you're going with will work. Correct me if I'm wrong, but IDE has no idea what Also, this issue is addressed in #2698 and implemented in #2721, so I would propose closing #3263 and this issye and continue discussion in #2698 for better visibility. @shughes-uk, dataclasses don't do any of this. IDEs just have a custom behaviour defined to support them since they're included the the standard library. |
Dangit I had hoped that wasn't the case but had my suspicions 😭 , glad to see that support will exist in the next release though |
@Bobronium By the way, In particular, I'm using But I think there may be something wrong in what I am saying. |
Wow, if it does really work, authors of However, I still can't wrap my head around how it could be implemented. Are you sure it picks up An easy check would be look like following (unfortunately don't use VSCode/pylance/pyright to test this): from pydantic.main import BaseModel, ModelMetaclass
class AutocompleteMetaclass(ModelMetaclass):
def __new__(*args, **kwargs):
cls = super().__new__(*args, **kwargs)
cls.__init__.__annotations__ = {'foo': int}
return cls
class FancyAutocompleteModel(BaseModel, metaclass=AutocompleteMetaclass)
...
class Foo(FancyAutocompleteModel):
bar: int
Foo() # here you should have (bar: int) signature, if it really picks up annotations defined in metaclass Also, keep in mind, that setting |
Any update here? |
#2721 is released with v1.9, I therefore think this is fixed. |
Discussed in #3263
Originally posted by elda27 September 26, 2021
Currently,
BaseModel.__init__
takes**data
as an argument.I would like to set
__annotations__
for editor complementions.I seem that
BaseModel.__init__.__annotations__
can be set inModelMetaclass
.Is this change acceptable?
If it acceptable, I would like to contribute.
I posted three months ago.
Arguments of
__init__
doesn't work code completion on the VSCode now.Current behavior
Expected proposing behavior
I think
__signature__
may work well since Python 3.9.But practical annotation for
__init__
should be__annotaions__
before Python 3.8.I have already implemented this solution three months ago.
So I can contribute the solution.
Please consider my suggestion.
Following code is an example of changes at
ModelMetaclass
for code completion.The text was updated successfully, but these errors were encountered: