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

[BUG] multiple values for keyword argument 'xmlns' #464

Open
pyrot23 opened this issue Sep 25, 2024 · 0 comments
Open

[BUG] multiple values for keyword argument 'xmlns' #464

pyrot23 opened this issue Sep 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@pyrot23
Copy link

pyrot23 commented Sep 25, 2024

Important Notice
We do not provide support through GitHub issues. For community-based help, please use either:

If you're reporting a bug, please continue with this template.

Describe the bug
Creating Svg object with the argument "xmlns" will cause TypeError: fasthtml.svg.ft_svg() got multiple values for keyword argument 'xmlns'.
I believe it would be a very common practice to convert svg code to Svg object by using the html2ft tool, which often contains the property xmlns='http://www.w3.org/2000/svg'. In the lastest version of the source code svg.py, this argument is passed through **kwargs. It will cause an argument conflict in line 39 ft_svg('svg', *args, xmlns="http://www.w3.org/2000/svg", viewBox=viewBox, height=height, width=width, **kwargs), since xmlns is explictly given.

This is of course not really a bug, but it would be much convenient to provide an argument check, so a common user don't have to remove this property every time converting a html code to Svg object.

code suggestion

# svg.py line 34
def Svg(*args, viewBox=None, h=None, w=None, height=None, width=None, **kwargs):
    "An SVG tag; xmlns is added automatically, and viewBox defaults to height and width if not provided"
    if h: height=h
    if w: width=w
    if not viewBox and height and width: viewBox=f'0 0 {width} {height}'
    if "xmlns" not in kwargs: kwargs["xmlns"]="http://www.w3.org/2000/svg"
    return ft_svg('svg', *args, viewBox=viewBox, height=height, width=width, **kwargs)

Minimal Reproducible Example
Provide a minimal code snippet that reproduces the issue. This is crucial for us to understand and fix the bug quickly.

Svg(
                        Path(fill_rule='evenodd', d='M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h6a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z', clip_rule='evenodd'),
                        aria_hidden='true',
                        fill='currentColor',
                        viewbox='0 0 20 20',
                        xmlns='http://www.w3.org/2000/svg',
                        cls='w-6 h-6'
                    )

output

    Svg(
  File "/home/mupro/workshop/fasthtml-learn/.venv/lib/python3.12/site-packages/fasthtml/svg.py", line 40, in Svg
    return ft_svg('svg', *args, xmlns="http://www.w3.org/2000/svg", viewBox=viewBox, height=height, width=width, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fasthtml.svg.ft_svg() got multiple values for keyword argument 'xmlns'

Expected behavior
A clear and concise description of what you expected to happen.

Environment Information
Please provide the following version information:

  • fastlite version: 0.0.11
  • fastcore version: 1.7.9
  • fasthtml version: 0.6.8

Confirmation
Please confirm the following:

  • [ x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [x ] I have provided a minimal reproducible example
  • [ x] I have included the versions of fastlite, fastcore, and fasthtml
  • [x ] I understand that this is a volunteer open source project with no commercial support.

Additional context
Add any other context about the problem here.

Screenshots
If applicable, add screenshots to help explain your problem.

@pyrot23 pyrot23 added the bug Something isn't working label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant