Menu

#1 TypeHints

2.0
open
2024-02-06
2020-02-19
No

I presume this will be impossible while maintaining Python2 and 3 support (though Python2 has officially reached EOL now, but that doesn't mean people don't still use it) but...

Using Python 3's TypeHints would make complicated schemas much easier to code towards when using an IDE like PyCharm.
I'm currently working with a schema https://ftp.ncbi.nlm.nih.gov/pub/clinvar/xsd_submission/clinvar_submission_1.6.xsd which is considerable size (and generateds has made it so much easier), but being able to tell right away if an element "Name" is of "NameType" or "str" would streamline things immensely.

Regardless if you take this task on board, thanks for all the work you've put into this project.

Discussion

  • Ankur  Sinha

    Ankur Sinha - 2022-09-27

    +1 for this feature (although I don't know how much work this is to implement). At the moment, our classes all look like this:

    Izhikevich2007Cell(neuro_lex_id=None, id=None, metaid=None, notes=None, properties=None, annotation=None, C=None, v0=None, k=None, vr=None, vt=None, vpeak=None, a=None, b=None, c=None, d=None, gds_collector_=None, **kwargs_)
    

    which means users don't really get any information about what each argument to the constructor should be---they need to go look at our schema documentation to figure out what v0 should be, for example. If it's possible to somehow add type hints here about the class type that the parameter is meant to be:

    Izhikevich2007Cell(neuro_lex_id=None, id: NmlID = None, metaid: str = None, notes: NmlNote = None, properties: NmlProperty = None, annotation: NmlAnnotation = None, C: NmlQuantity = None, v0: NmlQuantity = None, k: NmlQuantity = None, vr:NmlQuantity: = None, vt: NmlQuantity = None, vpeak: NmlQuantity = None, a: NmlQuantity = None, b: NmlQuantity = None, c: NmlQuantity = None, d: NmlQuantity = None, gds_collector_:GdsCollector = None, **kwargs_)
    

    that'll mean users have this information while they write.

    In the meantime, I'm looking into whether it's possible to "post-process" the generated api using inspect to see if I can add this information.

     
  • Nik

    Nik - 2024-02-06

    Hi, we just implemented this in a fork on our gitlab.com group: https://gitlab.com/cdehealth/generateds/-/tree/2.44.1+20240201?ref_type=tags

    Because of possible references before definition of classes, like unordered in the XSDs, we had to use forward references, not:
    id: NmlID = None
    but:
    id: 'NmlID' = None
    but we can still use it with
    getattr(self.id, type_name)

    It seems Intellisense is not catching it, but we can still use it as intended.

    Maybe we could merge this into the main repo here. Feedback wanted.

     

Log in to post a comment.