Skip to content

Add pony stubs #14361

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"stubs/peewee",
"stubs/pexpect",
"stubs/pika",
"stubs/pony",
"stubs/protobuf",
"stubs/psutil",
"stubs/psycopg2",
Expand Down
14 changes: 14 additions & 0 deletions stubs/pony/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tests should not be part of the stubs
pony.orm.tests.*

# Modules with ImportError, cannot import third-party libraries:
pony.flask.*
pony.orm.dbproviders.cockroach
pony.orm.dbproviders.mysql
pony.orm.dbproviders.oracle
pony.orm.dbproviders.postgres
pony.orm.integration.bottle_plugin
pony.orm.examples.bottle_example

# TODO: Incomplete issues in examples dir:
pony.orm.examples.*
3 changes: 3 additions & 0 deletions stubs/pony/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "0.7.*"
upstream_repository = "https://github.com/ponyorm/pony"
requires = ["types-psycopg2", "types-PyMySQL"]
14 changes: 14 additions & 0 deletions stubs/pony/pony/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Final, Literal
from typing_extensions import TypeAlias

_Mode: TypeAlias = Literal[
"GAE-LOCAL", "GAE-SERVER", "MOD_WSGI", "INTERACTIVE", "FCGI-FLUP", "UWSGI", "FLASK", "CHERRYPY", "BOTTLE", "UNKNOWN"
]
__version__: Final[str]

def detect_mode() -> _Mode: ...

MODE: Final[_Mode]
MAIN_FILE: Final[str | None]
MAIN_DIR: Final[str | None]
PONY_DIR: Final[str]
48 changes: 48 additions & 0 deletions stubs/pony/pony/converting.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import re
from _typeshed import ConvertibleToInt
from collections.abc import Callable, Sequence
from datetime import date, datetime, time, timedelta
from typing import Any, Literal

class ValidationError(ValueError): ...

def check_ip(s: str) -> str: ...
def check_positive(s: ConvertibleToInt) -> int: ...
def check_identifier(s: str) -> str: ...

isbn_re: re.Pattern[str]

def isbn10_checksum(digits: Sequence[ConvertibleToInt]) -> str: ...
def isbn13_checksum(digits: Sequence[ConvertibleToInt]) -> str: ...
def check_isbn(s: str, convert_to: Literal[10, 13] | None = None) -> str: ...
def isbn10_to_isbn13(s: str) -> str: ...
def isbn13_to_isbn10(s: str) -> str: ...

email_re: re.Pattern[str]
rfc2822_email_re: re.Pattern[str]

def check_email(s: str) -> str: ...
def check_rfc2822_email(s: str) -> str: ...

date_str_list: list[str]
date_re_list: list[re.Pattern[str]]
time_str: str
time_re: re.Pattern[str]
datetime_re_list: list[re.Pattern[str]]
month_lists: list[list[str]]
month_list: list[str]
i: int
month: str
month_dict: dict[str, int]

def str2date(s: str) -> date: ...
def str2time(s: str) -> time: ...
def str2datetime(s: str) -> datetime: ...
def str2timedelta(s: str) -> timedelta: ...
def timedelta2str(td: timedelta) -> str: ...

converters: dict[type | str, tuple[Callable[[str], Any], type[str], str | None]] # Any type from types above

def str2py(
value: str, type: str | type | tuple[Callable[[str], Any], type[str], str | None] | None
) -> Any: ... # Any type from types above
17 changes: 17 additions & 0 deletions stubs/pony/pony/flask/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from _typeshed import Incomplete
from types import ModuleType
from typing import Protocol

# Protocol for flask.Flask class
class _Flask(Protocol):
def before_request(self, f): ...
def after_request(self, f): ...
def teardown_request(self, f): ...

flask_lib: ModuleType
request: Incomplete

class Pony:
app: _Flask | None
def __init__(self, app: _Flask | None = None) -> None: ...
def init_app(self, app: _Flask) -> None: ...
Empty file.
8 changes: 8 additions & 0 deletions stubs/pony/pony/flask/example/app.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from _typeshed import Incomplete

from pony.flask import _Flask

app: _Flask
login_manager: Incomplete

def load_user(user_id): ...
1 change: 1 addition & 0 deletions stubs/pony/pony/flask/example/config.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config: dict[str, bool | str | dict[str, str | bool]]
10 changes: 10 additions & 0 deletions stubs/pony/pony/flask/example/models.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from datetime import datetime

from pony.orm.core import Database, Entity

db: Database

class User(Entity):
login: str
password: str
last_login: datetime | None
4 changes: 4 additions & 0 deletions stubs/pony/pony/flask/example/views.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def index() -> str: ...
def login(): ...
def reg(): ...
def logout(): ...
39 changes: 39 additions & 0 deletions stubs/pony/pony/options.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import Final

DEBUG: Final[bool]
STATIC_DIR: Final[None]
CUT_TRACEBACK: Final[bool]
STD_DOCTYPE: Final[str]
STD_STYLESHEETS: Final[list[tuple[str, ...]]]
BASE_STYLESHEETS_PLACEHOLDER: Final[str]
COMPONENT_STYLESHEETS_PLACEHOLDER: Final[str]
SCRIPTS_PLACEHOLDER: Final[str]
RELOADING_CHECK_INTERVAL: Final[float]
LOG_TO_SQLITE: Final[None]
LOGGING_LEVEL: Final[None]
LOGGING_PONY_LEVEL: Final[None]
MAX_SESSION_CTIME: Final[int]
MAX_SESSION_MTIME: Final[int]
MAX_LONGLIFE_SESSION: Final[int]
COOKIE_SERIALIZATION_TYPE: Final[str]
COOKIE_NAME: Final[str]
COOKIE_PATH: Final[str]
COOKIE_DOMAIN: Final[None]
HASH_ALGORITHM: Final[None]
SESSION_STORAGE: Final[None]
MEMCACHE: Final[None]
ALTERNATIVE_SESSION_MEMCACHE: Final[None]
ALTERNATIVE_ORM_MEMCACHE: Final[None]
ALTERNATIVE_TEMPLATING_MEMCACHE: Final[None]
ALTERNATIVE_RESPONSE_MEMCACHE: Final[None]
PICKLE_START_OFFSET: Final[int]
PICKLE_HTML_AS_PLAIN_STR: Final[bool]
RESTORE_ESCAPES: Final[bool]
SOURCE_ENCODING: Final[None]
CONSOLE_ENCODING: Final[None]
MAX_FETCH_COUNT: Final[None]
CONSOLE_WIDTH: Final[int]
SIMPLE_ALIASES: Final[bool]
INNER_JOIN_SYNTAX: Final[bool]
DEBUGGING_REMOVE_ADDR: Final[bool]
DEBUGGING_RESTORE_ESCAPES: Final[bool]
1 change: 1 addition & 0 deletions stubs/pony/pony/orm/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pony.orm.core import *
139 changes: 139 additions & 0 deletions stubs/pony/pony/orm/asttranslation.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import ast
import sys
from _typeshed import Incomplete
from collections.abc import Callable, Generator
from typing import Any, TypeVar

_T = TypeVar("_T")

class TranslationError(Exception): ...

pre_method_caches: dict[type[ASTTranslator], dict[type[ast.AST], Callable[..., Any]]]
post_method_caches: dict[type[ASTTranslator], dict[type[ast.AST], Callable[..., Any]]]

class ASTTranslator:
tree: Incomplete
def __init__(translator, tree) -> None: ...
def dispatch(translator, node: ast.AST) -> None: ...
def call(translator, method: Callable[[ASTTranslator, ast.AST], _T], node: ast.AST) -> _T | None: ...
def default_pre(translator, node: ast.AST) -> None: ...
def default_post(translator, node: ast.AST) -> None: ...

def priority(p: int): ...
def binop_src(op: str, node) -> str: ...
def ast2src(tree): ...
def get_child_nodes(node: ast.AST) -> Generator[ast.AST]: ...

class PythonTranslator(ASTTranslator):
def __init__(translator, tree) -> None: ...
def call(translator, method, node) -> None: ...
def default_pre(translator, node: ast.AST): ...
def default_post(translator, node: ast.AST) -> None: ...
def postGeneratorExp(translator, node: ast.GeneratorExp) -> str: ...
def postcomprehension(translator, node: ast.comprehension) -> str: ...
def postGenExprIf(translator, node) -> str: ...
def postExpr(translator, node: ast.Expr) -> str: ...
def postIfExp(translator, node: ast.IfExp) -> str: ...
def postLambda(translator, node: ast.Lambda) -> str: ...
def postarguments(translator, node: ast.arguments) -> str: ...
def postarg(translator, node: ast.arg) -> str: ...
def postOr(translator, node: ast.Or) -> str: ...
def postAnd(translator, node: ast.And) -> str: ...
def postNot(translator, node: ast.Not) -> str: ...
def postCompare(translator, node: ast.Compare) -> str: ...
def postEq(translator, node: ast.Eq) -> str: ...
def postNotEq(translator, node: ast.NotEq) -> str: ...
def postLt(translator, node: ast.Lt) -> str: ...
def postLtE(translator, node: ast.LtE) -> str: ...
def postGt(translator, node: ast.Gt) -> str: ...
def postGtE(translator, node: ast.GtE) -> str: ...
def postIs(translator, node: ast.Is) -> str: ...
def postIsNot(translator, node: ast.IsNot) -> str: ...
def postIn(translator, node: ast.In) -> str: ...
def postNotIn(translator, node: ast.NotIn) -> str: ...
def postBitOr(translator, node: ast.BitOr) -> str: ...
def postBitXor(translator, node: ast.BitXor) -> str: ...
def postBitAnd(translator, node: ast.BitAnd) -> str: ...
def postLShift(translator, node: ast.LShift) -> str: ...
def postRShift(translator, node: ast.RShift) -> str: ...
def postAdd(translator, node: ast.Add) -> str: ...
def postSub(translator, node: ast.Sub) -> str: ...
def postMult(translator, node: ast.Mult): ...
def postMatMult(translator, node: ast.MatMult) -> None: ...
def postDiv(translator, node: ast.Div) -> str: ...
def postFloorDiv(translator, node: ast.FloorDiv) -> str: ...
def postMod(translator, node: ast.Mod) -> str: ...
def postUSub(translator, node: ast.USub) -> str: ...
def postUAdd(translator, node: ast.UAdd) -> str: ...
def postInvert(translator, node: ast.Invert) -> str: ...
def postPow(translator, node: ast.Pow) -> str: ...
def postAttribute(translator, node: ast.Attribute) -> str: ...
def postCall(translator, node: ast.Call) -> str: ...
def postkeyword(translator, node: ast.keyword) -> str: ...
def postStarred(translator, node: ast.Starred) -> str: ...
def postSubscript(translator, node: ast.Subscript) -> str: ...
def postIndex(translator, node: ast.Index) -> str: ...
def postSlice(translator, node: ast.Slice) -> str: ...
def postConstant(translator, node: ast.Constant) -> str: ...
if sys.version_info >= (3, 14):
def postNameConstant(translator, node: ast.Constant) -> str: ...
def postNum(translator, node: ast.Constant) -> str: ...
def postStr(translator, node: ast.Constant) -> str: ...
def postBytes(translator, node: ast.Constant) -> str: ...
else:
def postNameConstant(translator, node: ast.NameConstant) -> str: ...
def postNum(translator, node: ast.Num) -> str: ...
def postStr(translator, node: ast.Str) -> str: ...
def postBytes(translator, node: ast.Bytes) -> str: ...

def postList(translator, node: ast.List) -> str: ...
def postTuple(translator, node: ast.Tuple) -> str: ...
def postDict(translator, node: ast.Dict) -> str: ...
def postSet(translator, node: ast.Set) -> str: ...
def postName(translator, node: ast.Name) -> str: ...
def postJoinedStr(self, node: ast.JoinedStr) -> str: ...
def postFormattedValue(self, node: ast.FormattedValue) -> str: ...

nonexternalizable_types: tuple[type[ast.AST], ...]

class PreTranslator(ASTTranslator):
def __init__(translator, tree, globals, locals, special_functions, const_functions, outer_names=()) -> None: ...
def dispatch(translator, node) -> None: ...
def preGeneratorExp(translator, node: ast.GeneratorExp) -> bool: ...
def preLambda(translator, node: ast.Lambda) -> bool: ...
def postName(translator, node: ast.Name) -> None: ...
def postSlice(translator, node: ast.Slice) -> None: ...
def postStarred(translator, node: ast.Starred) -> None: ...
def postConstant(translator, node: ast.Constant) -> None: ...
if sys.version_info >= (3, 14):
def postNum(translator, node: ast.Constant) -> None: ...
def postStr(translator, node: ast.Constant) -> None: ...
def postBytes(translator, node: ast.Constant) -> None: ...
else:
def postNum(translator, node: ast.Num) -> None: ...
def postStr(translator, node: ast.Str) -> None: ...
def postBytes(translator, node: ast.Bytes) -> None: ...

def postDict(translator, node: ast.Dict) -> None: ...
def postList(translator, node: ast.List) -> None: ...
def postkeyword(translator, node: ast.keyword) -> None: ...
def postIndex(translator, node: ast.Index) -> None: ...
def postCall(translator, node: ast.Call) -> None: ...
def postCompare(translator, node: ast.Compare) -> None: ...
def post_binop(translator, node: ast.BinOp) -> None: ...
def postBitOr(translator, node: ast.BitOr) -> None: ...
def postBitXor(translator, node: ast.BitXor) -> None: ...
def postBitAnd(translator, node: ast.BitAnd) -> None: ...
def postLShift(translator, node: ast.LShift) -> None: ...
def postRShift(translator, node: ast.RShift) -> None: ...
def postAdd(translator, node: ast.Add) -> None: ...
def postSub(translator, node: ast.Sub) -> None: ...
def postMult(translator, node: ast.Mult) -> None: ...
def postMatMult(translator, node: ast.MatMult) -> None: ...
def postDiv(translator, node: ast.Div) -> None: ...
def postFloorDiv(translator, node: ast.FloorDiv) -> None: ...
def postMod(translator, node: ast.Mod) -> None: ...

extractors_cache: dict[str | int, tuple[Incomplete, dict[Incomplete, Incomplete]]]

def create_extractors(code_key: str | int, tree, globals, locals, special_functions, const_functions, outer_names=()): ...
Loading