[PATCH 18 of 23 yams] [mod] force string convertion to please mypy

Laurent Peuch cortex at worlddomination.be
Fri Feb 14 16:00:08 CET 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1581689236 -3600
#      Fri Feb 14 15:07:16 2020 +0100
# Node ID c2fd360f320a8ae2f06c72960732f3eee5de29bb
# Parent  b7d7e49aa8122f0c87713de670d01353639acdab
# Available At https://hg.logilab.org/users/lpeuch/yams
#              hg pull https://hg.logilab.org/users/lpeuch/yams -r c2fd360f320a
[mod] force string convertion to please mypy

Right now it's working because we are doing magic in __eq__ to behave like
string so this modification doesn't change the code behavior but that makes it
more explicit and avoid doing dirty things with typing.

diff --git a/yams/__init__.py b/yams/__init__.py
--- a/yams/__init__.py
+++ b/yams/__init__.py
@@ -108,7 +108,7 @@ def convert_default_value(rdef: _RdefRde
         # including things that look like keywords for other base types
         if rdef.object in KEYWORD_MAP:
             try:
-                return KEYWORD_MAP[rdef.object][default.upper()]()
+                return KEYWORD_MAP[str(rdef.object)][default.upper()]()
             except KeyError:
                 # the default was likely not a special constant
                 # like TODAY but some literal
@@ -125,11 +125,11 @@ def convert_default_value(rdef: _RdefRde
 
             try:
                 if rdef.object == "Time":
-                    cast(Callable[[str], float], DATE_FACTORY_MAP[rdef.object])
-                    return DATE_FACTORY_MAP[rdef.object](default)
+                    cast(Callable[[str], float], DATE_FACTORY_MAP[str(rdef.object)])
+                    return DATE_FACTORY_MAP[str(rdef.object)](default)
                 else:
-                    cast(Callable[[str], datetime], DATE_FACTORY_MAP[rdef.object])
-                    return DATE_FACTORY_MAP[rdef.object](default)
+                    cast(Callable[[str], datetime], DATE_FACTORY_MAP[str(rdef.object)])
+                    return DATE_FACTORY_MAP[str(rdef.object)](default)
 
             except ValueError as verr:
                 raise ValueError('creating a default value for '



More information about the cubicweb-devel mailing list