Skip to content

Compatibility issues between base and C-accelerated pyyaml types #7768

Closed
@masklinn

Description

@masklinn

pyyaml does not implicitly swap out the C-accelerated types for the base ones because there are observable differences between the two (yaml/pyyaml#436).

However for packages only expected relatively simple inputs, a common pattern is to try and use the libYAML types if available and fallback:

try:
    from yaml import CLoader as Loader
except ImportError:
    from yaml import Loader

However running this through mypy yields:

error: Incompatible import of "Loader" (imported name has type "Type[Loader]", local name has type "Type[CLoader]")

While this is technically correct, it's not exactly convenient. Is there a local workaround aside from type: ignore, or a way to fix this in the stubs?

Tested with:

  • CPython 10.4
  • mypy 0.950
  • types_PyYAML 6.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions