autodoc_pydantic icon indicating copy to clipboard operation
autodoc_pydantic copied to clipboard

Generics not supported?

Open s0undt3ch opened this issue 2 years ago • 2 comments

invalid signature for autopydantic_model ('saf.collect.beacons::PipelineRunContext[BeaconsConfig]')
make: *** [Makefile:20: coverage] Error 2
class BeaconsConfig(CollectConfigBase):
    """
    Configuration schema for the beacons collect plugin.
    """

    beacons: List[str]

async def collect(*, ctx: PipelineRunContext[BeaconsConfig]) -> AsyncIterator[BeaconCollectedEvent]:
    """
    Method called to collect events.
    """
PipelineRunContextConfigType = TypeVar("PipelineRunContextConfigType", bound=NonMutableConfig)


class PipelineRunContext(GenericModel, Generic[PipelineRunContextConfigType]):
    """
    Class representing a pipeline run context.
    """

    config: PipelineRunContextConfigType

s0undt3ch avatar Apr 15 '22 06:04 s0undt3ch

Hi @s0undt3ch,

thanks for raising this issue here. To be honest, I have silently assumed that autodoc_pydantic handles generic models just as fine as normal pydantic models in the past. Just now I added an example in the documentation showing how generic models are rendered via autodoc_pydantic. Given the standard example from the pydantic docs, it just works fine.

Nevertheless, I'm pretty sure you've stumbled across an edge case where autodoc_pydantic might break the building process. However, I need your help to reproduce the error because I'm currently rather new to generics in python:

  • Could you please provide a complete self containing example? With the above, I don't know what NonMutableConfig is. Moreover, the saf.collect.beacons module seems to have a concrete implementation of PipelineRunContext with BeaconsConfig. This is not shown in your code example.
  • What sphinx/pydantic/autodoc_pydantic versions are you using?
  • How do you invoke the building process?

mansenfranzen avatar Apr 15 '22 20:04 mansenfranzen

Sure, I'll try to make a self contained version of the error and I'll post it here.

Thank You for your work!

s0undt3ch avatar Apr 15 '22 20:04 s0undt3ch