pydantic-pycharm-plugin
pydantic-pycharm-plugin copied to clipboard
Optional Field wrongly report 'Parameter x unfilled'
To Reproduce
class Test(BaseModel):
name: Optional[str] = Field()
def test_model() -> None:
a = Test()
print(a.name) # output None
Expected behavior No warning
Screenshots

Environments:
- IDE: PyCharm 2022.1 (Professional Edition)
- OS: Ubuntu 21.10
- Pydantic Version: 1.9.0
- Plugin version: 0.3.12
I'm also getting this issue, using python 3.10:

Any ideas on this false positive? Seems like it affects multiple python versions
I am also having the same issue on a "related" use-case, not exactly the same as above. In my case I am using metaclass to dynamically change the fields to Optional. When I do this PyCharm reports the same "unfulfilled" argument.
metaclass approach lifted from this SO: https://stackoverflow.com/questions/67699451/make-every-fields-as-optional-with-pydantic
class MetaMeasurement(pydantic.main.ModelMetaclass):
def __new__(mcs, name, bases, namespaces, **kwargs):
annotations = namespaces.get("__annotations__", {})
for base in bases:
annotations.update(base.__annotations__)
for field in annotations:
if not field.startswith("__"):
annotations[field] = Optional[annotations[field]]
namespaces["__annotations__"] = annotations
return super().__new__(mcs, name, bases, namespaces, **kwargs)
If this is not the same issue to report here, I could create a new issue specifically for the metaclass case. Please let me know and I'll proceed accordingly.
Thank you so much for your time and efforts working on this plugin - it is really amazing! :heart_eyes: :heart_eyes: :heart_eyes:
@Andrioden @josecsotomorales I'm sorry for my too-late reply. The fixed version has been released. Thank you very much.
@jeremyschulman I'm sorry for my too-late reply. Could you please open another issue for your problem? I will fix it.
Tested it now, works, thanks! Closing.
thanks for the fix @koxudaxi! 🚀