Closed pylint-bot closed 8 years ago
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
Having a Singleton node makes sense to me, so I would pretty much prefer this solution.
Yes, at some point we'll have to discuss about separating ASTs from live objects, but we shouldn't worry right now about this. I don't know why issue #205 has any relevancy here, the underlying proxy mechanism should be just an implementation detail from Const's point of view.
Original comment by BitBucket: ceridwenv, GitHub: @ceridwen:
Added Singleton node in 45b5ba2 to resolve some of these problems.
Originally reported by: BitBucket: ceridwenv, GitHub: @ceridwen
(This is part of a series of issues I'm going to open to talk about necessary reworkings that aren't obvious.)
This test is raising ultimately because for None,
type(self.value).__name__
evaluates toNoneType
, which is the type of the None singleton, only there's no name in the builtins module forNoneType
. This will also be a problem for NotImplemented.Fundamentally, this problem and others like it are arising because astroid is using AST nodes to represent both ASTs and live objects. However, there's no one-to-one mapping between ASTs and live objects: because None and NotImplemented only exist in the AST as Name(name=None) and Name(name=NotImplemented), using Const to represent them is kind of a hack. In the far future, we should maybe talk about better-distinguishing the two layers of astroid objects, AST nodes and live objects, and clarifying what kinds of objects only exist in one layer or the other.
For now, my best suggestion is to create a new node that subclasses Const called Singleton that overrides the _proxied property. Alternately, we could talk about shifting to a different proxy structure, perhaps in combination with replacing bases.Proxy with a different proxy (#205). Other solutions, like dispatching on the type of the object in _proxied or modifying the builtins AST to add names, look more hackish to me.