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

Slugify blog post examples fail #4452

Closed
5 tasks done
ofek opened this issue Oct 4, 2022 · 6 comments
Closed
5 tasks done

Slugify blog post examples fail #4452

ofek opened this issue Oct 4, 2022 · 6 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@ofek
Copy link
Sponsor Collaborator

ofek commented Oct 4, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Expected behaviour

Docs build

Actual behaviour

ERROR    -  Config value: 'plugins'. Error: Plugin 'blog' value: 'post_slugify'. Error: Expected type: <class 'function'> but received: <class 'functools.partial'>
            Plugin 'blog' value: 'categories_slugify'. Error: Expected type: <class 'function'> but received: <class 'functools.partial'>

Steps to reproduce

mkdocs build

Package versions

  • Python: 3.8.10
  • MkDocs: 1.4.0
  • Material: 8.5.6

Configuration

INHERIT: mkdocs.yml

plugins:
  blog:
    post_slugify: !!python/object/apply:pymdownx.slugs.slugify
      kwds:
        case: lower
    categories_slugify: !!python/object/apply:pymdownx.slugs.slugify
      kwds:
        case: lower

System information

  • Operating system: Windows 10
  • Browser: Chrome
@oprypin
Copy link
Contributor

oprypin commented Oct 4, 2022

I had to do this in order to fix it:

pip install -U pymdown-extensions 

EDIT: ah no, my problem was slightly different, but still might help

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Oct 4, 2022

Tried but already on latest

@facelessuser
Copy link
Contributor

Ideally, the blog plugin would accept a "callable", but since the options seem to require a type(s), you may need to add functools.partial as an additional, accepted type.

@squidfunk
Copy link
Owner

@facelessuser I'm not familiar with functools.partial. Could you clarify what exact change would be necessary to the configuration scheme of the blog plugin?

@facelessuser
Copy link
Contributor

functools.partial is an alternative to using lambda. While lambda is an anonymous function with late evaluation, functools.partial, as stated in the docs is:

The partial() is used for partial function application which “freezes” some portion of a function’s arguments and/or keywords resulting in a new object with a simplified signature.

Anyways, I won't go into details as to why someone may choose functools.partial over lambda, but it is a fairly common way to return functions at times, so probably good to support. Ideally, one would normally just check if the provided object is callable with callable(obj), but since MkDocs is using type objects to validate, you most likely need to do something like:

import functools

post_slugify = opt.Type((type(slugify), functools.partial), default = slugify)

This is my guess after looking quickly at what Material is doing and taking a glance at the MkDocs source. Hopefully, I'm right 🙃.

@squidfunk
Copy link
Owner

Thanks, @facelessuser! My testing shows that the signature you posted works, so the blog and tags plugins don't crash anymore. Fixed in squidfunk/mkdocs-material-insiders@bf0cd1fb7 and released as part of 8.5.6-insiders-4.25.2.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

4 participants