-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better tab handling, copy function updated
- Loading branch information
Showing
6 changed files
with
138 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from typing import Iterator, Tuple, Any | ||
|
||
EXCLUDED_NAME = "EXCLUDED_ATTRIBUTES" | ||
|
||
# Metaclasses ------------------------------------------------------------------ | ||
|
||
class IterableAttributeNames(type): | ||
""" Makes the class itself iterable over its attribute names. """ | ||
|
||
|
||
def __iter__(self) -> Iterator[str]: | ||
for attr in dir(self): | ||
if not attr.startswith("__") and attr != EXCLUDED_NAME and attr not in getattr(self, EXCLUDED_NAME, []): | ||
yield attr | ||
|
||
|
||
class IterableAttributeValues(type): | ||
""" Makes the class itself iterable over its attribute values. """ | ||
def __iter__(self) -> Iterator[Any]: | ||
for attr, value in self.__dict__.items(): | ||
if not attr.startswith("__"): | ||
yield value | ||
|
||
|
||
class IterableAttributeItems(type): | ||
""" Makes the class itself iterable over its attribute name and values. """ | ||
def __iter__(self) -> Iterator[Tuple[str, Any]]: | ||
for attr, value in self.__dict__.items(): | ||
if not attr.startswith("__"): | ||
yield attr, value | ||
|
||
|
||
# Iterable Class --------------------------------------------------------------- | ||
|
||
|
||
class IterClass(metaclass=IterableAttributeNames): | ||
|
||
EXCLUDED_ATTRIBUTES = ["keys", "values", "items"] | ||
|
||
@classmethod | ||
def keys(cls) -> Iterator[str]: | ||
for attr in cls: | ||
yield attr | ||
|
||
@classmethod | ||
def values(cls) -> Iterator[Any]: | ||
for attr in cls: | ||
yield getattr(cls, attr) | ||
|
||
@classmethod | ||
def items(cls) -> Iterator[Tuple[str, Any]]: | ||
for attr in cls: | ||
yield attr, getattr(cls, attr) |
File renamed without changes.