agronholm / agronholm/typeguard

Checking types against types

Offen
#584 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
145
Ø Merge
8 T. 12 Std.
Gemergte PRs (30 T.)
1

Beschreibung

### 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.