microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
29 stars 5 forks source link

Python syntax/type errors when default union type is list or dict #112

Closed naegelejd closed 7 months ago

naegelejd commented 7 months ago

Given the following model:

GenericUnionsRecord<T, U>: !record
  fields:
    a: !union
      tv: T*
      t: T
    b: !union
      tm: T->U
      t: T

yardl v0.4.0 generates invalid constructor code for both inner unions:

class GenericUnionsRecord(typing.Generic[T, T_NP, U]):
    ...

    def __init__(self, *, ...):
        self.a = a if a is not None else TvOrT.Tv([]())
        self.b = b if b is not None else TmOrT.Tm({}())

Warnings on import (these are TypeErrors at runtime):

/workspaces/yardl/joe/issue-#112/python/odd/types.py:58: SyntaxWarning: 'list' object is not callable; perhaps you missed a comma?
  self.a = a if a is not None else TvOrT.Tv([]())
/workspaces/yardl/joe/issue-#112/python/odd/types.py:59: SyntaxWarning: 'dict' object is not callable; perhaps you missed a comma?
  self.b = b if b is not None else TmOrT.Tm({}())

This issue occurs when the first type in the union resolves to a Python list or dict.