Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

93
Is there a library for basic type inference?
Post Flair (click to view more posts with a particular flair)
Post Body

To clarify, I'm after something like the following. Let's say I have a function that takes some arbitrary inputs and provides some arbitrary output. It's lightweight and type-stable, so that the return type is predictable from the input types, but there are no other restrictions.

I want to be able to call the function with type objects to infer the return type given the input types. Obviously I can't do that with raw python type objects:

def my_func(a, b):
    return a   b

inferred_return = my_func(int, int)   # fail

But this would work:

class MyInt:
    pytype = int
    def __add__(self, other):
        if isinstance(other, MyInt):
            return MyInt()
        return NotImplemented

inferred_return = my_func(MyInt(), MyInt()).pytype   # == int

I could make such wrappers for all the types I'm interested in and do this the manual way. It wouldn't be hard, just tedious, and I'm likely to be hunting down edge cases for a while. Is there a library that provides such type wrappers?

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
140,975
Link Karma
2,184
Comment Karma
137,443
Profile updated: 1 week ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago