-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #665 from Ananya2001-an/refactor-python-add-type-h…
…ints
- Loading branch information
Showing
7 changed files
with
55 additions
and
52 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
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,7 +1,9 @@ | ||
from typing import Optional | ||
|
||
class {{spec.title | caseUcfirst}}Exception(Exception): | ||
def __init__(self, message, code = 0, type = None, response = None): | ||
def __init__(self, message: str, code: int = 0, type: Optional[str] = None, response: Optional[dict] = None): | ||
self.message = message | ||
self.code = code | ||
self.type = type | ||
self.response = response | ||
super().__init__(self.message) | ||
super().__init__(self.message) |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ class ID: | |
|
||
@staticmethod | ||
def unique(): | ||
return 'unique()' | ||
return 'unique()' |
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,21 +1,21 @@ | ||
class Permission: | ||
|
||
@staticmethod | ||
def read(role): | ||
def read(role) -> str: | ||
return f'read("{role}")' | ||
|
||
@staticmethod | ||
def write(role): | ||
def write(role) -> str: | ||
return f'write("{role}")' | ||
|
||
@staticmethod | ||
def create(role): | ||
def create(role) -> str: | ||
return f'create("{role}")' | ||
|
||
@staticmethod | ||
def update(role): | ||
def update(role) -> str: | ||
return f'update("{role}")' | ||
|
||
@staticmethod | ||
def delete(role): | ||
def delete(role) -> str: | ||
return f'delete("{role}")' |
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,92 +1,92 @@ | ||
class Query: | ||
@staticmethod | ||
def equal(attribute, value): | ||
def equal(attribute, value) -> str: | ||
return Query.add_query(attribute, "equal", value) | ||
|
||
@staticmethod | ||
def not_equal(attribute, value): | ||
def not_equal(attribute, value) -> str: | ||
return Query.add_query(attribute, "notEqual", value) | ||
|
||
@staticmethod | ||
def less_than(attribute, value): | ||
def less_than(attribute, value) -> str: | ||
return Query.add_query(attribute, "lessThan", value) | ||
|
||
@staticmethod | ||
def less_than_equal(attribute, value): | ||
def less_than_equal(attribute, value) -> str: | ||
return Query.add_query(attribute, "lessThanEqual", value) | ||
|
||
@staticmethod | ||
def greater_than(attribute, value): | ||
def greater_than(attribute, value) -> str: | ||
return Query.add_query(attribute, "greaterThan", value) | ||
|
||
@staticmethod | ||
def greater_than_equal(attribute, value): | ||
def greater_than_equal(attribute, value) -> str: | ||
return Query.add_query(attribute, "greaterThanEqual", value) | ||
|
||
@staticmethod | ||
def is_null(attribute): | ||
def is_null(attribute) -> str: | ||
return f'isNull("{attribute}")' | ||
|
||
@staticmethod | ||
def is_not_null(attribute): | ||
def is_not_null(attribute) -> str: | ||
return f'isNotNull("{attribute}")' | ||
|
||
@staticmethod | ||
def between(attribute, start, end): | ||
def between(attribute, start, end) -> str: | ||
return Query.add_query(attribute, "between", [start, end]) | ||
|
||
@staticmethod | ||
def starts_with(attribute, value): | ||
def starts_with(attribute, value) -> str: | ||
return Query.add_query(attribute, "startsWith", value) | ||
|
||
@staticmethod | ||
def ends_with(attribute, value): | ||
def ends_with(attribute, value) -> str: | ||
return Query.add_query(attribute, "endsWith", value) | ||
|
||
@staticmethod | ||
def select(attributes): | ||
def select(attributes) -> str: | ||
return f'select([{",".join(map(Query.parseValues, attributes))}])' | ||
|
||
@staticmethod | ||
def search(attribute, value): | ||
def search(attribute, value) -> str: | ||
return Query.add_query(attribute, "search", value) | ||
|
||
@staticmethod | ||
def order_asc(attribute): | ||
def order_asc(attribute) -> str: | ||
return f'orderAsc("{attribute}")' | ||
|
||
@staticmethod | ||
def order_desc(attribute): | ||
def order_desc(attribute) -> str: | ||
return f'orderDesc("{attribute}")' | ||
|
||
@staticmethod | ||
def cursor_before(id): | ||
def cursor_before(id) -> str: | ||
return f'cursorBefore("{id}")' | ||
|
||
@staticmethod | ||
def cursor_after(id): | ||
def cursor_after(id) -> str: | ||
return f'cursorAfter("{id}")' | ||
|
||
@staticmethod | ||
def limit(limit): | ||
def limit(limit) -> str: | ||
return f'limit({limit})' | ||
|
||
@staticmethod | ||
def offset(offset): | ||
def offset(offset) -> str: | ||
return f'offset({offset})' | ||
|
||
@staticmethod | ||
def add_query(attribute, method, value): | ||
def add_query(attribute, method, value) -> str: | ||
if type(value) == list: | ||
return f'{method}("{attribute}", [{",".join(map(Query.parseValues, value))}])' | ||
else: | ||
return f'{method}("{attribute}", [{Query.parseValues(value)}])' | ||
|
||
@staticmethod | ||
def parseValues(value): | ||
def parseValues(value) -> str: | ||
if type(value) == str: | ||
return f'"{value}"' | ||
elif type(value) == bool: | ||
return str(value).lower() | ||
else: | ||
return str(value) | ||
return str(value) |
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,30 +1,30 @@ | ||
class Role: | ||
@staticmethod | ||
def any(): | ||
def any() -> str: | ||
return 'any' | ||
|
||
@staticmethod | ||
def user(id, status = ""): | ||
def user(id, status: str = "") -> str: | ||
if status: | ||
return f'user:{id}/{status}' | ||
return f'user:{id}' | ||
|
||
@staticmethod | ||
def users(status = ""): | ||
def users(status: str = "") -> str: | ||
if status: | ||
return f'users/{status}' | ||
return 'users' | ||
|
||
@staticmethod | ||
def guests(): | ||
def guests() -> str: | ||
return 'guests' | ||
|
||
@staticmethod | ||
def team(id, role = ""): | ||
def team(id, role: str = "") -> str: | ||
if role: | ||
return f'team:{id}/{role}' | ||
return f'team:{id}' | ||
|
||
@staticmethod | ||
def member(id): | ||
return f'member:{id}' | ||
def member(id) -> str: | ||
return f'member:{id}' |