Distinguishing between "instance of class" and "class" types in the duchain

Sven Brauch svenbrauch at googlemail.com
Mon Apr 9 21:37:03 UTC 2012


Hi there,

consider this code:
  class my_class(): pass
  copy_of_my_class = my_class
  instance_of_my_class = my_class()
How could you find out which of instance_of_my_class or
copy_of_my_class are the class itself or instances of the class now? I
mean, both have the "raw" structuretype assigned, no?

Cheers

Am 9. April 2012 23:02 schrieb Milian Wolff <mail at milianw.de>:
> On Monday 09 April 2012 22:32:02 Sven Brauch wrote:
>> Hello there,
>>
>> there's something I'm unsure about how to correctly represent it in
>> the duchain: the difference between "class" and "instance of a class".
>> My current solution is that a class declaration creates a structure
>> type, and if I want to reference the class itself (not an instance of
>> the class) I create an alias declaration which aliases the class
>> declaration. That is not really optimal for several reasons tough:
>> there's always the need to search for declarations if you work with
>> types, e.g. if handling an assignment, you cannot simply assign B the
>> type of A, but you have to check if A is a class or an instance of a
>> class, then create an alias declaration or something else depending on
>> that... etc; additionaly, it's not possible to store class types in
>> unsure types that way (a declaration cannot have an unsure type which
>> could either be a class or None, or similar).
>>
>> Is there a good way to do this?
>> Is there a good *idea* which I could implement in the duchain to solve
>> this problem? It's really messy right now.
>
> In PHP and C++ we just assign the "raw" structuretype to instances. To figure
> out if you actually have a declaration, you can either cast to
> ClassDeclaration or compare the declaration of the structuretype. Why does
> that not work for you?
>
> bye
>
> --
> Milian Wolff
> mail at milianw.de
> http://milianw.de
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
>




More information about the KDevelop-devel mailing list