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

Using 'content' as a metadata key breaks frontmatter #96

Open
harleypig opened this issue Aug 28, 2022 · 4 comments
Open

Using 'content' as a metadata key breaks frontmatter #96

harleypig opened this issue Aug 28, 2022 · 4 comments
Milestone

Comments

@harleypig
Copy link

If I have a file with content as a key in the frontmatter, frontmatter dies a horrible death.

Example markdown file (test.md):

---
content: bad key
---
Ooops!

Example python file (badkey.py):

import frontmatter
post = frontmatter.load('test.md')

When running python badkey.py you get:

$ python badkey.py 
Traceback (most recent call last):
  File "/home/harleypig/work/pfm/badkey.py", line 3, in <module>
    post = frontmatter.load('test.md')
  File "/home/harleypig/.local/lib/python3.10/site-packages/frontmatter/__init__.py", line 150, in load
    return loads(text, encoding, handler, **defaults)
  File "/home/harleypig/.local/lib/python3.10/site-packages/frontmatter/__init__.py", line 166, in loads
    return Post(content, handler, **metadata)
TypeError: Post.__init__() got multiple values for argument 'content'
@merwok
Copy link

merwok commented Aug 28, 2022

To fix this, Python 3.8 added positional-only parameters:

def __init__(self, content, hander, /, **metadata);
    ...

@eyeseast
Copy link
Owner

I've thought about that. Not sure I'm ready to drop Python 3.7 just yet, but it's an option.

@merwok
Copy link

merwok commented Aug 29, 2022

What about __init__(_self, _content, _handler, **metadata) then?

Or alternatively metadata as a dict, without kwarg unpacking?

@eyeseast
Copy link
Owner

The first option is probably better. Second would break backwards compatibility, and I'd rather not do that if I can avoid it.

Also, Python 3.7 has almost a year until EOL, so can't do positional-only arguments just yet.

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

3 participants