Skip to content

Commit 9401cb4

Browse files
committed
simplify
1 parent ef4db84 commit 9401cb4

File tree

3 files changed

+11
-49
lines changed

3 files changed

+11
-49
lines changed

src/textual/_slug.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,9 @@ def slug_for_tcss_id(text: str) -> str:
128128
Returns:
129129
A slugified version of text suitable for use as a TCSS id.
130130
"""
131-
131+
is_valid = VALID_ID_CHARACTERS.__contains__
132132
slug = "".join(
133-
(
134-
character
135-
if character in VALID_ID_CHARACTERS
136-
else ord(character).__format__("x")
137-
)
133+
(character if is_valid(character) else "{:x}".format(ord(character)))
138134
for character in text.casefold().replace(" ", "-")
139135
)
140136
if not slug:

src/textual/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ def render_segments(
12311231
return segments
12321232

12331233
def __rich__(self):
1234+
"""Allow Content to be rendered with rich.print."""
12341235
from rich.segment import Segments
12351236

12361237
return Segments(self.render_segments(Style(), "\n"))

src/textual/getters.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,12 @@
55

66
from __future__ import annotations
77

8-
from typing import Generic, TypeVar, overload
8+
from typing import Generic, overload
99

1010
from textual.css.query import NoMatches, QueryType, WrongType
1111
from textual.dom import DOMNode
1212
from textual.widget import Widget
1313

14-
AppType = TypeVar("AppType", bound="App")
15-
16-
17-
class app(Generic[AppType]):
18-
"""A typed getter for the app.
19-
20-
Example:
21-
```python
22-
class MyWidget(Widget):
23-
app = getters.app(MyApp)
24-
```
25-
26-
27-
Args:
28-
Generic (_type_): _description_
29-
"""
30-
31-
def __init__(self, app_type: type[AppType]) -> None:
32-
self._app_type = app_type
33-
34-
def __get__(self, obj: DOMNode, obj_type: type[DOMNode]) -> AppType:
35-
app = obj.app
36-
assert isinstance(app, self._app_type)
37-
return app
38-
3914

4015
class query_one(Generic[QueryType]):
4116
"""Create a query one property.
@@ -79,23 +54,17 @@ def __init__(self, selector: str) -> None:
7954
Args:
8055
selector: A TCSS selector, e.g. "#mywidget"
8156
"""
82-
self.selector = selector
83-
self.expect_type = Widget
8457

8558
@overload
86-
def __init__(self, selector: type[QueryType]) -> None:
87-
self.selector = selector.__name__
88-
self.expect_type = selector
59+
def __init__(self, selector: type[QueryType]) -> None: ...
8960

9061
@overload
91-
def __init__(self, selector: str, expect_type: type[QueryType]) -> None:
92-
self.selector = selector
93-
self.expect_type = expect_type
62+
def __init__(self, selector: str, expect_type: type[QueryType]) -> None: ...
9463

9564
@overload
96-
def __init__(self, selector: type[QueryType], expect_type: type[QueryType]) -> None:
97-
self.selector = selector.__name__
98-
self.expect_type = expect_type
65+
def __init__(
66+
self, selector: type[QueryType], expect_type: type[QueryType]
67+
) -> None: ...
9968

10069
def __init__(
10170
self,
@@ -165,14 +134,10 @@ def on_mount(self) -> None:
165134
expect_type: type[Widget]
166135

167136
@overload
168-
def __init__(self, child_id: str) -> None:
169-
self.child_id = child_id
170-
self.expect_type = Widget
137+
def __init__(self, child_id: str) -> None: ...
171138

172139
@overload
173-
def __init__(self, child_id: str, expect_type: type[QueryType]) -> None:
174-
self.child_id = child_id
175-
self.expect_type = expect_type
140+
def __init__(self, child_id: str, expect_type: type[QueryType]) -> None: ...
176141

177142
def __init__(
178143
self,

0 commit comments

Comments
 (0)