Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Add mypy stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
kalkin committed Sep 27, 2016
1 parent 9ba7a2c commit 0cbe9b1
Show file tree
Hide file tree
Showing 36 changed files with 347 additions and 0 deletions.
12 changes: 12 additions & 0 deletions stubs/curses.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import (
Any, Callable, Iterable, Tuple, List, TextIO, Sequence,
Optional, overload, TypeVar, Pattern, Type
)

class error(Exception):...

def setupterm() -> None: ...
def tparm(arg: str, *args: int) -> None: ...
def tigetstr(arg: str) -> str: ...

# vim: syntax=python
28 changes: 28 additions & 0 deletions stubs/dbus/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Stubs for dbus

import dbus.mainloop
import dbus.proxies
import dbus._dbus
from typing import Optional, Union, Callable


class Interface(object):
def __init__(self, object: Union[dbus.proxies.ProxyObject, Interface], dbus_interface: str) -> None: ...
def get_dbus_method(self, member: str, dbus_interface: Optional[str]=...) -> Callable: ...


class Bus(dbus.bus.BusConnection):
def __new__(cls,
bus_type: Optional[int], private: Optional[bool]=...,
mainloop: Optional[dbus.mainloop.NativeMainLoop]=...
) -> dbus.bus.BusConnection: ...

def SessionBus() -> dbus._dbus.SessionBus: ...

class String(str): ...
class Boolean(int): ...

class Array(list): ...
class Dictionary(dict): ...
# vim: syntax=python

12 changes: 12 additions & 0 deletions stubs/dbus/_dbus.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Optional
import dbus
import dbus.bus
import dbus.mainloop

class SessionBus(dbus.bus.BusConnection):
def __new__(cls,
private: Optional[bool]=...,
mainloop: Optional[dbus.mainloop.NativeMainLoop]=...
) -> dbus.Bus: ...

# vim: syntax=python
15 changes: 15 additions & 0 deletions stubs/dbus/bus.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dbus.connection
import dbus.proxies
from typing import Optional


class BusConnection(dbus.connection.Connection):
def get_object(self,
bus_name: str=...,
object_path: str=...,
introspect: Optional[bool]=...,
follow_name_owner_changes: Optional[bool]=...
) -> dbus.proxies.ProxyObject:
...

# vim: syntax=python
2 changes: 2 additions & 0 deletions stubs/dbus/connection.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Connection(object):
pass
3 changes: 3 additions & 0 deletions stubs/dbus/mainloop/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

class NativeMainLoop:
...
3 changes: 3 additions & 0 deletions stubs/dbus/mainloop/glib.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dbus.mainloop

def DBusGMainLoop(set_as_default: bool = ... ) -> dbus.mainloop.NativeMainLoop: ...
7 changes: 7 additions & 0 deletions stubs/dbus/proxies.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Stubs for dbus.proxies
from typing import Optional, Callable

class ProxyObject(object):
def get_dbus_method(self, member: str=..., dbus_interface: Optional[str]=...) -> Callable: ...

# vim: ft=python tw=0 syntax=python
45 changes: 45 additions & 0 deletions stubs/dbus/service.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Stubs for dbus.service

import dbus
from dbus.connection import Connection
from dbus._dbus import SessionBus
from typing import Optional, Tuple, Callable, Union


class Object(dbus.Interface):
def __init__(self, conn: Optional[Union[BusName,Connection]] = ...,
object_path: Optional[str] = ...,
bus_name: Optional[BusName] = ...) -> None: ...

def method(
dbus_interface: str=...,
in_signature: Optional[str]=...,
out_signature: Optional[str]=...,
async_callbacks: Tuple[str,str]=...,
sender_keyword: Optional[str]=...,
path_keyword: Optional[str]=...,
rel_path_keyword: Optional[str]=...,
destination_keyword: Optional[str]=...,
message_keyword: Optional[str]=...,
connection_keyword: Optional[str]=...,
utf8_strings: bool=...,
byte_arrays: bool=...,

) -> Callable: ...

def signal(
dbus_interface: str=...,
signature: Optional[str]=...,
path_keyword: Optional[str]=...,
rel_path_keyword: Optional[str]=...,
) -> Callable: ...

class BusName(object):
def __new__(cls,
name: str,
bus: Union[dbus.Bus, SessionBus],
allow_replacement: Optional[bool]=...,
replace_existing: Optional[bool]=...,
do_not_queue: Optional[bool]=...,
) -> BusName: ...
# vim: syntax=python tw=0
Empty file added stubs/docutils/__init__.pyi
Empty file.
Empty file added stubs/docutils/core.pyi
Empty file.
Empty file added stubs/docutils/io.pyi
Empty file.
Empty file added stubs/gi/__init__.pyi
Empty file.
7 changes: 7 additions & 0 deletions stubs/gi/repository.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Stubs for gi.repository

class GLib(object):
class MainLoop(object):
def run(self) -> None: ...

# vim: syntax=python
Empty file added stubs/jinja2.pyi
Empty file.
Empty file added stubs/libvirt/__init__.pyi
Empty file.
Empty file added stubs/lxml/__init__.pyi
Empty file.
Empty file added stubs/lxml/etree.pyi
Empty file.
6 changes: 6 additions & 0 deletions stubs/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import (Iterable, Optional, Any, Callable)
class EntryPoint(object):
def load(self, require: bool = ..., *args: Any, **kwargs: Any) -> Callable: ...


def iter_entry_points(group: str, name: Optional[str] = ...) -> Iterable[EntryPoint]: ...
Empty file added stubs/pywintypes.pyi
Empty file.
4 changes: 4 additions & 0 deletions stubs/qubes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import (List)
import qubes.vm
class Qubes(object):
domains = ... # type: List[qubes.vm.BaseVM]
1 change: 1 addition & 0 deletions stubs/qubes/vm/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class BaseVM(object): ...
2 changes: 2 additions & 0 deletions stubs/qubes/vm/qubesvm.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class QubesVM(object):
qid = ... # type: int
Empty file added stubs/qubesdb/__init__.pyi
Empty file.
Empty file added stubs/systemd/__init__.pyi
Empty file.
9 changes: 9 additions & 0 deletions stubs/systemd/journal.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Stubs for systemd.journal

import logging

from typing import Optional

class JournalHandler(logging.Handler):
def __init__(self, level: Optional[int]=..., SYSLOG_IDENTIFIER: Optional[str]=...) -> None: ...
# vim: syntax=python tw=0
191 changes: 191 additions & 0 deletions stubs/unittest.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Stubs for unittest

# Based on http://docs.python.org/2.7/library/unittest.html

# Only a subset of functionality is included.

from typing import (
Any, Callable, Iterable, Tuple, List, TextIO, Sequence,
overload, TypeVar, Pattern, Type, IO
)
from abc import abstractmethod, ABCMeta

_T = TypeVar('_T')
_FT = TypeVar('_FT')

class Testable(metaclass=ABCMeta):
@abstractmethod
def run(self, result: 'TestResult') -> None: ...
@abstractmethod
def debug(self) -> None: ...
@abstractmethod
def countTestCases(self) -> int: ...

# TODO ABC for test runners?

class TestResult:
errors = ... # type: List[Tuple[Testable, str]]
failures = ... # type: List[Tuple[Testable, str]]
testsRun = 0
shouldStop = ... # type: bool

def wasSuccessful(self) -> bool: ...
def stop(self) -> None: ...
def startTest(self, test: Testable) -> None: ...
def stopTest(self, test: Testable) -> None: ...
def addError(self, test: Testable,
err: Tuple[type, Any, Any]) -> None: ... # TODO
def addFailure(self, test: Testable,
err: Tuple[type, Any, Any]) -> None: ... # TODO
def addSuccess(self, test: Testable) -> None: ...

class TextTestResult(TestResult):
separator1 = ... # type: str
separator2 = ... # type: str

class _AssertRaisesBaseContext:
expected = ... # type: Any
failureException = ... # type: type
obj_name = ... # type: str
expected_regex = ... # type: Pattern[str]

class _AssertRaisesContext(_AssertRaisesBaseContext):
exception = ... # type: Any # TODO precise type
def __enter__(self) -> _AssertRaisesContext: ...
def __exit__(self, exc_type, exc_value, tb) -> bool: ...

class _AssertWarnsContext(_AssertRaisesBaseContext):
warning = ... # type: Any # TODO precise type
filename = ... # type: str
lineno = 0
def __enter__(self) -> _AssertWarnsContext: ...
def __exit__(self, exc_type, exc_value, tb) -> bool: ...

class TestCase(Testable):
def __init__(self, methodName: str = ...) -> None: ...
# TODO failureException
def setUp(self) -> None: ...
def tearDown(self) -> None: ...
def run(self, result: TestResult = ...) -> None: ...
def debug(self) -> None: ...
def assert_(self, expr: Any, msg: object = ...) -> None: ...
def failUnless(self, expr: Any, msg: object = ...) -> None: ...
def assertTrue(self, expr: Any, msg: object = ...) -> None: ...
def assertEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertEquals(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def failUnlessEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertNotEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertNotEquals(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def failIfEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertAlmostEqual(self, first: float, second: float, places: int = ...,
msg: object = ...,
delta: float = ...) -> None: ...
def assertAlmostEquals(self, first: float, second: float, places: int = ...,
msg: object = ...,
delta: float = ...) -> None: ...
def failUnlessAlmostEqual(self, first: float, second: float, places: int = ...,
msg: object = ...) -> None: ...
def assertNotAlmostEqual(self, first: float, second: float, places: int = ...,
msg: object = ...,
delta: float = ...) -> None: ...
def assertNotAlmostEquals(self, first: float, second: float, places: int = ...,
msg: object = ...,
delta: float = ...) -> None: ...
def failIfAlmostEqual(self, first: float, second: float, places: int = ...,
msg: object = ...,
delta: float = ...) -> None: ...
def assertGreater(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertGreaterEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertMultiLineEqual(self, first: str, second: str,
msg: object = ...) -> None: ...
def assertSequenceEqual(self, first: Sequence[Any], second: Sequence[Any],
msg: object = ..., seq_type: type = ...) -> None: ...
def assertListEqual(self, first: List[Any], second: List[Any],
msg: object = ...) -> None: ...
def assertTupleEqual(self, first: Tuple[Any, ...], second: Tuple[Any, ...],
msg: object = ...) -> None: ...
def assertSetEqual(self, first: Set[Any], second: Set[Any],
msg: object = ...) -> None: ...
def assertDictEqual(self, first: Dict[Any, Any], second: Dict[Any, Any],
msg: object = ...) -> None: ...
def assertLess(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertLessEqual(self, first: Any, second: Any,
msg: object = ...) -> None: ...
def assertRaises(self, expected_exception: type, *args: Any, **kwargs: Any) -> Any: ...
def failUnlessRaises(self, expected_exception: type, *args: Any, **kwargs: Any) -> Any: ...
def failIf(self, expr: Any, msg: object = ...) -> None: ...
def assertFalse(self, expr: Any, msg: object = ...) -> None: ...
def assertIs(self, first: object, second: object,
msg: object = ...) -> None: ...
def assertIsNot(self, first: object, second: object,
msg: object = ...) -> None: ...
def assertIsNone(self, expr: Any, msg: object = ...) -> None: ...
def assertIsNotNone(self, expr: Any, msg: object = ...) -> None: ...
def assertIn(self, first: _T, second: Iterable[_T],
msg: object = ...) -> None: ...
def assertNotIn(self, first: _T, second: Iterable[_T],
msg: object = ...) -> None: ...
def assertIsInstance(self, obj: Any, cls: type,
msg: object = ...) -> None: ...
def assertNotIsInstance(self, obj: Any, cls: type,
msg: object = ...) -> None: ...
def assertWarns(self, expected_warning: type, callable_obj: Any = ...,
*args: Any, **kwargs: Any) -> _AssertWarnsContext: ...
def fail(self, msg: object = ...) -> None: ...
def countTestCases(self) -> int: ...
def defaultTestResult(self) -> TestResult: ...
def id(self) -> str: ...
def shortDescription(self) -> str: ... # May return None
def addCleanup(function: Any, *args: Any, **kwargs: Any) -> None: ...
def skipTest(self, reason: Any) -> None: ...

class CallableTestCase(Testable):
def __init__(self, testFunc: Callable[[], None],
setUp: Callable[[], None] = ...,
tearDown: Callable[[], None] = ...,
description: str = ...) -> None: ...
def run(self, result: TestResult) -> None: ...
def debug(self) -> None: ...
def countTestCases(self) -> int: ...

class TestSuite(Testable):
def __init__(self, tests: Iterable[Testable] = ...) -> None: ...
def addTest(self, test: Testable) -> None: ...
def addTests(self, tests: Iterable[Testable]) -> None: ...
def run(self, result: TestResult) -> None: ...
def debug(self) -> None: ...
def countTestCases(self) -> int: ...

# TODO TestLoader
# TODO defaultTestLoader

class TextTestRunner:
resultclass = ... # type: Type[TestResult]
def __init__(self, stream: IO[str] = ..., descriptions: bool = ...,
verbosity: int = ..., failfast: bool = ...) -> None: ...
def run(self, test: Testable) -> TestResult: ...

class SkipTest(Exception):
...

# TODO precise types
def skipUnless(condition: Any, reason: str) -> Any: ...
def skipIf(condition: Any, reason: str) -> Any: ...
def expectedFailure(func: _FT) -> _FT: ...
def skip(reason: str) -> Any: ...

def main(module: str = ..., defaultTest: str = ...,
argv: List[str] = ..., testRunner: Any = ...,
testLoader: Any = ...) -> None: ... # TODO types

# private but occasionally used
util = ... # type: module
Empty file added stubs/win32con.pyi
Empty file.
Empty file added stubs/win32file.pyi
Empty file.
Empty file added stubs/xen/__init__.pyi
Empty file.
Empty file added stubs/xen/lowlevel/__init__.pyi
Empty file.
Empty file added stubs/xen/lowlevel/xc.pyi
Empty file.
Empty file added stubs/xen/lowlevel/xs.pyi
Empty file.
Empty file added stubs/xml/__init__.pyi
Empty file.
Empty file added stubs/xml/parsers/__init__.pyi
Empty file.
Empty file added stubs/xml/parsers/expat.pyi
Empty file.

0 comments on commit 0cbe9b1

Please sign in to comment.