Skip to content

Preserve filesystem subclass types in context managers - #608

Open
Hugohong258 wants to merge 1 commit into
PyFilesystem:masterfrom
Hugohong258:fix-context-manager-return-types
Open

Hugohong258 wants to merge 1 commit into
PyFilesystem:masterfrom
Hugohong258:fix-context-manager-return-types

Conversation

@Hugohong258

Copy link
Copy Markdown

Type of changes

  • Bug fix
  • Tests

Checklist

  • Black 22.3.0, pinned by the repository's codeformat environment, passes with default settings on changed Python files.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @PyFilesystem/maintainers may be pedantic in the code review.

Description

FS.__enter__ returns the same instance but annotates the result as FS, widening concrete subclasses in with blocks. Bind its return to the existing _F self type variable, so a TempFS, OSFS, or custom subclass keeps its concrete type. Related to the type-inference aspect of #580.

The mypy regression reports three errors on the base and passes with the change using the repository's pinned mypy 0.800 on Windows/Python 3.9.25. It skips when mypy is unavailable. Related base/memory/temp filesystem tests have 280 passes, 4 skips and 2 symlink-permission failures; the same two WinError 1314 failures reproduce on unchanged upstream. Pinned Black, Flake8 with configured plugins and the changed-file type check pass. The full 57-file type check has the same five diagnostics before and after. Other runtimes, the complete project suite and the full platform matrix were not run.

This branch has not been deployed

No deployments
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