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

Update type hints for prefix map merging #454

Merged
merged 6 commits into from
Nov 6, 2023
Merged

Conversation

cthoyt
Copy link
Member

@cthoyt cthoyt commented Oct 7, 2023

This PR does the following:

  1. Creates a literal type for the 3 different prefix map merge modes
  2. Updates type hints based on that

This PR does the following:

1. Creates a literal type for the 3 different prefix map merge modes
2. Updates type hints based on that
3. Renames `prefix_map_mode` to `merge_mode` in the API

This doesn't update the name of the flag in the CLI, that can be done in a separate PR since I don't want to worry about changing backwards compatibility here.
@cthoyt cthoyt mentioned this pull request Oct 7, 2023
@cthoyt cthoyt requested a review from hrshdhgd October 7, 2023 10:24
Copy link
Collaborator

@matentzn matentzn left a comment

Choose a reason for hiding this comment

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

Just a few questions, nothing actionable I think

PREFIX_MAP_MODE_MERGED,
]
MergeMode = Literal["metadata_only", "sssom_default_only", "merged"]
PREFIX_MAP_MODE_METADATA_ONLY: MergeMode = "metadata_only"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Never seen this syntax. What does this do, when considering line 40? Looks redundant at first glance (twice the same assignment)

Copy link
Member Author

Choose a reason for hiding this comment

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

This makes checking that one of the constants is used properly is checked by type checking. It further builds the string enumeration into the automatic documentation generation

src/sssom/io.py Outdated
@@ -59,7 +60,7 @@ def parse_file(
output: TextIO,
input_format: Optional[str] = None,
metadata_path: Optional[str] = None,
prefix_map_mode: Optional[str] = None,
merge_mode: Optional[MergeMode] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

All borders have fallen now, but renaming parameters to central methods like this is really annoying for users, but the change makes sense, so lets just break and mend it all now.

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 have a feeling this one is unused - it is only part of a method that should itself be private. In fact, I would rather remove this option completely and have it automatically chain on all instances.

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 reverted this and removed the renames

src/sssom/io.py Outdated Show resolved Hide resolved
@cthoyt
Copy link
Member Author

cthoyt commented Oct 9, 2023

@matentzn actually, I would much rather delete this functionality entirely and only support the PREFIX_MAP_MODE_MERGED mode. Given we spent lots of effort to make the curies integration, this option is much more powerful than before and I can't see why one would choose either of the others.

@matentzn
Copy link
Collaborator

matentzn commented Oct 9, 2023

We should be able at CLI time to allow an option to "fail if a prefix is not declared", like a "strict parsing" mode. This prevents cases like completely automated systems that accidentally infer a completely wrong prefix map for a dataset. I'd prefer to continue supporting that functionality, but I would be ok to move MERGED mode as default..

@cthoyt cthoyt requested a review from matentzn November 6, 2023 10:34
@cthoyt
Copy link
Member Author

cthoyt commented Nov 6, 2023

@matentzn I simplified this PR and took all of the questionable parts out. Now it's just about using type hints better.

Copy link
Collaborator

@matentzn matentzn left a comment

Choose a reason for hiding this comment

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

Great!

@cthoyt cthoyt merged commit 77b4263 into master Nov 6, 2023
6 checks passed
@cthoyt cthoyt deleted the update-merge-mode-typing branch November 28, 2023 16:55
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.

2 participants