Repository: encode/typesystem

Issue:
Don't echo values back if `format="password"`
Just needs a tweak in `Form.render_field` to set `value=""`, and a test case.

Discussion:

Patch:
diff --git a/docs/schemas.md b/docs/schemas.md
index 4064ca0..b75f524 100644
--- a/docs/schemas.md
+++ b/docs/schemas.md
@@ -105,7 +105,7 @@ print(dict(album))
 Index lookup on schema instances returns serialized datatypes.
 
 ```python
-print(type(album['release_date']))
+print(type(album.release_date))
 # <class 'str'>
 ```
 
diff --git a/typesystem/forms.py b/typesystem/forms.py
index 5035eee..a6d8929 100644
--- a/typesystem/forms.py
+++ b/typesystem/forms.py
@@ -69,6 +69,7 @@ class Form:
         input_type = self.input_type_for_field(field)
         template_name = self.template_for_field(field)
         template = self.env.get_template(template_name)
+        value = "" if input_type == "password" else value
         return template.render(
             {
                 "field_id": field_id,


Test patch:
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 52f8eaf..9bb302f 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -24,6 +24,15 @@ def test_form_rendering():
     assert html.count("<select ") == 1
 
 
+def test_password_rendering():
+    class PasswordForm(typesystem.Schema):
+        password = typesystem.String(format="password")
+
+    form = forms.Form(PasswordForm, values={"password": "secret"})
+    html = str(form)
+    assert "secret" not in html
+
+
 def test_form_html():
     form = forms.Form(Contact)