fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] XT undefined in components.py

Open autonomouse opened this issue 9 months ago • 1 comments

XT undefined in components.py in FastHTML 0.12.4

Describe the bug In FastHTML version 0.12.4, there is an error in the components.py file where XT is referenced but not defined. According to the error message, this should be FT based on the library's own suggestion. This appears to be a remnant from a transition from using XT to FT for component types, as mentioned in FastHTML's changelog for version 0.1.10.

The error prevents any application using FastHTML from running, as the import chain fails before any application code can execute. This appears to be a critical issue affecting all users of FastHTML 0.12.4.

Minimal Reproducible Example

from fasthtml.core import fast_app
from fasthtml.xtend import Style

# Initialize the FastHTML app
app, rt = fast_app(
    hdrs=[Style("body { font-family: sans-serif; }")]
)

@rt("/")
def get():
    return "Hello, World!"

if __name__ == "__main__":
    from fasthtml.core import serve
    serve()

When running the above script, the following error occurs:

Traceback (most recent call last):
  File "/path/to/app.py", line 1, in <module>
    from fasthtml.core import fast_app
  File "/path/to/.venv/lib/python3.11/site-packages/fasthtml/__init__.py", line 2, in <module>
    from .core import *
  File "/path/to/.venv/lib/python3.11/site-packages/fasthtml/core.py", line 14, in <module>
    from .xtend import *
  File "/path/to/.venv/lib/python3.11/site-packages/fasthtml/xtend.py", line 15, in <module>
    from .components import *
  File "/path/to/.venv/lib/python3.11/site-packages/fasthtml/components.py", line 85, in <module>
    def fill_form(form:XT, obj)->XT:
                       ^^
NameError: name 'XT' is not defined. Did you mean: 'FT'?

Expected behavior The script should run successfully, starting a FastHTML application without any import errors.

Environment Information Please provide the following version information:

  • fasthtml version: 0.12.4
  • fastcore version: 1.7.29
  • fastlite version: 0.1.2
  • Python version: 3.11
  • Operating system: Linux 6.11.0-18-generic
  • Installation method: pip via uv (uv pip install python-fasthtml)

Confirmation

  • [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 This appears to be a leftover artifact from the transition mentioned in the changelog for version 0.1.10:

## 0.1.10

### Dependencies

* Update for fastcore XT to FT name change

It seems that in components.py, line 85, the type annotation still uses XT instead of FT, but XT is no longer defined in the namespace.

Looking at the error message, the Python interpreter even suggests the correct fix: "Did you mean: 'FT'?", supporting the hypothesis that this is a missed rename.

The fix would likely involve updating the fill_form function signature in components.py from:

def fill_form(form:XT, obj)->XT:

to:

def fill_form(form:FT, obj)->FT:

autonomouse avatar Mar 07 '25 15:03 autonomouse