agronholm / agronholm/typeguard

Checking types against types

Aberta
#584 3 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement
Linguagem predominante
Python
Estrelas
1.8k
Forks
146
Merge médio
8d 12h
PRs com merge (30d)
1

Descrição

### Things to check first

- [x] I have searched the existing issues and didn't find my feature already requested there

### Feature description

An API function, similar to `check_type()` (or an expansion of that function), to check a type against another type, rather than a value against a type.

The difference between the existing behavior lies in already knowing what the data type will be, but not having the data ready (yet).

### Use case

I've got a library that takes a callable and a tuple of arguments, and that attempts to call the callable, trying multiple permutations of the arguments to see if the types match. For example, calling the library on callables `(Arg1, Arg2)`, `(Arg2,)` and `()` with args `(Arg1, Arg2)` will call each function by dropping the unmatched arguments.

This underpins both many callbacks across my app, as well as a factory API where arguments are provided but callable may opt out to decouple themselves from those values's APIs, allowing third parties to integrate their code flexibly, without needless coupling.

Additionally, the aforementioned factory API tries several factory callables for any class it needs to initialize (ranging from just calling `cls(...)` to factory methods the class may implement), and combined with finding the right permutation of argument types, this may be quite a bit of work per class. Given that in many of my cases the types are known beforehand, this feature would allow me to 'precompile' and cache the results of this, resulting in an almost zero-cost-abstraction.

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Start by reading the existing check_type() implementation and its public API. Trace how it handles values versus types, then define the corresponding type-to-type behavior for callable argument permutations and cached results. Done means callers can check already-known types without constructing values and use the result for the described factory and callback selection.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
tooling
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
48/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.