-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
As in subject I'm having an issue that Container objects are not correctly verified just like in below example:
from typing import Any, List, Container
from multimethod import multimethod
@multimethod
def validate_enum_list(key: str, value: Any, allowed_values: Any):
return NotImplemented
@validate_enum_list.register
def _(key: str, value: str, allowed_values: Container[str]) -> None:
print("key: str, value: str, allowed_values: Container[str]")
print(type(value))
print(type(allowed_values))
@validate_enum_list.register
def _(key: str, value: Container[str], allowed_values: Container[Container[str]]) -> None:
print("key: str, value: Container[str], allowed_values: Container[Container[str]]")
print(type(value))
print(type(allowed_values))
validate_enum_list("test1", "test1", ["test1"])
validate_enum_list("test2", ["test2"], [["test2"]])
validate_enum_list("test2", "test2", "test2")According to this the third call of validate_enum_list should not be printed as it returns NotImplemented but instead the otuput looks like:
key: str, value: str, allowed_values: Container[str]
<class 'str'>
<class 'list'>
key: str, value: Container[str], allowed_values: Container[Container[str]]
<class 'list'>
<class 'list'>
key: str, value: str, allowed_values: Container[str]
<class 'str'>
<class 'str'>I have verified that if I will add additional method to serve such case than it's all OK but I wanted to have it served with the NotImplemented pattern. Any better solution how to handle it or maybe there is a bug in multimethod code?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels