elastic / elasticsearch-dsl-py

High level Python client for Elasticsearch
http://elasticsearch-dsl.readthedocs.org
Apache License 2.0
3.84k stars 801 forks source link

Typehints not working as expected from documentation #1933

Closed t-kuijs closed 1 month ago

t-kuijs commented 1 month ago

Hello, When defining a document using typehints, the way it should working according to the documentation is not working. I have a document in which i have a field org_type, when defining it as follows it works

org_type = Keyword(required=True)

But when adding typehints, it will no longer be added to my index parameters in Elastic (using the document.Init() method). I have tried several options including the following

org_type: str
org_type: M[str]
org_type: str = mapepd_field(Keyword(required=True))
org_type: M[str] = mapped_field(Keyword(required=True))

This is exactly how the documentation suggests to add typehints according to this page https://elasticsearch-dsl.readthedocs.io/en/latest/persistence.html#python-type-hints

Adding typehint only will work, but now MyPy is complaining about incompatible types

org_type: str = Keyword(required=True)

I am using the latest version (8.15.4) at the moment of writing in combination with python version 3.11.9.

t-kuijs commented 1 month ago

Looks like it was something on my side that was wrong. Spend a day looking at it while being a small mistake from my side... Closing the issue now