Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for enum type annotations
- Loading branch information
1 parent
392704a
commit 02f2547
Showing
8 changed files
with
136 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# pylint: disable=unused-argument,not-callable | ||
|
||
from ._bases import Converter | ||
|
||
|
||
class Enumeration(Converter): | ||
|
||
ENUM: type = None # type: ignore | ||
|
||
@classmethod | ||
def of_type(cls, enum: type): | ||
name = f'{enum.__name__}Converter' | ||
bases = (cls,) | ||
attributes = {'ENUM': enum} | ||
return type(name, bases, attributes) | ||
|
||
@classmethod | ||
def to_python_value(cls, deserialized_data, *, target_object=None): | ||
return cls.ENUM(deserialized_data) | ||
|
||
@classmethod | ||
def to_preserialization_data(cls, python_value, *, default_to_skip=None): | ||
return python_value.value |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.