-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
NamedStyles
and some other base classes
- Loading branch information
1 parent
3a8818a
commit 6cfab68
Showing
8 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,5 @@ | |
|
||
# Style | ||
'Style', | ||
'NamedStyles', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
# Style | ||
'PythonStyle', | ||
'SpacesStyle', | ||
'IntelliJ', | ||
|
||
# Formatter | ||
'AutoFormat', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Protocol | ||
from dataclasses import dataclass | ||
from typing import Protocol, TypeVar, Type, Iterable, Optional, Set | ||
from uuid import UUID | ||
|
||
from rewrite import Marker | ||
|
||
|
||
class Style(Protocol): | ||
def merge(self, lower_precedence: Style) -> Style: | ||
... | ||
return self | ||
|
||
def apply_defaults(self) -> Style: | ||
return self | ||
|
||
|
||
S = TypeVar('S', bound=Style) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class NamedStyles(Marker): | ||
_id: UUID | ||
_name: str | ||
_display_name: str | ||
_description: Optional[str] | ||
_tags: Set[str] | ||
_styles: Iterable[Style] | ||
|
||
@classmethod | ||
def merge(cls, style_type: Type[S], named_styles: Iterable[NamedStyles]) -> Optional[S]: | ||
merged = None | ||
for named_style in named_styles: | ||
styles = named_style._styles | ||
if styles is not None: | ||
for style in styles: | ||
if isinstance(style, style_type): | ||
style = style.apply_defaults() | ||
if merged is None: | ||
merged = style | ||
else: | ||
merged = merged.merge(style) | ||
return merged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters