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

fix: python self referencing property types not using forward reference #1893

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

jonaslagoni
Copy link
Sponsor Member

@jonaslagoni jonaslagoni commented Mar 14, 2024

Description

This PR fixes a problem where the Python generator cannot handle self-referencing properties i.e. in the constructor everything works fine, but in the getters and setters we must use '<self reference type>'. Also the changed constructor to use if 'tuple_model' in input instead of if hasattr(input, 'tuple_model'):.

class Address: 
  def __init__(self, input: Dict):
    if 'self_model' in input:
      self._self_model: Address = Address(input['self_model'])
    if 'array_model' in input:
      self._array_model: List[Address] = input['array_model']
    if 'tuple_model' in input:
      self._tuple_model: tuple[Address] = input['tuple_model']
    if 'map_model' in input:
      self._map_model: dict[str, Address] = input['map_model']
    if 'union_model' in input:
      self._union_model: Address = input['union_model']

  @property
  def self_model(self) -> 'Address':
    return self._self_model
  @self_model.setter
  def self_model(self, self_model: 'Address'):
    self._self_model = self_model

  @property
  def array_model(self) -> List['Address']:
    return self._array_model
  @array_model.setter
  def array_model(self, array_model: List['Address']):
    self._array_model = array_model

  @property
  def tuple_model(self) -> tuple['Address']:
    return self._tuple_model
  @tuple_model.setter
  def tuple_model(self, tuple_model: tuple['Address']):
    self._tuple_model = tuple_model

  @property
  def map_model(self) -> dict[str, 'Address']:
    return self._map_model
  @map_model.setter
  def map_model(self, map_model: dict[str, 'Address']):
    self._map_model = map_model

  @property
  def union_model(self) -> 'Address':
    return self._union_model
  @union_model.setter
  def union_model(self, union_model: 'Address'):
    self._union_model = union_model

Copy link

netlify bot commented Mar 14, 2024

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 624310e
🔍 Latest deploy log https://app.netlify.com/sites/modelina/deploys/65f81240184013000893a167

@jonaslagoni jonaslagoni marked this pull request as draft March 15, 2024 12:04
@jonaslagoni
Copy link
Sponsor Member Author

Still need some work

@jonaslagoni jonaslagoni marked this pull request as ready for review March 18, 2024 10:07
Copy link

sonarcloud bot commented Mar 18, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@jonaslagoni jonaslagoni merged commit 7d69b70 into asyncapi:next Mar 26, 2024
25 checks passed
@jonaslagoni jonaslagoni deleted the fix-forward-references branch March 26, 2024 08:59
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 4.0.0-next.20 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants