Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError in docs example for KeyValidator #178

Open
jrom99 opened this issue Apr 12, 2022 · 1 comment
Open

NameError in docs example for KeyValidator #178

jrom99 opened this issue Apr 12, 2022 · 1 comment

Comments

@jrom99
Copy link

jrom99 commented Apr 12, 2022

The example code in docs page for Key Validator:

from collections import OrderedDict
from strictyaml import Map, Optional, Str, Seq, load, ScalarValidator

# This example uses slugify from the "python-slugify" package
from slugify import slugify

yaml_snippet = """
Name: United Kingdom
country-code: GB
DIAL CODE: +44
official languages:
- English
- Welsh
"""

class Slug(ScalarValidator):
    def validate_scalar(self, chunk):
        return slugify(unicode(chunk.contents))

schema = Map({
    "name": Str(),
    Optional("country-code"): Str(),
    "dial-code": Str(),
    "official-languages": Seq(Str())
}, key_validator=Slug())

load(yaml_snippet, schema)

raises NameError: name 'unicode' is not defined

Is it supposed to happen? Where should unicode come from?

@crdoconnor
Copy link
Owner

crdoconnor commented Apr 12, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants