[BUG] multiple values for keyword argument 'xmlns'
Opened this issue · 0 comments
Important Notice
We do not provide support through GitHub issues. For community-based help, please use either:
- GitHub Discussions tab
- Our Discord channel
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.