sloria / environs

simplified environment variable parsing
MIT License
1.21k stars 85 forks source link

Incomplete Typing on Env methods #330

Closed aThorp96 closed 9 months ago

aThorp96 commented 9 months ago

Hello! I'm having an issue using this library with in a project with strict typing using pyright. The issue I'm experiencing is that _field2method returns a typing.Callable, but the args and return of the typing.Callable is undefined, leading to Pyright identifying that the return type, and therefore Env().list, Env().bool, etc, having the type(...) -> Unknown. I recognize that this isn't an easy problem to solve, but I wanted to flag the error and mention that it may be incorrect to include py.typed

It's incomplete because it doesn't support imports such as marshmallow, but the issue can be seen on line 367 in the code in the Pyright AST viewer

sloria commented 9 months ago

this is a known issue, and there was some investigation in https://github.com/sloria/environs/issues/120 . ultimately, we didn't arrive on good solution there. still open to ideas if we can preserve both conciseness and type correctness, but it turns out to be less straightforward than you think.

closing this for now; any further discussion should happen on #120