jxnl / instructor

structured outputs for llms
https://python.useinstructor.com/
MIT License
7.7k stars 614 forks source link

type checker cannot see any attributes of retry.py #649

Open kojiromike opened 5 months ago

kojiromike commented 5 months ago

What Model are you using?

Describe the bug The type: ignore[all] comment at the top of retry.py teaches mypy that retry has no attributes at all.

To Reproduce When I write a python module with:

from instructor.retry import reask_messages

and type check it with mypy in an environment with instructor installed, mypy complains:

error: Module "instructor.retry" has no attribute "reask_messages"  [attr-defined]

Expected behavior Since instructor ships with a PEP 561 py.typed file, I expected type checking to be largely correct across the package.

ionflow commented 3 months ago

@kojiromike it's in from instructor.exceptions import InstructorRetryException

kojiromike commented 3 months ago

Aha, thanks! Perhaps this was fixed in #710 three weeks ago and released in 1.3.3 then. I will test.

kojiromike commented 3 months ago

Unfortunately this is not really fixed. mypy still cannot see any attributes of retry.py, because it still has type: ignore[all] at the top. The example case is avoidable now because we can (and should) get the exception class from another module, but from instructor.retry import reask_messages still causes mypy to give an error.

I have edited the example to use reask_messages instead of InstructorRetryException.