Skip to content

Checking types against types #584

Description

@bartfeenstra

Things to check first

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions