forked from frappe/frappe
-
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.
chore(docref): fix circular imports (frappe#28282)
- Loading branch information
Showing
7 changed files
with
33 additions
and
27 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
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,2 @@ | ||
from .docref import DocRef | ||
from .frappedict import _dict |
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,25 @@ | ||
from typing_extensions import override | ||
|
||
|
||
class DocRef: | ||
"""A lightweight reference to a document, containing just the doctype and name.""" | ||
|
||
def __init__(self, doctype: str, name: str): | ||
self.doctype = doctype | ||
self.name = name | ||
|
||
def __value__(self) -> str: | ||
# Used when requiring its value representation for db interactions, serializations, etc | ||
return self.name | ||
|
||
@override | ||
def __hash__(self) -> int: | ||
return hash(self.doctype + self.name or "") | ||
|
||
@override | ||
def __str__(self) -> str: | ||
return f"{self.doctype} ({self.name or 'n/a'})" | ||
|
||
@override | ||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}: doctype={self.doctype} name={self.name or 'n/a'}>" |