Coder Social home page Coder Social logo

type aliases no longer work? about cinder HOT 2 OPEN

bennn avatar bennn commented on June 14, 2024
type aliases no longer work?

from cinder.

Comments (2)

DinoV avatar DinoV commented on June 14, 2024 1

Thanks for the report... It looks like this was caused by 6ce212a. That prevents code like:

import __static__

class C:
    def __init__(self):
        self.x = 42

def f():
    global a
    a = 42
a = C()
f()

print(a.x)

From crashing, but we'll need to come up with a better solution here and retain the implicit type information while disallowing the conflicting assignment. We do report the invalid assignment if def f comes after the assignment to a so it's probably just adjusting how our passes run or adding a new pass.

from cinder.

DinoV avatar DinoV commented on June 14, 2024

We've come up with some other interesting examples:

class A: pass
class B(A): pass

def f():
    global x
    x = A()  # this assignment should be ok

def g(arg: B): pass

x: A = B()

f()

g(x)  # should be a TypedSyntaxError, with or without `f()` (or even the definition of `f`)

And we've looked at what Pyre does here as well. Both Pyre and static Python have a notion of inferred type as well as the declared type. In some annotated cases like "x = 42" it seems that there ends up being an inferred type of Literal[42] and a declared type of int.

Currently we only end up with an inferred type, and then we're turning that into dynamic. We probably need to more closely mimic what Pyre is doing for getting a declared type in these situations, and then drop the inferred type. And we need to understand more when we should treat the inferred type as declared.

We also may be able to do this in limited scenarios, e.g. where there are no references to global in the module, where we know the value won't change (because the module is known to be immutable).

And we may need to add an extra pass in to accomodate this as well.

Unfortunately this will take a little while to get to!

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.