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

Type Hints for Python 3.10 #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions sparkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def load_string(self, str):
self._tokenize()
self._parse()

def render(self):
def render(self) -> str:
"""Renders.
Called by [[Router]].
"""
Expand All @@ -401,7 +401,7 @@ def render(self):
# Protected methods
# -------------------------------------------------------------------------

def _textmatify(self, output):
def _textmatify(self, output) -> str:
"""Returns a version of the output with TextMate placeholders in it.
"""

Expand Down Expand Up @@ -539,7 +539,7 @@ def _parse(self):
prefix = ''

# Property: suffix
# (string) The trailing tag at the end.
# (String) The trailing tag at the end.
suffix = ''
pass

Expand Down Expand Up @@ -607,7 +607,7 @@ def __init__(self, token=None, parent=None, count=None, local_count=None,

if self.populate: self._populate()

def render(self):
def render(self) -> str:
"""Renders the element, along with it's subelements, into HTML code.

[Grouped under "Rendering methods"]
Expand Down Expand Up @@ -723,7 +723,7 @@ def render(self):

return output

def get_default_tag(self):
def get_default_tag(self) -> str:
"""Returns the opening tag (without brackets).

Usage:
Expand All @@ -737,13 +737,13 @@ def get_default_tag(self):
output += ' %s="%s"' % (key, value)
return output

def get_opening_tag(self):
def get_opening_tag(self) -> str:
if self.opening_tag is None:
return "<%s>" % self.get_default_tag()
else:
return self.opening_tag

def get_closing_tag(self):
def get_closing_tag(self) -> str:
if self.closing_tag is None:
return "</%s>" % self.name
else:
Expand All @@ -767,7 +767,7 @@ def append(self, object):

self.children.append(object)

def get_last_child(self):
def get_last_child(self) -> 'Element':
"""Returns the last child element which was [[append()]]ed to this element.

Usage:
Expand Down Expand Up @@ -1128,14 +1128,14 @@ def __init__(self, router, argv, options=None):
for k, v in iteritems(options):
self.options[k] = v

def __getattr__(self, attr):
def __getattr__(self, attr) -> dict[str, int | bool] | None:
return self.get(attr)

def get(self, attr):
def get(self, attr) -> dict[str, int | bool] | None:
try: return self.options[attr]
except: return None

def has(self, attr):
def has(self, attr) -> bool:
try: return self.options.has_key(attr)
except: return False

Expand Down