Assisting pydev with type information.

  • Tom

    Tom - 2009-07-23

    I'd like to 'help' pydev by giving it some info about my types - so that it can provide me with auto-complete information, and so that it doesn't mar

    The problem is that I often initially assign attributes the 'None' value, and then set their actual value later.  This typically comes up with class types.  I guess this is the equivelent of assigning a null value to a reference in other languages.

    The result seems to be that pydev/pylint thinks the attribute has a type of None (which is true, initially).

    Is there some way that I can 'tell' pydev what the correct type is?  Ideally it would be better if I could do this in the source code, rather then in a configuration file, since that would be more convenient and because it is useful information for documenting the program.

    • f33l

      f33l - 2009-08-04

      I'd be interested in this too - I'd be cool, if you could somehow tell pydev to use the @type tag for the pydoc as reference, but I guess that's also messy and not implemented. I wish Guido had made python 3.0 optionally statically typed. Sigh.

    • Gunnlaugur Thor Briem

      You can do that with assertions. E.g.:

      assert isinstance(ds, DataSet)

      With the cursor there, PyDev will autocomplete on members of the class DataSet.

    • Tom

      Tom - 2009-08-25

      That is a good idea, but I find that it doesn't work.  I guess pydev doesn't parse the 'isinstance' statement?

      I hope it will be supported in the future as it is a good solution to the problem.  Then I would define a static member like this:

      class Blah:
          shape1 = None;           # will be used as a Shape object later.
          isinstance( shape1, Shape );         # returns False here, but ignored.
              # or
          assert isinstance( shape1, (NoneType, Shape) );

      • Fabio Zadrozny

        Fabio Zadrozny - 2009-08-25

        It should support the assert isinstance(), but I guess it's not working with a tuple as a parameter (please enter a bug request for that).



        • Tom

          Tom - 2009-08-25

          Are you sure?

          I'm finding that it doesn't work in either case.  For example:

                  assert isinstance( attr1, Obj1 );
                           # here an error is reported, even though member1 is a member of Obj1.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks