Skip to content

Commit

Permalink
Type stub improvements
Browse files Browse the repository at this point in the history
* Remove default values from instance attributes and globals
* Remove collection super classes, rely on protocols
* Remove quotes around forward references
* Derive classes from object
* Fix argument type of __getattr__()
* Fix a non-ellipsis default value
  • Loading branch information
srittau committed Jul 28, 2018
1 parent 33ff90e commit b8d8654
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 107 deletions.
30 changes: 15 additions & 15 deletions htmlgen/document.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ from typing import Any, Optional, Union
from htmlgen.element import Element, NonVoidElement, VoidElement
from htmlgen.generator import Generator

MIME_JAVASCRIPT: str = ...
MIME_JSON: str = ...
MIME_JAVASCRIPT: str
MIME_JSON: str

class Document(Generator):
root: HTMLRoot = ...
title: str = ...
root: HTMLRoot
title: str
def __init__(self, title: Optional[str] = ..., language: str = ...) -> None: ...
def add_stylesheets(self, *stylesheets: str) -> None: ...
def add_stylesheet(self, stylesheet: str) -> None: ...
Expand All @@ -18,12 +18,12 @@ class Document(Generator):
def append_body(self, child: Union[str, bytes, Generator]) -> None: ...

class HTMLRoot(NonVoidElement):
head: Head = ...
body: Body = ...
head: Head
body: Body
def __init__(self, title: Optional[str] = ..., language: str = ...) -> None: ...

class Head(Element):
title: Title = ...
title: Title
def __init__(self, title: Optional[str] = ...) -> None: ...
def add_stylesheets(self, *stylesheets: str) -> None: ...
def add_stylesheet(self, stylesheet: str) -> None: ...
Expand All @@ -34,28 +34,28 @@ class Body(Element):
def __init__(self) -> None: ...

class Title(NonVoidElement):
title: str = ...
title: str
def __init__(self, title: Optional[str] = ...) -> None: ...

class Meta(VoidElement):
def __init__(self) -> None: ...
@classmethod
def create_charset(cls, charset: str) -> "Meta": ...
def create_charset(cls, charset: str) -> Meta: ...

class Script(NonVoidElement):
url: Optional[str] = ...
script: Optional[str] = ...
type: str = ...
url: Optional[str]
script: Optional[str]
type: str
def __init__(self, url: Optional[str] = ..., script: Optional[str] = ...) -> None: ...

def json_script(json: Any) -> Script: ...

class HeadLink(VoidElement):
relation: str = ...
url: str = ...
relation: str
url: str
def __init__(self, relation: str, url: str) -> None: ...
@classmethod
def create_stylesheet(cls, stylesheet: str) -> "HeadLink": ...
def create_stylesheet(cls, stylesheet: str) -> HeadLink: ...

class Main(Element):
def __init__(self) -> None: ...
15 changes: 7 additions & 8 deletions htmlgen/element.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import collections
import typing
from typing import Any, Mapping, MutableMapping, Union, TypeVar, Set, Optional, \
Generator as TGenerator, overload
from typing import Any, Mapping, Union, TypeVar, Set, Optional, overload

from htmlgen.generator import Generator, HTMLChildGenerator

_T = TypeVar("_T")

def is_element(o: Any, element_name: str) -> bool: ...

class _ElementDataProxy(MutableMapping[str, str]):
class _ElementDataProxy:
def __init__(self, element: _ElementBase) -> None: ...
def __iter__(self) -> TGenerator[str, None, None]: ...
def __iter__(self) -> typing.Generator[str, None, None]: ...
def __len__(self) -> int: ...
def __setitem__(self, key: str, value: str) -> None: ...
def __getitem__(self, key: str) -> str: ...
Expand All @@ -21,8 +20,8 @@ class _ElementDataProxy(MutableMapping[str, str]):
def from_data(cls, element: _ElementBase, data: Mapping[str, str]) -> _ElementDataProxy: ...

class _ElementBase(Generator):
id: Optional[str] = ...
element_name: str = ...
id: Optional[str]
element_name: str

@property
def data(self) -> _ElementDataProxy: ...
Expand All @@ -48,10 +47,10 @@ class NonVoidElement(_ElementBase):
def generate_children(self) -> typing.Generator[Union[str, bytes, Generator], None, None]: ...

class Element(NonVoidElement, collections.Sized):
children: HTMLChildGenerator = ...
children: HTMLChildGenerator
def __init__(self, element_name: str) -> None: ...
def __bool__(self) -> bool: ...
def __getattr__(self, item: Any) -> Any: ...
def __getattr__(self, item: str) -> Any: ...
def __len__(self) -> int: ...
def __nonzero__(self) -> bool: ...

Expand Down
94 changes: 47 additions & 47 deletions htmlgen/form.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ from htmlgen.generator import Generator


class Form(Element):
method: str = ...
url: str = ...
target: str = ...
encryption_type: str = ...
multipart: bool = ...
method: str
url: str
target: str
encryption_type: str
multipart: bool
def __init__(self, method: str = ..., url: str = ...) -> None: ...
def set_blank_target(self) -> None: ...

class Input(VoidElement):
name: str = ...
value: str = ...
readonly: bool = ...
disabled: bool = ...
type: str = ...
placeholder: Optional[str] = ...
size: Optional[int] = ...
focus: bool = ...
name: str
value: str
readonly: bool
disabled: bool
type: str
placeholder: Optional[str]
size: Optional[int]
focus: bool
def __init__(self, type_: str = ..., name: str = ...) -> None: ...

class TextInput(Input):
Expand All @@ -35,76 +35,76 @@ class PasswordInput(Input):
def __init__(self, name: str = ...) -> None: ...

class NumberInput(Input):
number: Optional[float] = ...
minimum: Optional[float] = ...
maximum: Optional[float] = ...
step: Optional[float] = ...
number: Optional[float]
minimum: Optional[float]
maximum: Optional[float]
step: Optional[float]
def __init__(self, name: str = ..., number: Optional[float] = ...) -> None: ...

class DateInput(Input):
date: Optional[datetime.date] = ...
date: Optional[datetime.date]
def __init__(self, name: str = ..., date: Optional[datetime.date] = ...) -> None: ...

class TimeInput(Input):
time: Optional[datetime.time] = ...
minimum: Optional[datetime.time] = ...
maximum: Optional[datetime.time] = ...
step: Optional[float] = ...
time: Optional[datetime.time]
minimum: Optional[datetime.time]
maximum: Optional[datetime.time]
step: Optional[float]
def __init__(self, name: str = "", time: Optional[datetime.time] = ...) -> None: ...

class Checkbox(Input):
checked: bool = ...
checked: bool
def __init__(self, name: str = ..., value: str = ...) -> None: ...

class RadioButton(Input):
checked: bool = ...
checked: bool
def __init__(self, name: str = ..., value: str = ...) -> None: ...

class FileInput(Input):
max_length: Optional[int] = ...
accept: List[str] = ...
max_length: Optional[int]
accept: List[str]
def __init__(self, name: str = ...) -> None: ...

class HiddenInput(Input):
def __init__(self, name: str, value: str) -> None: ...

class SubmitButton(Input):
label: str = ...
label: str
def __init__(self, label: str) -> None: ...

class Button(Element):
def __init__(self, *content: Union[str, bytes, Generator]) -> None: ...

class TextArea(Element):
name: str = ...
readonly: bool = ...
disabled: bool = ...
columns: Optional[int] = ...
rows: Optional[int] = ...
placeholder: Optional[str] = ...
name: str
readonly: bool
disabled: bool
columns: Optional[int]
rows: Optional[int]
placeholder: Optional[str]
def __init__(self, name: str = ...) -> None: ...

class Select(Element):
name: str = ...
disabled: bool = ...
selected_option: Optional[Option] = ...
selected_value: Optional[str] = ...
def __init__(self, name: str = "") -> None: ...
def create_group(self, label: str) -> "OptionGroup": ...
def create_option(self, label: str, value: Optional[str] = ..., selected: bool = ...) -> "Option": ...
name: str
disabled: bool
selected_option: Optional[Option]
selected_value: Optional[str]
def __init__(self, name: str = ...) -> None: ...
def create_group(self, label: str) -> OptionGroup: ...
def create_option(self, label: str, value: Optional[str] = ..., selected: bool = ...) -> Option: ...

class OptionGroup(Element):
label: Optional[str] = ...
disabled: bool = ...
label: Optional[str]
disabled: bool
def __init__(self, label: str) -> None: ...
def create_option(self, label: str, value: Optional[str] = ...) -> "Option": ...
def create_option(self, label: str, value: Optional[str] = ...) -> Option: ...

class Option(Element):
value: Optional[str] = ...
disabled: bool = ...
selected: bool = ...
value: Optional[str]
disabled: bool
selected: bool
def __init__(self, label: str, value: Optional[str] = None) -> None: ...

class Label(Element):
for_: Optional[str] = ...
for_: Optional[str]
def __init__(self, *children: Union[str, bytes, Generator]) -> None: ...
9 changes: 4 additions & 5 deletions htmlgen/generator.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import collections
import typing
from typing import Union, Iterator, Optional, List, Iterable

class Generator(collections.Iterable):
class Generator(object):
def __iter__(self) -> Iterator[bytes]: ...
def __str__(self) -> str: ...
def generate(self) -> typing.Generator[Union[str, bytes, "Generator"], None, None]: ...
def generate(self) -> typing.Generator[Union[str, bytes, Generator], None, None]: ...

class NullGenerator(Generator):
...

class IteratorGenerator(Generator):
def __init__(self, iterator: Iterable[Union[str, bytes, Generator]]) -> None: ...

class ChildGenerator(Generator, collections.Sized):
class ChildGenerator(Generator):
def __init__(self) -> None: ...
def __len__(self) -> int: ...
def append(self, child: Optional[Union[str, bytes, Generator]]) -> None: ...
Expand All @@ -23,7 +22,7 @@ class ChildGenerator(Generator, collections.Sized):
@property
def children(self) -> List[Union[str, bytes, Generator]]: ...

class HTMLChildGenerator(Generator, collections.Sized):
class HTMLChildGenerator(Generator):
def __init__(self) -> None: ...
def __len__(self) -> int: ...
def append(self, child: Optional[Union[str, bytes, Generator]]) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions htmlgen/image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from .element import VoidElement


class Image(VoidElement):
url: str = ...
alternate_text: Optional[str] = ...
title: Optional[str] = ...
url: str
alternate_text: Optional[str]
title: Optional[str]
def __init__(self, url: str, alternate_text: Optional[str] = ...) -> None: ...
6 changes: 3 additions & 3 deletions htmlgen/link.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ from htmlgen.generator import Generator


class Link(Element):
url: Optional[str] = ...
target: str = ...
title: Optional[str] = ...
url: Optional[str]
target: str
title: Optional[str]
def __init__(self, url: Optional[str], *content: Union[str, bytes, Generator]) -> None: ...
def set_blank_target(self) -> None: ...
6 changes: 3 additions & 3 deletions htmlgen/list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ from htmlgen.generator import Generator


class _ListBase(Element):
def create_item(self, child: Optional[Union[str, bytes, Generator]] = ...) -> "ListItem": ...
def create_items(self, *items: Optional[Union[str, bytes, Generator]]) -> List["ListItem"]: ...
def create_item(self, child: Optional[Union[str, bytes, Generator]] = ...) -> ListItem: ...
def create_items(self, *items: Optional[Union[str, bytes, Generator]]) -> List[ListItem]: ...

class OrderedList(_ListBase):
start: int = ...
start: int
def __init__(self) -> None: ...

class UnorderedList(_ListBase):
Expand Down
1 change: 0 additions & 1 deletion htmlgen/structure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class Footer(Element):
def __init__(self) -> None: ...

class Heading(Element):

def __init__(self, level: int = ..., *content: Union[str, bytes, Generator]) -> None: ...
Loading

0 comments on commit b8d8654

Please sign in to comment.