BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.02k stars 213 forks source link

[BUG] Pylance: Every `.save()`, `.insert()`, `.update()` operation reports `Argument missing for parameter "self"` #864

Closed TheBloke closed 7 months ago

TheBloke commented 7 months ago

Describe the bug

I use VSCode with Pylance. Every time I use .save(), .insert(), .update() or .save_changes() I get this Pylance error:

Argument missing for parameter "self"

Screenshot, showing the error on three of the mentioned methods: image

To Reproduce

example_doc = SomeDoc(...)
await example_doc.save() # Pylance: `Argument missing for parameter "self"`

This is quite frustrating because I currently have to litter my code with # type: ignore messages, which risks hiding real issues.

Problem source

I've done some digging, and the error on .save(), .update(), .insert() seems to be caused by the call to functools.wraps() :

@wraps(f)

It's this line in beanie/odm/actions.py:wrap_with_actions.

If I comment out that line, the error goes away for .save(), .update(), .insert(). I don't know enough about what this code is doing to know how to fix it, but hopefully this will help identify the root of the issue.

(Note that commenting that one line does not fix .save_update(), so I assume there's also other places where a similar thing is happening)

Expected behavior No typing errors

Additional context

Thanks in advance

TheBloke commented 7 months ago

I just realised this is a duplicate of https://github.com/roman-right/beanie/issues/679