fix: type narrowing (#28673)
This commit is contained in:
parent
a390992408
commit
d3cbd2d4be
2 changed files with 12 additions and 9 deletions
|
|
@ -16,14 +16,17 @@ class DocRef:
|
|||
|
||||
@override
|
||||
def __hash__(self: Union[type, "DocRef"]) -> int:
|
||||
if isinstance(self, DocRef):
|
||||
if self.name:
|
||||
return hash(self.doctype + self.name)
|
||||
else:
|
||||
raise TypeError(
|
||||
f"Only named documents can be hashed; maybe the document ({self.doctype}) is unsaved."
|
||||
)
|
||||
raise TypeError("Only document instances can be hashed.")
|
||||
if isinstance(self, type):
|
||||
raise TypeError("Only document instances can be hashed.")
|
||||
try:
|
||||
name = self.name
|
||||
except AttributeError:
|
||||
raise TypeError("Partially instantiated document instances can't be hashed.")
|
||||
if name:
|
||||
return hash(self.doctype + name)
|
||||
raise TypeError(
|
||||
f"Only named documents can be hashed; maybe the document ({self.doctype}) is unsaved."
|
||||
)
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ test = [
|
|||
"coverage~=6.5.0",
|
||||
"Faker~=18.10.1",
|
||||
"hypothesis~=6.77.0",
|
||||
"freezegun~=1.2.2",
|
||||
"freezegun~=1.5.1",
|
||||
"pdbpp~=0.10.3",
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue