From 8efd77a7dee2a5542de0ed0d602fe9a8617b4525 Mon Sep 17 00:00:00 2001 From: henribru <6639509+henribru@users.noreply.github.com> Date: Tue, 12 Oct 2021 18:44:32 +0200 Subject: [PATCH] Initial commit --- .github/workflows/main.yml | 102 +++++++++++ .github/workflows/matchers/black.json | 14 ++ .github/workflows/matchers/isort.json | 14 ++ .github/workflows/matchers/mypy.json | 17 ++ .github/workflows/publish.yml | 22 +++ .gitignore | 9 + LICENSE | 177 +++++++++++++++++++ README.md | 12 ++ proto-stubs/__init__.pyi | 25 +++ proto-stubs/_file_info.pyi | 16 ++ proto-stubs/_package_info.pyi | 3 + proto-stubs/datetime_helpers.pyi | 13 ++ proto-stubs/enums.pyi | 14 ++ proto-stubs/fields.pyi | 47 +++++ proto-stubs/marshal/__init__.pyi | 1 + proto-stubs/marshal/collections/__init__.pyi | 2 + proto-stubs/marshal/collections/maps.pyi | 14 ++ proto-stubs/marshal/collections/repeated.pyi | 24 +++ proto-stubs/marshal/compat.pyi | 5 + proto-stubs/marshal/marshal.pyi | 20 +++ proto-stubs/marshal/rules/__init__.pyi | 0 proto-stubs/marshal/rules/dates.pyi | 15 ++ proto-stubs/marshal/rules/enums.pyi | 7 + proto-stubs/marshal/rules/message.pyi | 6 + proto-stubs/marshal/rules/struct.pyi | 18 ++ proto-stubs/marshal/rules/wrappers.pyi | 13 ++ proto-stubs/message.pyi | 64 +++++++ proto-stubs/modules.pyi | 10 ++ proto-stubs/primitives.pyi | 20 +++ proto-stubs/py.typed | 1 + proto-stubs/utils.pyi | 1 + pyproject.toml | 33 ++++ 32 files changed, 739 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/matchers/black.json create mode 100644 .github/workflows/matchers/isort.json create mode 100644 .github/workflows/matchers/mypy.json create mode 100644 .github/workflows/publish.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 proto-stubs/__init__.pyi create mode 100644 proto-stubs/_file_info.pyi create mode 100644 proto-stubs/_package_info.pyi create mode 100644 proto-stubs/datetime_helpers.pyi create mode 100644 proto-stubs/enums.pyi create mode 100644 proto-stubs/fields.pyi create mode 100644 proto-stubs/marshal/__init__.pyi create mode 100644 proto-stubs/marshal/collections/__init__.pyi create mode 100644 proto-stubs/marshal/collections/maps.pyi create mode 100644 proto-stubs/marshal/collections/repeated.pyi create mode 100644 proto-stubs/marshal/compat.pyi create mode 100644 proto-stubs/marshal/marshal.pyi create mode 100644 proto-stubs/marshal/rules/__init__.pyi create mode 100644 proto-stubs/marshal/rules/dates.pyi create mode 100644 proto-stubs/marshal/rules/enums.pyi create mode 100644 proto-stubs/marshal/rules/message.pyi create mode 100644 proto-stubs/marshal/rules/struct.pyi create mode 100644 proto-stubs/marshal/rules/wrappers.pyi create mode 100644 proto-stubs/message.pyi create mode 100644 proto-stubs/modules.pyi create mode 100644 proto-stubs/primitives.pyi create mode 100644 proto-stubs/py.typed create mode 100644 proto-stubs/utils.pyi create mode 100644 pyproject.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1291677 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,102 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install Poetry + run: pip install poetry + + - name: Cache dependencies + uses: actions/cache@v2 + env: + cache-name: cache-dependencies + with: + path: ~/.cache/pypoetry + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}- + + - name: Install dependencies + run: poetry install + + - name: Register problem matcher + run: echo "::add-matcher::.github/workflows/matchers/black.json" + + - name: Run Black + run: poetry run black --check --diff proto-stubs + + isort: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install Poetry + run: pip install poetry + + - name: Cache dependencies + uses: actions/cache@v2 + env: + cache-name: cache-dependencies + with: + path: ~/.cache/pypoetry + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}- + + - name: Install dependencies + run: poetry install + + - name: Register problem matcher + run: echo "::add-matcher::.github/workflows/matchers/isort.json" + + - name: Run isort + run: poetry run isort --check-only --diff proto-stubs + + mypy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install Poetry + run: pip install poetry + + - name: Cache dependencies + uses: actions/cache@v2 + env: + cache-name: cache-dependencies + with: + path: ~/.cache/pypoetry + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('poetry.lock') }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}- + + - name: Install dependencies + run: poetry install + + - name: Register problem matchers + run: echo "::add-matcher::.github/workflows/matchers/mypy.json" + + - name: Run Mypy + run: | + poetry run mypy proto-stubs diff --git a/.github/workflows/matchers/black.json b/.github/workflows/matchers/black.json new file mode 100644 index 0000000..9d66e5f --- /dev/null +++ b/.github/workflows/matchers/black.json @@ -0,0 +1,14 @@ +{ + "problemMatcher": [ + { + "owner": "black", + "pattern": [ + { + "regexp": "^(would reformat) (.+)$", + "message": 1, + "file": 2 + } + ] + } + ] +} diff --git a/.github/workflows/matchers/isort.json b/.github/workflows/matchers/isort.json new file mode 100644 index 0000000..8aaa98f --- /dev/null +++ b/.github/workflows/matchers/isort.json @@ -0,0 +1,14 @@ +{ + "problemMatcher": [ + { + "owner": "isort", + "pattern": [ + { + "regexp": "^ERROR: .+(proto-plus-stubs/.+) (Imports are incorrectly sorted and/or formatted.)$", + "file": 1, + "message": 2 + } + ] + } + ] +} diff --git a/.github/workflows/matchers/mypy.json b/.github/workflows/matchers/mypy.json new file mode 100644 index 0000000..78e317d --- /dev/null +++ b/.github/workflows/matchers/mypy.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "mypy", + "pattern": [ + { + "regexp": "^(.+):(\\d+):(\\d+):\\s(error|warning):\\s(.+)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + ] + } + ] +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..53ab8be --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,22 @@ +name: Publish to PyPi + +on: + release: + types: [created] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + + - name: Install Poetry + run: pip install poetry + + - name: Build and publish + run: poetry publish --build --username __token__ --password "$PYPI_TOKEN" + env: + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae82f91 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +* +!*/ +!/.github/** +!/.gitignore +!/proto-stubs/** +!/pyproject.toml +!/README.md +!/LICENSE +__pycache__ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f433b1a --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7d4b64 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Type stubs for proto-plus-stubs +[![PyPI version](https://badge.fury.io/py/proto-plus-stubs.svg)](https://badge.fury.io/py/proto-plus-stubs) + +This package provides type stubs for the [proto-plus](https://pypi.org/project/proto-plus/) package. + +**This is in no way affiliated with Google.** + +The stubs were created automatically by [stubgen](https://mypy.readthedocs.io/en/stable/stubgen.html). +## Installation +```shell script +$ pip install proto-plus-stubs +``` diff --git a/proto-stubs/__init__.pyi b/proto-stubs/__init__.pyi new file mode 100644 index 0000000..c658609 --- /dev/null +++ b/proto-stubs/__init__.pyi @@ -0,0 +1,25 @@ +from typing import Any + +from .enums import Enum as Enum +from .fields import Field as Field, MapField as MapField, RepeatedField as RepeatedField +from .marshal import Marshal as Marshal +from .message import Message as Message +from .modules import define_module as module + +DOUBLE: Any +FLOAT: Any +INT64: Any +UINT64: Any +INT32: Any +FIXED64: Any +FIXED32: Any +BOOL: Any +STRING: Any +MESSAGE: Any +BYTES: Any +UINT32: Any +ENUM: Any +SFIXED32: Any +SFIXED64: Any +SINT32: Any +SINT64: Any diff --git a/proto-stubs/_file_info.pyi b/proto-stubs/_file_info.pyi new file mode 100644 index 0000000..c452a48 --- /dev/null +++ b/proto-stubs/_file_info.pyi @@ -0,0 +1,16 @@ +from typing import Any + +from proto.marshal.rules.message import MessageRule as MessageRule + +log: Any + +class _FileInfo: + registry: Any + @classmethod + def maybe_add_descriptor(cls, filename, package): ... + @staticmethod + def proto_file_name(name): ... + def generate_file_pb(self, new_class, fallback_salt: str = ...) -> None: ... + def ready(self, new_class): ... + @property + def unresolved_fields(self) -> None: ... diff --git a/proto-stubs/_package_info.pyi b/proto-stubs/_package_info.pyi new file mode 100644 index 0000000..46adc22 --- /dev/null +++ b/proto-stubs/_package_info.pyi @@ -0,0 +1,3 @@ +from proto.marshal import Marshal as Marshal + +def compile(name, attrs): ... diff --git a/proto-stubs/datetime_helpers.pyi b/proto-stubs/datetime_helpers.pyi new file mode 100644 index 0000000..9471cbb --- /dev/null +++ b/proto-stubs/datetime_helpers.pyi @@ -0,0 +1,13 @@ +import datetime + +class DatetimeWithNanoseconds(datetime.datetime): + def __new__(cls, *args, **kw): ... + def replace(self, *args, **kw): ... + @property + def nanosecond(self): ... + def rfc3339(self): ... + @classmethod + def from_rfc3339(cls, stamp): ... + def timestamp_pb(self): ... + @classmethod + def from_timestamp_pb(cls, stamp): ... diff --git a/proto-stubs/enums.pyi b/proto-stubs/enums.pyi new file mode 100644 index 0000000..d7a3999 --- /dev/null +++ b/proto-stubs/enums.pyi @@ -0,0 +1,14 @@ +import enum +from typing import Any + +from proto.marshal.rules.enums import EnumRule as EnumRule + +class ProtoEnumMeta(enum.EnumMeta): + def __new__(mcls, name, bases, attrs): ... + +class Enum(enum.IntEnum, metaclass=ProtoEnumMeta): ... + +class _EnumInfo: + full_name: Any + pb: Any + def __init__(self, full_name: str, pb) -> None: ... diff --git a/proto-stubs/fields.pyi b/proto-stubs/fields.pyi new file mode 100644 index 0000000..2326536 --- /dev/null +++ b/proto-stubs/fields.pyi @@ -0,0 +1,47 @@ +from typing import Any + +class Field: + repeated: bool + mcls_data: Any + parent: Any + number: Any + proto_type: Any + message: Any + enum: Any + json_name: Any + optional: Any + oneof: Any + def __init__( + self, + proto_type, + number: int, + *, + message: Any | None = ..., + enum: Any | None = ..., + oneof: str = ..., + json_name: str = ..., + optional: bool = ... + ) -> None: ... + @property + def descriptor(self): ... + @property + def name(self) -> str: ... + @property + def package(self) -> str: ... + @property + def pb_type(self): ... + +class RepeatedField(Field): + repeated: bool + +class MapField(Field): + map_key_type: Any + def __init__( + self, + key_type, + value_type, + number: int, + *, + message: Any | None = ..., + enum: Any | None = ... + ) -> None: ... diff --git a/proto-stubs/marshal/__init__.pyi b/proto-stubs/marshal/__init__.pyi new file mode 100644 index 0000000..880daac --- /dev/null +++ b/proto-stubs/marshal/__init__.pyi @@ -0,0 +1 @@ +from .marshal import Marshal as Marshal diff --git a/proto-stubs/marshal/collections/__init__.pyi b/proto-stubs/marshal/collections/__init__.pyi new file mode 100644 index 0000000..4d5a34d --- /dev/null +++ b/proto-stubs/marshal/collections/__init__.pyi @@ -0,0 +1,2 @@ +from .maps import MapComposite as MapComposite +from .repeated import Repeated as Repeated, RepeatedComposite as RepeatedComposite diff --git a/proto-stubs/marshal/collections/maps.pyi b/proto-stubs/marshal/collections/maps.pyi new file mode 100644 index 0000000..378e063 --- /dev/null +++ b/proto-stubs/marshal/collections/maps.pyi @@ -0,0 +1,14 @@ +import collections.abc + +from proto.utils import cached_property as cached_property + +class MapComposite(collections.abc.MutableMapping): + def __init__(self, sequence, marshal) -> None: ... + def __contains__(self, key): ... + def __getitem__(self, key): ... + def __setitem__(self, key, value) -> None: ... + def __delitem__(self, key) -> None: ... + def __len__(self): ... + def __iter__(self): ... + @property + def pb(self): ... diff --git a/proto-stubs/marshal/collections/repeated.pyi b/proto-stubs/marshal/collections/repeated.pyi new file mode 100644 index 0000000..a9c2600 --- /dev/null +++ b/proto-stubs/marshal/collections/repeated.pyi @@ -0,0 +1,24 @@ +import collections.abc +from typing import Any + +from proto.utils import cached_property as cached_property + +class Repeated(collections.abc.MutableSequence): + def __init__(self, sequence, marshal, *, proto_type: Any | None = ...) -> None: ... + def __copy__(self): ... + def __delitem__(self, key) -> None: ... + def __eq__(self, other): ... + def __getitem__(self, key): ... + def __len__(self): ... + def __ne__(self, other): ... + def __setitem__(self, key, value) -> None: ... + def insert(self, index: int, value): ... + def sort(self, *, key: str = ..., reverse: bool = ...): ... + @property + def pb(self): ... + +class RepeatedComposite(Repeated): + def __eq__(self, other): ... + def __getitem__(self, key): ... + def __setitem__(self, key, value) -> None: ... + def insert(self, index: int, value): ... diff --git a/proto-stubs/marshal/compat.pyi b/proto-stubs/marshal/compat.pyi new file mode 100644 index 0000000..60c53b2 --- /dev/null +++ b/proto-stubs/marshal/compat.pyi @@ -0,0 +1,5 @@ +from typing import Any + +repeated_composite_types: Any +repeated_scalar_types: Any +map_composite_types: Any diff --git a/proto-stubs/marshal/marshal.pyi b/proto-stubs/marshal/marshal.pyi new file mode 100644 index 0000000..517ce3e --- /dev/null +++ b/proto-stubs/marshal/marshal.pyi @@ -0,0 +1,20 @@ +import abc + +class Rule(abc.ABC): + @classmethod + def __subclasshook__(cls, C): ... + +class BaseMarshal: + def __init__(self) -> None: ... + def register(self, proto_type: type, rule: Rule = ...): ... + def reset(self) -> None: ... + def to_python(self, proto_type, value, *, absent: bool = ...): ... + def to_proto(self, proto_type, value, *, strict: bool = ...): ... + +class Marshal(BaseMarshal): + def __new__(cls, name: str): ... + def __init__(self, name: str) -> None: ... + +class NoopRule: + def to_python(self, pb_value, *, absent: bool = ...): ... + def to_proto(self, value): ... diff --git a/proto-stubs/marshal/rules/__init__.pyi b/proto-stubs/marshal/rules/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/proto-stubs/marshal/rules/dates.pyi b/proto-stubs/marshal/rules/dates.pyi new file mode 100644 index 0000000..df6711b --- /dev/null +++ b/proto-stubs/marshal/rules/dates.pyi @@ -0,0 +1,15 @@ +from datetime import timedelta, timezone as timezone + +from google.protobuf import duration_pb2, timestamp_pb2 + +from proto import datetime_helpers as datetime_helpers, utils as utils + +class TimestampRule: + def to_python( + self, value, *, absent: bool = ... + ) -> datetime_helpers.DatetimeWithNanoseconds: ... + def to_proto(self, value) -> timestamp_pb2.Timestamp: ... + +class DurationRule: + def to_python(self, value, *, absent: bool = ...) -> timedelta: ... + def to_proto(self, value) -> duration_pb2.Duration: ... diff --git a/proto-stubs/marshal/rules/enums.pyi b/proto-stubs/marshal/rules/enums.pyi new file mode 100644 index 0000000..a2739f5 --- /dev/null +++ b/proto-stubs/marshal/rules/enums.pyi @@ -0,0 +1,7 @@ +import enum +from typing import Type + +class EnumRule: + def __init__(self, enum_class: Type[enum.IntEnum]) -> None: ... + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value): ... diff --git a/proto-stubs/marshal/rules/message.pyi b/proto-stubs/marshal/rules/message.pyi new file mode 100644 index 0000000..111af53 --- /dev/null +++ b/proto-stubs/marshal/rules/message.pyi @@ -0,0 +1,6 @@ +class MessageRule: + def __init__(self, descriptor: type, wrapper: type) -> None: ... + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value): ... + @property + def is_map(self): ... diff --git a/proto-stubs/marshal/rules/struct.pyi b/proto-stubs/marshal/rules/struct.pyi new file mode 100644 index 0000000..0dfb782 --- /dev/null +++ b/proto-stubs/marshal/rules/struct.pyi @@ -0,0 +1,18 @@ +from google.protobuf import struct_pb2 + +from proto.marshal.collections import maps as maps, repeated as repeated + +class ValueRule: + def __init__(self, marshal) -> None: ... + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value) -> struct_pb2.Value: ... + +class ListValueRule: + def __init__(self, marshal) -> None: ... + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value) -> struct_pb2.ListValue: ... + +class StructRule: + def __init__(self, marshal) -> None: ... + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value) -> struct_pb2.Struct: ... diff --git a/proto-stubs/marshal/rules/wrappers.pyi b/proto-stubs/marshal/rules/wrappers.pyi new file mode 100644 index 0000000..a2ee405 --- /dev/null +++ b/proto-stubs/marshal/rules/wrappers.pyi @@ -0,0 +1,13 @@ +class WrapperRule: + def to_python(self, value, *, absent: bool = ...): ... + def to_proto(self, value): ... + +class DoubleValueRule(WrapperRule): ... +class FloatValueRule(WrapperRule): ... +class Int64ValueRule(WrapperRule): ... +class UInt64ValueRule(WrapperRule): ... +class Int32ValueRule(WrapperRule): ... +class UInt32ValueRule(WrapperRule): ... +class BoolValueRule(WrapperRule): ... +class StringValueRule(WrapperRule): ... +class BytesValueRule(WrapperRule): ... diff --git a/proto-stubs/message.pyi b/proto-stubs/message.pyi new file mode 100644 index 0000000..8cbd6f7 --- /dev/null +++ b/proto-stubs/message.pyi @@ -0,0 +1,64 @@ +from typing import Any, List, Type + +from google.protobuf import descriptor_pb2, message + +from proto.fields import Field +from proto.marshal import Marshal + +class MessageMeta(type): + def __new__(mcls, name, bases, attrs): ... + @classmethod + def __prepare__(mcls, name, bases, **kwargs): ... + @property + def meta(cls): ... + def pb(cls, obj: Any | None = ..., *, coerce: bool = ...): ... + def wrap(cls, pb): ... + def serialize(cls, instance) -> bytes: ... + def deserialize(cls, payload: bytes) -> Message: ... + def to_json( + cls, + instance, + *, + use_integers_for_enums: bool = ..., + including_default_value_fields: bool = ..., + preserving_proto_field_name: bool = ... + ) -> str: ... + def from_json(cls, payload, *, ignore_unknown_fields: bool = ...) -> Message: ... + def to_dict( + cls, + instance, + *, + use_integers_for_enums: bool = ..., + preserving_proto_field_name: bool = ... + ) -> Message: ... + def copy_from(cls, instance, other) -> None: ... + +class Message(metaclass=MessageMeta): + def __init__( + self, mapping: Any | None = ..., *, ignore_unknown_fields: bool = ..., **kwargs + ) -> None: ... + def __bool__(self): ... + def __contains__(self, key): ... + def __delattr__(self, key) -> None: ... + def __eq__(self, other): ... + def __getattr__(self, key): ... + def __ne__(self, other): ... + def __setattr__(self, key, value): ... + +class _MessageInfo: + package: Any + full_name: Any + options: Any + fields: Any + fields_by_number: Any + marshal: Any + def __init__( + self, + fields: List[Field], + package: str, + full_name: str, + marshal: Marshal, + options: descriptor_pb2.MessageOptions, + ) -> None: ... + @property + def pb(self) -> Type[message.Message]: ... diff --git a/proto-stubs/modules.pyi b/proto-stubs/modules.pyi new file mode 100644 index 0000000..3b82b90 --- /dev/null +++ b/proto-stubs/modules.pyi @@ -0,0 +1,10 @@ +from typing import Any, NamedTuple, Set + +class _ProtoModule(NamedTuple): + package: Any + marshal: Any + manifest: Any + +def define_module( + package: str, *, marshal: str = ..., manifest: Set[str] = ... +) -> _ProtoModule: ... diff --git a/proto-stubs/primitives.pyi b/proto-stubs/primitives.pyi new file mode 100644 index 0000000..f333454 --- /dev/null +++ b/proto-stubs/primitives.pyi @@ -0,0 +1,20 @@ +import enum + +class ProtoType(enum.IntEnum): + DOUBLE: int + FLOAT: int + INT64: int + UINT64: int + INT32: int + FIXED64: int + FIXED32: int + BOOL: int + STRING: int + MESSAGE: int + BYTES: int + UINT32: int + ENUM: int + SFIXED32: int + SFIXED64: int + SINT32: int + SINT64: int diff --git a/proto-stubs/py.typed b/proto-stubs/py.typed new file mode 100644 index 0000000..b648ac9 --- /dev/null +++ b/proto-stubs/py.typed @@ -0,0 +1 @@ +partial diff --git a/proto-stubs/utils.pyi b/proto-stubs/utils.pyi new file mode 100644 index 0000000..162bb8b --- /dev/null +++ b/proto-stubs/utils.pyi @@ -0,0 +1 @@ +def cached_property(fx): ... diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..124fa43 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[tool.poetry] +name = "proto-plus-stubs" +version = "0.1.0" +license = "Apache-2.0" +description = "Type stubs for proto-plus" +authors = ["Henrik BruÄsdal "] +readme = "README.md" +repository = "https://github.com/henribru/proto-plus-stubs" +packages = [ + { include = "proto-stubs" }, +] +classifiers = [ + "Typing :: Typed", +] + +[tool.poetry.dependencies] +python = "^3.7" +proto-plus = "^1.18.0" +types-protobuf = "^3.17.4" + +[tool.poetry.dev-dependencies] +mypy = "^0.910" +isort = "^5.9.3" +black = "^21.9b0" + +[tool.isort] +profile = "black" +known_first_party = "proto" +combine_as_imports = true + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api"