Skip to content

Conversation

GlassOfWhiskey
Copy link
Contributor

Closes #592.

@GlassOfWhiskey
Copy link
Contributor Author

Some discussion is needed here.

  1. Generated parsers give some weird error with MyPy that does not recognise bool return values correctly.
  2. I am not sure if the class_ field should be compared or if it would be better to just use isinstance.
  3. At the moment both extension_fields and loadingOptions are not considered with comparing. Any issue with that?

@mr-c
Copy link
Member

mr-c commented Sep 10, 2022

2. I am not sure if the class_ field should be compared or if it would be better to just use isinstance.

isinstance is the right call; not all objects have class fields

@mr-c
Copy link
Member

mr-c commented Sep 10, 2022

  • Skipping loadingOptions makes sense, I think.

Ok then, we can leave it out. Maybe we can put __eq__ and __hash__ also in the LoadingOptions object, but maybe in a separate PR in the future if it is needed.

  • As for extension_fields you could add another methods that first calls __eq__ and if True further checks the extensions fields.

Here, you mean directly in the object (through the code generator)? Or externally in a utility file (e.g. in cwl_utils). Because maybe extension fields can be used to add information to objects, and such information can vary from one implementation to the other. For example, I am thinking about the not-connected key.

@GlassOfWhiskey
Copy link
Contributor Author

isinstance is the right call; not all objects have class fields

But when it is present, is it correct to include it in the __eq__ method (as it happens now)?
Or it should be explicitly excluded, leaving only the initial isinstance(other, {classname}) check?

@mr-c
Copy link
Member

mr-c commented Sep 10, 2022

isinstance is the right call; not all objects have class fields

But when it is present, is it correct to include it in the __eq__ method (as it happens now)? Or it should be explicitly excluded, leaving only the initial isinstance(other, {classname}) check?

Yes, because we are looking for equality, so that should include all regular fields, identifiers included.

Again, we can add other methods that might ignore any identifier fields (class, id, name, …)

@codecov
Copy link

codecov bot commented Sep 10, 2022

Codecov Report

Merging #593 (c0ff86b) into main (774157d) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #593      +/-   ##
==========================================
+ Coverage   83.15%   83.19%   +0.04%     
==========================================
  Files          20       20              
  Lines        3953     3963      +10     
  Branches     1104     1105       +1     
==========================================
+ Hits         3287     3297      +10     
  Misses        431      431              
  Partials      235      235              
Impacted Files Coverage Δ
schema_salad/python_codegen.py 93.82% <100.00%> (+0.36%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

pycodegen: make generated objects comparable
2 participants