litestar-org/polyfactory

Typing: DataclassProtocol.__dataclass_fields__ should be ClassVar

Closed this issue · 1 comments

https://github.com/starlite-api/pydantic-factories/blob/d5ebb7a2071ed393926dbdd2f7f7e47fd2a026a6/pydantic_factories/protocols.py#L10-L11

Defined here:

    # Remember all of the fields on our class (including bases).  This
    # also marks this class as being a dataclass.
    setattr(cls, _FIELDS, fields)

Where _FIELDS is:

# The name of an attribute on the class where we store the Field
# objects.  Also used to check if a class is a Data Class.
_FIELDS = '__dataclass_fields__'

I ran into this when trying to use the types in Starlite:

/home/peter/PycharmProjects/starlite/starlite/types/partial.py
  /home/peter/PycharmProjects/starlite/starlite/types/partial.py:137:49 - error: Protocol class "DataclassProtocol" does not define "__dataclass_fields__" as a ClassVar (reportGeneralTypeIssues)

Turns out this isn't as clear cut as it seems: python/typing#1056 (reply in thread)

Prob just better to side with mypy and leave as is.