Skip to content

refactor: use difficulty labels and classes, tidy up domain slightly#29

Closed
exploreriii wants to merge 1 commit intomainfrom
domain-refactor
Closed

refactor: use difficulty labels and classes, tidy up domain slightly#29
exploreriii wants to merge 1 commit intomainfrom
domain-refactor

Conversation

@exploreriii
Copy link
Copy Markdown
Contributor

Fixes #28

Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
@exploreriii exploreriii marked this pull request as ready for review March 10, 2026 14:16
ONBOARDING_STAGES = (
FIRST_PR,
MERGED_FIRST_PR,
) No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The GFI_STARTER is missing.

normalized = {label.lower() for label in issue_labels}
return bool(self.labels.intersection(normalized))

def __contains__(self, issue_labels: Iterable[str]) -> bool:
Copy link
Copy Markdown
Contributor

@Adityarya11 Adityarya11 Mar 10, 2026

Choose a reason for hiding this comment

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

I would suggest, removing the __contains__ method. the current implementation accepts Iterable[str] but in case a single string is passed (eg: "good first issue") then this will be produced as set(), which could lead to unexpected or incorrect matching behavior.

since we already have
src\hiero_analytics\domain\difficulty.py

        if level.label_spec.matches(issue_labels):   line: 87

the __contains__ is not necessary for this scenario.

though i appreciate a second opinion from @MonaaEid @undefinedIsMyLife

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

agree

for level in DIFFICULTY_LEVELS:
if level.label_spec.matches(issue_labels):
return level.name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we are moving toward a domain model, would it be better to return the DifficultyLevel object itself rather than just the string name? This would allow calling scripts to access the .order attribute if they need to sort results later.
Instead of level.name if we can return level


name: str
labels: set[str]
labels: FrozenSet[str]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since matches() relies on lowercase comparison, we should ensure the internal labels set is always lowercase. Instead of just adding a documentation note, we can enforce this in the code using a __post_init__ block. This prevents 'silent bugs' if a future contributor accidentally adds a label with capital letters.

def __post_init__(self):
    object.__setattr__(self, 'labels', frozenset(l.lower() for l in self.labels))

What do you think about making the class handle this normalization automatically?

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.

abstract difficulty into its own class

4 participants