Giter Site home page Giter Site logo

Comments (5)

carljm avatar carljm commented on June 7, 2024 1

Fixed with merge of #311

from monkeytype.

carljm avatar carljm commented on June 7, 2024

Thanks for the suggestion!

This is a case that falls under MonkeyType's clearly documented minimalist philosophy: it aims to give you accurate and concrete information about the types seen in your program, and let you make the decisions about how to best abstract those into good annotations.

If we added this feature, it would lead to judgment calls that would probably end up requiring new config options. E.g. what happens if there are twenty different subclasses of a common base type and only two of them are ever seen at a particular location? Is the base type still the best annotation, or is the union better?

Or what about cases where the base type is very broad, e.g. some kind of base "object" type in a large type hierarchy? We could special-case the Python object type, but users can create similar type hierarchies with similar common bases (e.g. if writing a type-checker in Python!), and may not want all unions reduced to Object.

Fundamentally this transformation of the annotation loses potentially useful information, and since we can't be sure it is preferred in all cases, it's better not to do the transformation by default.

This is why MonkeyType has "type rewriters" which allow arbitrary post-transformation of types. The transformation you want can be written as a type rewriter and used in your own projects. I'd even consider merging it into MonkeyType so it's available to all users (though I don't think I would have it be turned on by default.)

from monkeytype.

carljm avatar carljm commented on June 7, 2024

I'm leaving the issue open in case someone wants to provide a PR implementing this as an optional but built-in type rewriter.

from monkeytype.

dgutson avatar dgutson commented on June 7, 2024

@arieltorti @qequ

from monkeytype.

dgutson avatar dgutson commented on June 7, 2024

thanks @chrhansk !

from monkeytype.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.