Le 5 octobre 2010 17:14, Maarten ter Huurne <[email protected]> a écrit
:
> On Tuesday 05 October 2010, Marc-Antoine Ruel wrote:
>
> > And that's the problem I see, astng sees "isinstance" as a normal
> > CallFunc() node instead of a specialized node (?)
>
> "isinstance" is a built-in function, not a keyword:
>
> >>> isinstance
> <built-in function isinstance>
>
> So I think astng is correct in returning a CallFunc node for it.
>
> Maybe you can check for the function name being "isinstance" and the
> function module being "__builtin__"?
>
My bad, you are right. I'm just no sure where the pattern matching code
should go, basically I want to match the tree for this layout:
Assert()
test =
CallFunc()
func =
Name(isinstance)
args = [
Name(x)
Name(A)
]
starargs =
kwargs =
In that case, Name(isinstance) needs to confirm it's the __builtin__ version
(how?) and Name(A) must be resolved to the type. The shortest hack would be
to conceptually replace this form with the equivalent inference from "x =
A()".
I wonder where this check should be.
If you have the time, please also let astng recognise this pattern:
>
> if not isinstance(arg1, SomeType):
> raise TypeError(type(arg1))
> # Here arg1 is a SomeType.
>
That makes sense but it looks slightly more complex to implement. From what
I understand, you cannot scope type inference inside a frame.
M-A
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects