Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
naegelejd opened this issue Nov 28, 2023 · 0 comments · Fixed by #117
Closed

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

naegelejd opened this issue Nov 28, 2023 · 0 comments · Fixed by #117
Assignees

Comments

@naegelejd
Copy link
Contributor

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.

@naegelejd naegelejd changed the title Python unions Python syntax/type errors when default union type is list or dict Nov 28, 2023
@naegelejd naegelejd self-assigned this Nov 29, 2023
naegelejd added a commit that referenced this issue Nov 29, 2023
naegelejd added a commit that referenced this issue Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant