Skip to content

Conversation

@alessiostalla
Copy link
Member

Fixes #38

Copy link
Member

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added minor comments but my competence with Python is very limited, so please feel free to ignore them if they are irrelevant or wrong

return isinstance(decl_type, type) and issubclass(decl_type, Node)


def get_only_type_arg(decl_type):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use type annotations for both the parameter and the return type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't know how to properly type them


def get_only_type_arg(decl_type):
type_args = get_type_arguments(decl_type)
if len(type_args) == 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the type_args are more than one should we throw an exception perhaps?
If not, I would add a short document to explain it

return None


def process_annotated_property(name, decl_type, known_property_names):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here I would consider adding type annotations

def process_annotated_property(name, decl_type, known_property_names):
multiplicity = Multiplicity.SINGULAR
is_reference = False
if get_type_origin(decl_type) is ReferenceByName:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python I often get confused by is because I should use isinstance instead. I am not sure if that is the case here, but I mention it to be on the safe side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is is Java's ==
== is .equals
isinstance is instanceof

Here, we want to check if the type is exactly ReferenceByName

@internal_property
def properties(self):
return (PropertyDescription(p.name, p.provides_nodes, p.multiplicity, getattr(self, p.name))
return (PropertyDescription(p.name, p.type, p.is_containment, p.is_reference, p.multiplicity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when there are many parameters and several of them are boolean, we could pass them by name to avoid possible issues (i.e., writing them in the wrong order)

else:
return getattr(cls, '__annotations__', None)
try:
# On Python 3.10+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention this in the README?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention what? The algorithm for getting the annotations?

@alessiostalla alessiostalla merged commit d206736 into master Feb 20, 2025
6 checks passed
@alessiostalla alessiostalla deleted the feature/pep-0563 branch February 20, 2025 12:50
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 this pull request may close these issues.

PEP 0563

3 participants