Skip to content

Fix Pyright unknown types for YAML.load / YAML.dump (SF #564) - #2

Open
adamtheturtle wants to merge 1 commit into
commx:masterfrom
adamtheturtle:fix/pyright-yaml-load-dump-sf564
Open

Fix Pyright unknown types for YAML.load / YAML.dump (SF #564)#2
adamtheturtle wants to merge 1 commit into
commx:masterfrom
adamtheturtle:fix/pyright-yaml-load-dump-sf564

Conversation

@adamtheturtle

Copy link
Copy Markdown

Summary

Fixes SourceForge #564: under Pyright strict mode, YAML.load and YAML.dump reported reportUnknownMemberType because stream / data resolved to Unknown.

Cause

Imports for Path, StreamType, and StreamTextType lived under if False: # MYPY. Pyright does not treat that as a type-checking-only branch (unlike typing.TYPE_CHECKING), so those names were undefined and annotation resolution failed.

Changes

  • compat.py, main.py: use TYPE_CHECKING instead of if False for MYPY-only imports.
  • YAML.dump: type data as Any (the object to serialize). The previous Union[Path, StreamType] was incorrect for data. stream is Optional[Union[Path, StreamType]].

Verification

Strict Pyright on a small consumer that calls YAML().load(...) and YAML().dump(..., ...) reports 0 errors.

Made with Cursor

Pyright does not treat `if False` blocks as type-checker-only, so imports
of Path and Stream* aliases were undefined and parameters became Unknown under
strict reportUnknownMemberType.

- Use typing.TYPE_CHECKING in compat.py and main.py for MYPY-only imports.
- Type YAML.dump data as Any (the serialized object); stream as
  Optional[Union[Path, StreamType]].

Made-with: Cursor
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