Skip to content

Commit

Permalink
feat(stubs): make StubRepositoryPackage immutable, iterate matchers.
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Dec 11, 2022
1 parent 0f7487f commit ae71f91
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions micropy/stubs/repo_package.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import annotations

from typing import Iterator

import attrs
from micropy.stubs import StubPackage, StubsManifest
from pydantic import BaseModel


class StubRepositoryPackage(BaseModel):
@attrs.frozen
class StubRepositoryPackage:
manifest: StubsManifest
package: StubPackage

Expand Down Expand Up @@ -36,5 +39,17 @@ def versioned_name(self) -> str:
def absolute_versioned_name(self) -> str:
return self.manifest.resolve_package_absolute_versioned_name(self.package)

@property
def exact_matchers(self) -> Iterator[str]:
yield self.absolute_versioned_name
yield self.versioned_name
yield self.absolute_name

@property
def partial_matchers(self) -> Iterator[str]:
yield from self.exact_matchers
yield self.name
yield self.version

def match_exact(self, in_name: str) -> bool:
return in_name in [self.absolute_name, self.versioned_name, self.absolute_versioned_name]
return in_name in self.exact_matchers

0 comments on commit ae71f91

Please sign in to comment.