Skip to content

SG-39414 Add type annotations #393

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 3 commits into
base: master
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
packages=find_packages(exclude=("tests",)),
script_args=sys.argv[1:],
include_package_data=True,
package_data={"": ["cacerts.txt", "cacert.pem"]},
package_data={"": ["cacerts.txt", "cacert.pem", "py.typed"]},
zip_safe=False,
python_requires=">=3.7.0",
python_requires=">=3.9.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from .. import six

# Define all here to keep linters happy. It should be overwritten by the code
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import base64
import re

Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/certs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
"""Utilities for certificate management."""

import os
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/iri2uri.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore
"""Converts an IRI to a URI."""

__author__ = "Joe Gregorio (joe@bitworking.org)"
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/python3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore
"""Small, fast HTTP client library for Python."""

__author__ = "Joe Gregorio (joe@bitworking.org)"
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/python3/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import base64
import re

Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/python3/certs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
"""Utilities for certificate management."""

import os
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/httplib2/python3/iri2uri.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore
"""Converts an IRI to a URI."""

__author__ = "Joe Gregorio (joe@bitworking.org)"
Expand Down
15 changes: 8 additions & 7 deletions shotgun_api3/lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
a patched version of the native mimetypes module and is used only in Python
versions 2.7.0 - 2.7.9, which included a broken version of the mimetypes module.
"""
from __future__ import print_function

import os
import sys
Expand Down Expand Up @@ -568,14 +569,14 @@ def _default_mime_types():
"""

def usage(code, msg=''):
print USAGE
if msg: print msg
print(USAGE)
if msg: print(msg)
sys.exit(code)

try:
opts, args = getopt.getopt(sys.argv[1:], 'hle',
['help', 'lenient', 'extension'])
except getopt.error, msg:
except getopt.error as msg:
usage(1, msg)

strict = 1
Expand All @@ -590,9 +591,9 @@ def usage(code, msg=''):
for gtype in args:
if extension:
guess = guess_extension(gtype, strict)
if not guess: print "I don't know anything about type", gtype
else: print guess
if not guess: print("I don't know anything about type", gtype)
else: print(guess)
else:
guess, encoding = guess_type(gtype, strict)
if not guess: print "I don't know anything about type", gtype
else: print 'type:', guess, 'encoding:', encoding
if not guess: print("I don't know anything about type", gtype)
else: print('type:', guess, 'encoding:', encoding)
5 changes: 3 additions & 2 deletions shotgun_api3/lib/mockgun/mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
from ...shotgun import _Config
from .errors import MockgunError
from .schema import SchemaFactory
from typing import Any

# ----------------------------------------------------------------------------
# Version
Expand Down Expand Up @@ -581,7 +582,7 @@ def _get_new_row(self, entity_type):
row[field] = default_value
return row

def _compare(self, field_type, lval, operator, rval):
def _compare(self, field_type: str, lval: Any, operator: str, rval: Any) -> bool:
"""
Compares a field using the operator and value provide by the filter.

Expand Down Expand Up @@ -798,7 +799,7 @@ def _row_matches_filter(self, entity_type, row, sg_filter, retired_only):

return self._compare(field_type, lval, operator, rval)

def _rearrange_filters(self, filters):
def _rearrange_filters(self, filters: list) -> None:
"""
Modifies the filter syntax to turn it into a list of three items regardless
of the actual filter. Most of the filters are list of three elements, so this doesn't change much.
Expand Down
3 changes: 2 additions & 1 deletion shotgun_api3/lib/mockgun/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
"""
-----------------------------------------------------------------------------
Copyright (c) 2009-2017, Shotgun Software Inc
Expand Down Expand Up @@ -47,7 +48,7 @@ class SchemaFactory(object):
_schema_cache_path = None

@classmethod
def get_schemas(cls, schema_path, schema_entity_path):
def get_schemas(cls, schema_path: str, schema_entity_path: str) -> tuple:
"""
Retrieves the schemas from disk.

Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/pyparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# type: ignore

__doc__ = \
"""
Expand Down
2 changes: 1 addition & 1 deletion shotgun_api3/lib/sgsix.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
ShotgunSSLError = SSLHandshakeError


def normalize_platform(platform, python2=True):
def normalize_platform(platform: str, python2: bool = True) -> str:
"""
Normalize the return of sys.platform between Python 2 and 3.

Expand Down
4 changes: 2 additions & 2 deletions shotgun_api3/lib/sgutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""


def ensure_binary(s, encoding='utf-8', errors='strict'):
def ensure_binary(s, encoding='utf-8', errors='strict') -> bytes:
"""
Coerce **s** to bytes.

Expand All @@ -44,7 +44,7 @@ def ensure_binary(s, encoding='utf-8', errors='strict'):
raise TypeError(f"not expecting type '{type(s)}'")


def ensure_str(s, encoding='utf-8', errors='strict'):
def ensure_str(s, encoding='utf-8', errors='strict') -> str:
"""Coerce *s* to `str`.

- `str` -> `str`
Expand Down
1 change: 1 addition & 0 deletions shotgun_api3/lib/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# type: ignore

"""Utilities for writing code that runs on Python 2 and 3"""

Expand Down
Empty file added shotgun_api3/py.typed
Empty file.
Loading
Loading