Skip to content

Commit 562b91c

Browse files
Remove anonymous fragment for now. (#95)
1 parent ac60da6 commit 562b91c

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,6 @@ result = html(t"<ul><{Items} /></ul>")
385385
assert str(result) == "<ul><li>first</li><li>second</li></ul>"
386386
```
387387

388-
If you prefer, you can use **explicit fragment syntax** to wrap multiple
389-
elements in a `Fragment`:
390-
391-
```python
392-
def Items() -> Node:
393-
return html(t'<><li>first</li><li>second</li></>')
394-
395-
result = html(t'<ul><{Items} /></ul>')
396-
assert str(result) == "<ul><li>first</li><li>second</li></ul>"
397-
```
398-
399-
This is not required, but it can make your intent clearer.
400-
401388
#### Class-based components
402389

403390
Component functions are great for simple use cases, but for more complex

tdom/parser.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from string.templatelib import Interpolation, Template
55

66
from .nodes import VOID_ELEMENTS
7-
from .placeholders import FRAGMENT_TAG, PlaceholderState
7+
from .placeholders import PlaceholderState
88
from .tnodes import (
99
TAttribute,
1010
TComment,
@@ -171,10 +171,6 @@ def make_open_tag(self, tag: str, attrs: t.Sequence[HTMLAttribute]) -> OpenTag:
171171
tag_ref = self.placeholders.remove_placeholders(tag)
172172

173173
if tag_ref.is_literal:
174-
if tag == FRAGMENT_TAG:
175-
if attrs:
176-
raise ValueError("Fragments cannot have attributes.")
177-
return OpenTFragment()
178174
return OpenTElement(tag=tag, attrs=self.make_tattrs(attrs))
179175

180176
if not tag_ref.is_singleton:
@@ -230,11 +226,7 @@ def validate_end_tag(self, tag: str, open_tag: OpenTag) -> int | None:
230226
return None
231227

232228
case OpenTFragment():
233-
if not tag_ref.is_literal:
234-
raise ValueError("Component closing tag found for fragment.")
235-
if tag != FRAGMENT_TAG:
236-
raise ValueError(f"Mismatched closing tag </{tag}> for fragment.")
237-
return None
229+
raise NotImplementedError("We do not support anonymous fragments.")
238230

239231
case OpenTComponent(start_i_index=start_i_index):
240232
if tag_ref.is_literal:
@@ -327,7 +319,7 @@ def get_tnode(self) -> TNode:
327319
if len(self.root.children) > 1:
328320
# The parse structure results in multiple root elements, so we
329321
# return a Fragment to hold them all.
330-
return TFragment(children=tuple(self.root.children))
322+
return self.finalize_tag(self.root)
331323
elif len(self.root.children) == 1:
332324
# The parse structure results in a single root element, so we
333325
# return that element directly. This will be a non-Fragment Node.
@@ -336,16 +328,14 @@ def get_tnode(self) -> TNode:
336328
# Special case: the parse structure is empty; we treat
337329
# this as an empty document fragment.
338330
# CONSIDER: or as an empty text node?
339-
return TFragment(children=tuple())
331+
return self.finalize_tag(self.root)
340332

341333
# ------------------------------------------
342334
# Feeding and parsing
343335
# ------------------------------------------
344336

345337
def feed_str(self, s: str) -> None:
346338
"""Feed a string part of a Template to the parser."""
347-
# TODO: add tracking for this, or maybe just deprecate it?
348-
s = s.replace("<>", f"<{FRAGMENT_TAG}>").replace("</>", f"</{FRAGMENT_TAG}>")
349339
self.feed(s)
350340

351341
def feed_interpolation(self, index: int) -> None:

tdom/placeholders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .template_utils import TemplateRef
66

7-
FRAGMENT_TAG = f"t🐍f-{''.join(random.choices(string.ascii_lowercase, k=4))}-"
7+
88
_PLACEHOLDER_PREFIX = f"t🐍{''.join(random.choices(string.ascii_lowercase, k=2))}-"
99
_PLACEHOLDER_SUFFIX = f"-{''.join(random.choices(string.ascii_lowercase, k=2))}🐍t"
1010
_PLACEHOLDER_PATTERN = re.compile(

0 commit comments

Comments
 (0)