forked from pepkit/attmap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc how to customize text repr; close pepkit#47
- Loading branch information
Showing
3 changed files
with
29 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,4 @@ Thumbs.db | |
build/ | ||
dist/ | ||
attmap.egg-info/ | ||
|
||
docs/autodoc_build |
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,27 @@ | ||
# Use cases and "how-to..." | ||
|
||
## ...customize a subtype's text rendition | ||
In a subclass, override `_excl_from_repr`, using key and/or type of value. | ||
|
||
The most basic implementation is a no-op, excluding nothing: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
return False | ||
``` | ||
|
||
To exclude by key, though, you can do something like: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
protected = ["reserved_metadata", "REZKEY"] | ||
return k in protected | ||
``` | ||
|
||
To exclude by value type, you can use something like: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
return issubclass(cls, BaseOmissionType) | ||
``` | ||
where `BaseOmissionType` is a proxy for the name of some type of values that may | ||
be stored in your mapping but that you prefer to not display in its text representation. | ||
|
||
The two kinds of exclusion criteria may be combined as desired. |
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