Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #112 from jacebrowning/hotfix/v0.7.1
Browse files Browse the repository at this point in the history
Hotfix v0.7.1
  • Loading branch information
jacebrowning committed Mar 30, 2016
2 parents c8f96ab + 7654fdd commit f73cbcc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
@@ -1,5 +1,9 @@
# Revision History

## 0.7.1 (2016/03/30)

- Updated `String` to fetch `true` and `false` as strings.

## 0.7 (2016/03/29)

- Now preserving order of `attr` decorators.
Expand Down
2 changes: 1 addition & 1 deletion yorm/__init__.py
Expand Up @@ -3,7 +3,7 @@
import sys

__project__ = 'YORM'
__version__ = '0.7'
__version__ = '0.7.1'

VERSION = __project__ + '-' + __version__

Expand Down
4 changes: 4 additions & 0 deletions yorm/test/test_types_standard.py
Expand Up @@ -42,10 +42,14 @@ def describe_string():
pairs_to_value = pairs + [
(1, "1"),
(4.2, "4.2"),
(False, "false"),
(True, "true"),
]
pairs_to_data = pairs + [
(42, 42),
(4.2, 4.2),
("true", True),
("false", False),
]

def describe_to_value():
Expand Down
12 changes: 10 additions & 2 deletions yorm/types/standard.py
Expand Up @@ -35,6 +35,10 @@ class String(Object):
def to_value(cls, obj):
if isinstance(obj, cls.TYPE):
return obj
elif obj is True:
return "true"
elif obj is False:
return "false"
elif obj:
try:
return ', '.join(str(item) for item in obj)
Expand All @@ -50,9 +54,13 @@ def to_data(cls, obj):

@staticmethod
def _optimize_for_quoting(value):
for num in (int, float):
if value == "true":
return True
if value == "false":
return False
for number_type in (int, float):
try:
return num(value)
return number_type(value)
except (TypeError, ValueError):
continue
return value
Expand Down

0 comments on commit f73cbcc

Please sign in to comment.