-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: use static duck typing for packages #356
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
refactor: use static duck typing for packages #356
Conversation
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
fc57890 to
84fdb8d
Compare
|
|
||
| app_id: Required[str] | ||
| """The numerical identifier of the application this package is associated with""" | ||
| class _Packages(Sized, Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to suffix the class names with P to help visually declare that it's a protocol class?
| class _Packages(Sized, Protocol): | |
| class _PackagesP(Sized, Protocol): |
(Much easier to perform with "rename symbol")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we should make these public types. External users may want to use them for type hinting.
For example...
from posit.connect import Client, Packages
client = Client()
packages: Packages = client.packages| version: Required[str] | ||
| hash: Required[Optional[str]] | ||
| @overload | ||
| def __getitem__(self, index: slice) -> _ContentPackage: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def __getitem__(self, index: slice) -> _ContentPackage: ... | |
| def __getitem__(self, index: slice) -> list[_ContentPackage]: ... |
| @overload | ||
| def __getitem__(self, index: SupportsIndex) -> _ContentPackage: ... | ||
|
|
||
| class ContentPackage(Active): | ||
| class _Package(TypedDict): | ||
| language: Required[str] | ||
| name: Required[str] | ||
| version: Required[str] | ||
| hash: Required[Optional[str]] | ||
| @overload | ||
| def __getitem__(self, index: slice) -> _ContentPackage: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to put this into a generic helper class?
class _GetItem(Sized, Generic[T], Protocol):
@overload
def __getitem__(self, index: SupportsIndex) -> T: ...
@overload
def __getitem__(self, index: slice) -> list[T]: ...Co-authored-by: Barret Schloerke <[email protected]>
No description provided.