Skip to content

Complete OpenApiGeneratorExtension type hints - #1515

Open
johnthagen wants to merge 1 commit into
tfranzel:masterfrom
johnthagen:type-hint-openapi-generator-extension
Open

Complete OpenApiGeneratorExtension type hints#1515
johnthagen wants to merge 1 commit into
tfranzel:masterfrom
johnthagen:type-hint-openapi-generator-extension

Conversation

@johnthagen

@johnthagen johnthagen commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Subtask of #600

This allows users to subclass OpenApiSerializerFieldExtension without needing to add a # type: ignore

@johnthagen johnthagen changed the title Complete OpenApiGeneratorExtension type hints Complete OpenApiGeneratorExtension type hints Jul 6, 2026
@johnthagen

johnthagen commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@tfranzel I may need your help fixing the new type errors (as I am not as deeply familiar with the internals)

drf_spectacular/plumbing.py:843: error: Argument 1 to "append" of "list" has incompatible type "type[OpenApiGeneratorExtension[T]]"; expected "type[T]"  [arg-type]
drf_spectacular/plumbing.py:851: error: Argument 1 to "import_string" has incompatible type "str | type[object] | None"; expected "str"  [arg-type]
drf_spectacular/plumbing.py:854: error: Item "None" of "str | type[object] | None" has no attribute "startswith"  [union-attr]
drf_spectacular/plumbing.py:854: error: Item "type" of "str | type[object] | None" has no attribute "startswith"  [union-attr]
drf_spectacular/plumbing.py:862: error: Item "None" of "str | type[object] | None" has no attribute "startswith"  [union-attr]
drf_spectacular/plumbing.py:862: error: Item "type" of "str | type[object] | None" has no attribute "startswith"  [union-attr]

I'm surprised that the changes I added would cause "problems" since I'm simply specifying some loose types where there were none. Perhaps this change is allowing type checking to go "deeper" now and it is revealing real issues that were silent before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant