HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.79k stars 192 forks source link

Pyright reportGeneralTypeIssues error with cast #140

Closed badrbouslikhin closed 1 year ago

badrbouslikhin commented 2 years ago

Hello,

I am trying to use cast to parse a parameter and use it as an argument for a function that uses type hints.

controller = Controller(
    config("MAX_ALLOWED_POWER", cast=int),
)
class Controller:
    def __init__(
        self,
        max_allowed_power: int,

    ):
        self._max_allowed_power = max_allowed_power

But the LSP returns the following error:

Pyright: Argument of type "str | Unknown | bool" cannot be assigned to parameter "max_allowed_power" of type "int" in function "__init__" 
Type "str | Unknown | bool" cannot be assigned to type "int"
str" is incompatible with "int" [reportGeneralTypeIssues] 

Am I doing something wrong? Thanks!

henriquebastos commented 1 year ago

You can't tell what type config will return, because it depends on whatever you pass on cast.