Skip to content

feat: Use Sequence instead of list in type hints#25

Merged
kylebarron merged 1 commit into
mainfrom
kyle/sequence
May 21, 2025
Merged

feat: Use Sequence instead of list in type hints#25
kylebarron merged 1 commit into
mainfrom
kyle/sequence

Conversation

@kylebarron

@kylebarron kylebarron commented May 21, 2025

Copy link
Copy Markdown
Member

This is a good quick note on variance in Python and this is a good resource on variance of list vs Sequence:

Key Terms

  1. Covariant: If A is a subtype of B, then Container[A] is a subtype of Container[B].
  2. Contravariant: If A is a subtype of B, then Container[B] is a subtype of Container[A].
  3. Invariant: Neither covariant nor contravariant. Container[A] and Container[B] are not related, even if A and B are.

list is invariant while Sequence is covariant.

We want our type hints to be covariant so that users can return a subtype of ObjectMeta.

@kylebarron kylebarron changed the title Use Sequence instead of list in type hints feat: Use Sequence instead of list in type hints May 21, 2025
@kylebarron kylebarron merged commit d0f395c into main May 21, 2025
3 checks passed
@kylebarron kylebarron deleted the kyle/sequence branch May 21, 2025 16:17
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