Skip to content

[Python] Fix type annotations for protocols, ABCs, Atom, and Set module#4315

Merged
dbrattli merged 2 commits intomainfrom
python-typing-fixes-6
Dec 29, 2025
Merged

[Python] Fix type annotations for protocols, ABCs, Atom, and Set module#4315
dbrattli merged 2 commits intomainfrom
python-typing-fixes-6

Conversation

@dbrattli
Copy link
Copy Markdown
Collaborator

Summary

  • Separated protocols from ABC base classes for cleaner inheritance architecture
  • Added proper Atom[T] type for module-level mutable values
  • Created Python-specific Set.fs to avoid JS-specific constructs
  • Fixed protocol signatures and array stub types for Pyright compatibility
  • Added cast(type, None) for null assignments to typed variables

Changes

Compiler (src/Fable.Transforms/Python/)

  • Fable2Python.Annotation.fs: Added Atom[T] type annotation support; fixed protocol type mappings
  • Fable2Python.Transforms.fs: Map IDisposableDisposableBase, IEnumerator_1EnumeratorBase for inheritance; wrap Null t with cast(type, None)
  • Replacements.fs: Added makeAtomType for proper Atom[T] return type from create_atom

Library (src/fable-library-py/)

  • protocols.py (new): Consolidated pure protocol definitions (structural subtyping only)
  • util.py: Added ABC base classes (DisposableBase, EnumeratorBase, EnumerableBase) with implementations; uses Self return type for __enter__ methods
  • Set.fs (new): Python-specific Set module without JS-specific interfaces
  • core/array.pyi: Fixed equals_with to accept None; fixed index return types to Int32
  • choice.pyi, option.pyi: Updated protocol signatures

Other

  • Fable.Library.Python.fsproj: Use local Set.fs instead of TypeScript version
  • event.py, observable.py: Use DisposableBase.create() instead of IDisposable.create()

(This brings us down to 945 type annotation errors)

@dbrattli dbrattli merged commit 09baffb into main Dec 29, 2025
37 of 43 checks passed
@dbrattli dbrattli deleted the python-typing-fixes-6 branch December 29, 2025 00:55
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