GithubHelp home page GithubHelp logo

Comments (5)

DinoV avatar DinoV commented on May 10, 2024 2

The difficulty with disallowing a dynamic type is we do want to allow it sometimes. We have things like CheckedDict[str, Set[...]]. In this case other type checkers happily see the Set[...] type and CheckedDict as an alias for Dict and enforce the appropriate types. But we just see Set[...] as dynamic, and turn it into a CheckedDict[str, object].

So I think disallowing it ends up being worse than making it work. I have a fix which would make this work for CheckedDict by getting rid of __new__ so that our allocation will go through TP_ALLOC which takes a type descriptor. Unfortunately if we ever want a generic type which is immutable (which would presumably take arguments) then we'll run into this again.

There's probably a couple of possible solutions for that. One might be to add a way to invoke __new__ that takes the type descriptor and passes the resolved type in as the 1st argument (i.e. a TP_NEW opcode). What might be better would be adding an opcode which turns a type descriptor into the underlying type. Then we could emit the __new__ call with the compiler known type instead of emitting the various loads and binary subscrs required to produce the type. That might not require any specialization of the __new__ handling - we could just use that to emit any generic type references.

from cinder.

carljm avatar carljm commented on May 10, 2024 1

There is no dynamic at runtime, dynamic is purely a compiler construct. If a dynamic type ends up in the bytecode, it gets translated to object.

I think probably what we want here is the static type error on trying to make a CheckedDict with dynamic type as key or value type.

from cinder.

DinoV avatar DinoV commented on May 10, 2024

The problem here is that we think we want to create a CheckedDict[str, dynamic] because we don't know what C resolves to. But we then call CheckedDict.__new__(CheckedDict[str, C]) to create the instance of it.

from cinder.

bennn avatar bennn commented on May 10, 2024

Is chkdict[str, object].__new__ the same as CheckedDict.__new__ (the right constructor)? We were wondering how object got involved, as opposed to C or dynamic.

from cinder.

DinoV avatar DinoV commented on May 10, 2024

This is now fixed, we'll make a CheckedDict which respects what the compiler things the type is instead of the runtime provided type. Per the discussion above there'll be more work in the future though.

from cinder.

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.