Error "TypeError: href() takes 2 positional arguments but 3 were given" when subclassinc Style

Issue #152 new
Johann Petrak created an issue

This is extremely odd: I wanted to implement my own style class, but when I use href, I get an exception.

This happens even if all I do is subclass the original Style and overrdie the format_url method with EXACTLY THE SAME CODE as in the original class. Here is the code to demonstrate this:

from pybtex.database import parse_string
from pybtex.style.formatting.unsrt import Style
from pybtex.style.template import href, field

db = parse_string("""
@techreport{key1,
    author = "Last, First",
    title = "Some title",
    year = "1990",
    institution = "Institution",
    number = "0001",
    type = "Technical Report",
    url = "http://some.url.com"
}
""", "bibtex")
entry = db.entries["key1"]

# This works
Style().format_entry("", entry).text.render_as("html")
# 'First Last.\nSome title.\nTechnical Report 0001, Institution, 1990.\nURL: <a href="http://some.url.com">http://some.url.com</a>.'

class MyStyle(Style):
    # exactly the same is in style.formatting.unsrt!!
    # see https://bitbucket.org/pybtex-devs/pybtex/src/b2a2a4099b0a773bba75862836426d63fb18a2be/pybtex/style/formatting/unsrt.py#lines-423
    def format_url(self, e):
        url = field("url", raw=True)
        return href(url)[ url ]

MyStyle().format_entry("", entry).text.render_as("html")
# Exception: TypeError: href() takes 2 positional arguments but 3 were given

As you can see, MyStyle is identical to Style except for the format_url method which is identical to the method defined in Style!

What is going on here?????

Comments (3)

  1. Log in to comment