Skip to content

Commit cc9cb91

Browse files
authored
Add pony stubs (#14361)
1 parent a1ae191 commit cc9cb91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3997
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"stubs/peewee",
7171
"stubs/pexpect",
7272
"stubs/pika",
73+
"stubs/pony",
7374
"stubs/protobuf",
7475
"stubs/psutil",
7576
"stubs/psycopg2",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tests should not be part of the stubs
2+
pony.orm.tests.*
3+
4+
# Modules with ImportError, cannot import third-party libraries:
5+
pony.flask.*
6+
pony.orm.dbproviders.cockroach
7+
pony.orm.dbproviders.mysql
8+
pony.orm.dbproviders.oracle
9+
pony.orm.dbproviders.postgres
10+
pony.orm.integration.bottle_plugin
11+
pony.orm.examples.bottle_example
12+
13+
# TODO: Incomplete issues in examples dir:
14+
pony.orm.examples.*

stubs/pony/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "0.7.*"
2+
upstream_repository = "https://github.com/ponyorm/pony"
3+
requires = ["types-psycopg2", "types-PyMySQL"]

stubs/pony/pony/__init__.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Final, Literal
2+
from typing_extensions import TypeAlias
3+
4+
_Mode: TypeAlias = Literal[
5+
"GAE-LOCAL", "GAE-SERVER", "MOD_WSGI", "INTERACTIVE", "FCGI-FLUP", "UWSGI", "FLASK", "CHERRYPY", "BOTTLE", "UNKNOWN"
6+
]
7+
__version__: Final[str]
8+
9+
def detect_mode() -> _Mode: ...
10+
11+
MODE: Final[_Mode]
12+
MAIN_FILE: Final[str | None]
13+
MAIN_DIR: Final[str | None]
14+
PONY_DIR: Final[str]

stubs/pony/pony/converting.pyi

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import re
2+
from _typeshed import ConvertibleToInt
3+
from collections.abc import Callable, Sequence
4+
from datetime import date, datetime, time, timedelta
5+
from typing import Any, Literal
6+
7+
class ValidationError(ValueError): ...
8+
9+
def check_ip(s: str) -> str: ...
10+
def check_positive(s: ConvertibleToInt) -> int: ...
11+
def check_identifier(s: str) -> str: ...
12+
13+
isbn_re: re.Pattern[str]
14+
15+
def isbn10_checksum(digits: Sequence[ConvertibleToInt]) -> str: ...
16+
def isbn13_checksum(digits: Sequence[ConvertibleToInt]) -> str: ...
17+
def check_isbn(s: str, convert_to: Literal[10, 13] | None = None) -> str: ...
18+
def isbn10_to_isbn13(s: str) -> str: ...
19+
def isbn13_to_isbn10(s: str) -> str: ...
20+
21+
email_re: re.Pattern[str]
22+
rfc2822_email_re: re.Pattern[str]
23+
24+
def check_email(s: str) -> str: ...
25+
def check_rfc2822_email(s: str) -> str: ...
26+
27+
date_str_list: list[str]
28+
date_re_list: list[re.Pattern[str]]
29+
time_str: str
30+
time_re: re.Pattern[str]
31+
datetime_re_list: list[re.Pattern[str]]
32+
month_lists: list[list[str]]
33+
month_list: list[str]
34+
i: int
35+
month: str
36+
month_dict: dict[str, int]
37+
38+
def str2date(s: str) -> date: ...
39+
def str2time(s: str) -> time: ...
40+
def str2datetime(s: str) -> datetime: ...
41+
def str2timedelta(s: str) -> timedelta: ...
42+
def timedelta2str(td: timedelta) -> str: ...
43+
44+
converters: dict[type | str, tuple[Callable[[str], Any], type[str], str | None]] # Any type from types above
45+
46+
def str2py(
47+
value: str, type: str | type | tuple[Callable[[str], Any], type[str], str | None] | None
48+
) -> Any: ... # Any type from types above

stubs/pony/pony/flask/__init__.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from _typeshed import Incomplete
2+
from types import ModuleType
3+
from typing import Protocol
4+
5+
# Protocol for flask.Flask class
6+
class _Flask(Protocol):
7+
def before_request(self, f): ...
8+
def after_request(self, f): ...
9+
def teardown_request(self, f): ...
10+
11+
flask_lib: ModuleType
12+
request: Incomplete
13+
14+
class Pony:
15+
app: _Flask | None
16+
def __init__(self, app: _Flask | None = None) -> None: ...
17+
def init_app(self, app: _Flask) -> None: ...

stubs/pony/pony/flask/example/__init__.pyi

Whitespace-only changes.

stubs/pony/pony/flask/example/app.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from _typeshed import Incomplete
2+
3+
from pony.flask import _Flask
4+
5+
app: _Flask
6+
login_manager: Incomplete
7+
8+
def load_user(user_id): ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config: dict[str, bool | str | dict[str, str | bool]]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from datetime import datetime
2+
3+
from pony.orm.core import Database, Entity
4+
5+
db: Database
6+
7+
class User(Entity):
8+
login: str
9+
password: str
10+
last_login: datetime | None

0 commit comments

Comments
 (0)