Skip to content

[PyYAML] Use Incomplete instead of Any - #16197

Merged
srittau merged 2 commits into
python:mainfrom
donbarbos:pyyaml-use-incomplete
Aug 14, 2026
Merged

[PyYAML] Use Incomplete instead of Any#16197
srittau merged 2 commits into
python:mainfrom
donbarbos:pyyaml-use-incomplete

Conversation

@donbarbos

Copy link
Copy Markdown
Contributor

In some places, Any was intended to represent a Python object corresponding to a YAML value.
I think we could be more precise than simply using Any here for example, by defining a TypeAlias for the possible types (list, dict, etc.) and adding a comment explaining the choice.

@srittau

srittau commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

In some places, Any was intended to represent a Python object corresponding to a YAML value.
I think we could be more precise than simply using Any here for example, by defining a TypeAlias for the possible types (list, dict, etc.) and adding a comment explaining the choice.

In general a type alias would also double as documentation and would make the comment for Any superfluous. But we probably need to distinguish between output types (= Any) and input types (= X | Y) for the usual union in output types problem.

@donbarbos

Copy link
Copy Markdown
Contributor Author

Since any object can be passed as input (to 'dump' functions), I used the same type alias for it as well. It looks like we do need to use Any for both input and output types after all, just for different reasons.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

operator (https://github.com/canonical/operator)
- ops/storage.py:361: error: Unused "type: ignore" comment  [unused-ignore]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/core/deserialization.py:149: error: Unused "type: ignore" comment  [unused-ignore]
+ src/schemathesis/core/deserialization.py:157: error: Unused "type: ignore" comment  [unused-ignore]

@srittau
srittau merged commit 6fba3ae into python:main Aug 14, 2026
74 checks passed
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.

2 participants