BeanieODM / beanie

Asynchronous Python ODM for MongoDB

Home Page:http://beanie-odm.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

TheBloke opened this issue · comments

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

  • Pylance v2024.2.2, Type Checking Mode: 'basic'
    • Error also happens with the previous Pylance version, v2023.12.1.
  • Python 3.11.7
  • Pydantic 2.6.1
  • Beanie 1.25.0

Thanks in advance

I just realised this is a duplicate of #679