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

[CSS] Descendant type selectors can't have a numeric in their name #1836

Closed
davep opened this issue Feb 19, 2023 · 1 comment · Fixed by #1837
Closed

[CSS] Descendant type selectors can't have a numeric in their name #1836

davep opened this issue Feb 19, 2023 · 1 comment · Fixed by #1837
Labels
bug Something isn't working

Comments

@davep
Copy link
Contributor

davep commented Feb 19, 2023

Consider the following code:

from textual.app        import App, ComposeResult
from textual.containers import Vertical
from textual.widgets    import Header, Footer, Label

class LabelH1( Label ):
    ...

class CSSOddnessApp( App[ None ] ):

    CSS = """
    Vertical LabelH1 {
        background: red;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical(
            Label( "Label" ),
            LabelH1( "LabelH1" ),
        )
        yield Footer()

if __name__ == "__main__":
    CSSOddnessApp().run()

When run we get the following error:

 Error in stylesheet:
 /Users/davep/develop/python/textual-sandbox/css_oddness.py:CSSOddnessApp:1:19
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ❱ 1 │                                                                                                                                                      │
│   2 │   Vertical LabelH1 {                                                                                                                                 │
│   3 │   │   background: red;                                                                                                                               │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 • Expected one of 'combinator child', 'comment start', 'declaration set start', 'new selector', 'pseudo class', 'selector', 'selector class', 'selector id',
 'selector universal', or 'whitespace'.
 • Did you forget a semicolon at the end of a line?

The same thing happens with Vertical LabelH1. On the other hand, if I remove the number from the inherited label widget:

from textual.app        import App, ComposeResult
from textual.containers import Vertical
from textual.widgets    import Header, Footer, Label

class LabelHOne( Label ):
    ...

class CSSOddnessApp( App[ None ] ):

    CSS = """
    Vertical LabelHOne {
        background: red;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical(
            Label( "Label" ),
            LabelHOne( "LabelHOne" ),
        )
        yield Footer()

if __name__ == "__main__":
    CSSOddnessApp().run()

this works fine. Likewise, if I retain the name but don't use combination:

from textual.app        import App, ComposeResult
from textual.containers import Vertical
from textual.widgets    import Header, Footer, Label

class LabelH1( Label ):
    ...

class CSSOddnessApp( App[ None ] ):

    CSS = """
    LabelH1 {
        background: red;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical(
            Label( "Label" ),
            LabelH1( "LabelH1" ),
        )
        yield Footer()

if __name__ == "__main__":
    CSSOddnessApp().run()

that also works fine.

I would suspect a variation on #1253.

@davep davep added the bug Something isn't working label Feb 19, 2023
davep added a commit to davep/textual-sandbox that referenced this issue Feb 19, 2023
davep added a commit to davep/textual that referenced this issue Feb 19, 2023
davep added a commit that referenced this issue Feb 20, 2023
Allow numbers in descendant-combined type selectors (fix #1836)
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

davep added a commit to davep/textual that referenced this issue Mar 14, 2023
The start of what will hopefully become a one-stop comprehensive test of all
the fun corners of stylesheet parsing. While not intended to replace all the
other unit tests for CSS, this test should help to quickly and easily be
sure that nothing breaks any valid CSS.

Influenced by Textualize#1253 and Textualize#1836 this code starts the process of implementing
the requirement outlined in Textualize#1838.

Adding more rules -- simple and/or weird -- that are expected and known to
parse without a problem is encouraged.
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

Successfully merging a pull request may close this issue.

1 participant