biqqles / dataclassy

A fast and flexible reimplementation of data classes
https://pypi.org/project/dataclassy
Mozilla Public License 2.0
81 stars 9 forks source link

Enable typing per PEP-561 #20

Closed giannitedesco closed 3 years ago

giannitedesco commented 3 years ago

Description of changes

All that needs to be done is to add a "py.typed" file to the package, since adequate type annotations exist in all of the dataclassy code.

Testing

I installed the package locally and checked the following program with mypy --strict and it failed in the same way that dataclasses fails when the mypy dataclasses plugin is disabled.

from dataclassy import dataclass

@dataclass(slots=True)
class Foo:
    a: int
    b: str

x = Foo(1, 'abc')

Gives the following error:

dc.py:8: error: Too many arguments for "Foo"
Found 1 error in 1 file (checked 1 source file)

Which means that:

  1. mypy recognises that dataclassy supports types (hooray!)
  2. recognizes the types of the decorators (hooray!)
  3. does not yet understand how the decorators create new types, but only a mypy plugin can solve that (more work to do!)
biqqles commented 3 years ago

I committed my preferred formatting and added a comment explaining __all__'s purpose. I'm happy to merge this now. I was a bit curious about why mypy needed __all__ though, so I looked up the error it produces without the definition (error: Module 'dataclassy' does not explicitly export attribute 'dataclass'; implicit reexport disabled). Strangely, searching for generic parts of the string (e.g. "implicit reexport disabled") only brings up two results, both of them from mypy's repository itself. I thought this would be a very common problem.