-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Make codebase work with basic mypy usage #1084
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# coding=utf-8 | ||
from gettext import gettext as _ | ||
import logging | ||
|
||
service_cls = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# coding=utf-8 | ||
from typing import Dict, Any, Tuple | ||
|
||
from gi.repository import Gio, GLib, GObject | ||
from gi.types import GObjectMeta | ||
from blueman.bluez.errors import parse_dbus_error | ||
|
@@ -47,7 +49,7 @@ class Base(Gio.DBusProxy, metaclass=BaseMeta): | |
__name = 'org.bluez' | ||
__bus_type = Gio.BusType.SYSTEM | ||
|
||
__gsignals__ = { | ||
__gsignals__: Dict[str, Tuple[Any, GObject.SignalFlags, Tuple]] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first Tuple starts with GObject.SignalFlags not Any, next is None and then a tuple. For the second tuple we know the first is a str and we know what types to expect from dbus properties which we can represent as a Union. So I think it should be the below which works for Base. But not for subclasses that add their own signals so they will need their own type hints. |
||
'property-changed': (GObject.SignalFlags.NO_HOOKS, None, | ||
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# coding=utf-8 | ||
from gettext import gettext as _ | ||
import logging | ||
|
||
import blueman.bluez as bluez | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ class NMConnectionError(Exception): | |
|
||
|
||
class NMConnectionBase(object): | ||
conntype = None | ||
conntype: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def __init__(self, service, reply_handler=None, error_handler=None): | ||
if self.conntype not in ('dun', 'panu'): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
# coding=utf-8 | ||
import logging | ||
import weakref | ||
from typing import List, TYPE_CHECKING, Type, Dict, Tuple, Any | ||
|
||
from blueman.main.Config import Config | ||
|
||
|
||
class MethodAlreadyExists(Exception): | ||
pass | ||
|
||
|
||
if TYPE_CHECKING: | ||
from mypy_extensions import TypedDict | ||
|
||
class OptionBase(TypedDict): | ||
type: Type | ||
default: Any | ||
|
||
class Option(OptionBase, total=False): | ||
name: str | ||
desc: str | ||
range: Tuple[int, int] | ||
|
||
class GSettings(TypedDict): | ||
schema: str | ||
path: None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
class BasePlugin(object): | ||
__depends__ = [] | ||
__conflicts__ = [] | ||
__depends__: List[str] = [] | ||
__conflicts__: List[str] = [] | ||
__priority__ = 0 | ||
|
||
__description__ = None | ||
__author__ = None | ||
__description__: str | ||
__author__: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
__unloadable__ = True | ||
__autoload__ = True | ||
|
||
__instance__ = None | ||
|
||
__gsettings__ = None | ||
__gsettings__: "GSettings" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
__options__ = {} | ||
__options__: Dict[str, "Option"] = {} | ||
|
||
def __init__(self, parent): | ||
self.parent = parent | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# coding=utf-8 | ||
from typing import List, Tuple | ||
|
||
|
||
class ServicePlugin(object): | ||
instances = [] | ||
__plugin_info__ = None | ||
instances: List["ServicePlugin"] = [] | ||
__plugin_info__: Tuple[str, str] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def __init__(self, parent): | ||
ServicePlugin.instances.append(self) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# coding=utf-8 | ||
from gettext import gettext as _ | ||
import logging | ||
|
||
import blueman.bluez as bluez | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional[str] = None