lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
384 stars 46 forks source link

pyre error: Incompatible parameter type [6]: In call `simple_parsing.parsing.parse`, for 1st positional argument, expected `Type[Variable[DataclassT (bound to Dataclass)]]` but got `Type[Opts]` #268

Closed alexanderlobov closed 10 months ago

alexanderlobov commented 1 year ago

Describe the bug

pyre check
ƛ Found 1 type error!
src/test.py:9:21 Incompatible parameter type [6]: In call `simple_parsing.parsing.parse`, for 1st positional argument, expected `Type[Variable[DataclassT (bound to Dataclass)]]` but got `Type[Opts]`.

To Reproduce

from dataclasses import dataclass
import simple_parsing

@dataclass
class Opts:
    foo: int

simple_parsing.parse(Opts)
pyre init
pyre check

Expected behavior No errors are expected from pyre.

Actual behavior

pyre check
ƛ Found 1 type error!
src/test.py:9:21 Incompatible parameter type [6]: In call `simple_parsing.parsing.parse`, for 1st positional argument, expected `Type[Variable[DataclassT (bound to Dataclass)]]` but got `Type[Opts]`.

Desktop (please complete the following information):

pyre --version
Binary version: d5ff1b0a39e2b09e3873a3131373a7f466c77d5d
Client version: 0.9.18

pip list | grep simple
simple-parsing    0.1.3

python --version
Python 3.9.13

Additional context

The same happens for ArgumentParser.add_arguments:

Incompatible parameter type [6]: In call `simple_parsing.parsing.ArgumentParser.add_arguments`, for 1st positional argument, expected `Type[Variable[DataclassT (bound to Dataclass)]]` but got `Type[Options]`

The reason may be that a private method is used in the Dataclass declaration:

class Dataclass(Protocol):
    __dataclass_fields__: ClassVar[dict[str, Field]]

That is prohibited in pyre: https://pyre-check.org/docs/errors/#52-private-protocol-property

lebrice commented 1 year ago

Then that's a problem with Pyre, no?

Otherwise, how are you supposed to make a TypeVar with a bound set to a Dataclass protocol? I do want to keep the bound of Dataclass, otherwise any non-dataclass type could be passed.

alexanderlobov commented 1 year ago

Thanks for the answer! Sounds reasonable. I'll discuss it with the pyre team.

lebrice commented 10 months ago

Closing this for now, since the DataclassInstance protocol from dataclasses is also following this structure.