Skip to content

Commit

Permalink
Merge pull request #228 from d-bohls/standardizeDunders
Browse files Browse the repository at this point in the history
chore(API): increase uniformity of dunders
  • Loading branch information
Ajay Jashnani committed Feb 16, 2018
2 parents ef864af + 1fba5c3 commit c7f9f0e
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion nixnet/_session/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __hash__(self):

def __repr__(self):
# type: () -> typing.Text
return 'Session(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def close(self):
# type: () -> None
Expand Down
1 change: 1 addition & 0 deletions nixnet/_session/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Item(object):
"""Item configuration for a session."""

def __init__(self, handle, index, name):
# type: (int, int, typing.Text) -> None
self._handle = handle
self._index = index
self._name = name
Expand Down
3 changes: 2 additions & 1 deletion nixnet/_session/intf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class Interface(object):
'''Interface configuration for a session'''

def __init__(self, handle):
# type: (int) -> None
self._handle = handle

def __repr__(self):
return 'Session.Interface(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def __str__(self):
return self._name
Expand Down
3 changes: 2 additions & 1 deletion nixnet/_session/j1939.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class J1939(object):
"""J1939 configuration for a session"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle

def __repr__(self):
return 'Session.J1939(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def __str__(self):
return self.name
Expand Down
2 changes: 1 addition & 1 deletion nixnet/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __hash__(self):

def __repr__(self):
# type: () -> typing.Text
return 'Session(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def close(self):
# type: () -> None
Expand Down
5 changes: 3 additions & 2 deletions nixnet/database/_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class Cluster(object):
"""Database cluster"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._dbc_attributes = None
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]
self._ecus = _collection.DbCollection(
self._handle, constants.ObjectClass.ECU, _cconsts.NX_PROP_CLST_ECU_REFS, _ecu.Ecu)
self._frames = _collection.DbCollection(
Expand All @@ -49,7 +50,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Cluster(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def merge(
self,
Expand Down
2 changes: 1 addition & 1 deletion nixnet/database/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, handle, db_type, prop_id, factory):
self._factory = factory

def __repr__(self):
return 'database.DbCollection(handle={0}, db_type={1})'.format(self._handle, self._type)
return '{}(handle={0}, db_type={1})'.format(type(self).__name__, self._handle, self._type)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down
5 changes: 3 additions & 2 deletions nixnet/database/_ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Ecu(object):
"""Database ECU"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._dbc_attributes = None
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand All @@ -33,7 +34,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Ecu(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def clst_ref(self):
Expand Down
5 changes: 3 additions & 2 deletions nixnet/database/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class Frame(object):
"""Database frame"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._dbc_attributes = None
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]
self._mux_static_signals = _collection.DbCollection(
self._handle, constants.ObjectClass.SIGNAL, _cconsts.NX_PROP_FRM_MUX_STATIC_SIG_REFS, _signal.Signal)
self._mux_subframes = _collection.DbCollection(
Expand All @@ -43,7 +44,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Frame(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def application_protocol(self):
Expand Down
3 changes: 2 additions & 1 deletion nixnet/database/_linsched.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class LinSched(object):

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._entries = _collection.DbCollection(
self._handle,
Expand All @@ -39,7 +40,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'LinSched(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def clst_ref(self):
Expand Down
3 changes: 2 additions & 1 deletion nixnet/database/_linsched_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class LinSchedEntry(object):

def __init__(self, handle):
# type: (int) -> None
self._handle = handle

def __eq__(self, other):
Expand All @@ -31,7 +32,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'LinSchedEntry(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def collision_res_sched(self):
Expand Down
3 changes: 2 additions & 1 deletion nixnet/database/_pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class Pdu(object):

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._signals = _collection.DbCollection(
self._handle, constants.ObjectClass.SIGNAL, _cconsts.NX_PROP_PDU_SIG_REFS, _signal.Signal)
Expand All @@ -37,7 +38,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Pdu(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def cluster_ref(self):
Expand Down
5 changes: 3 additions & 2 deletions nixnet/database/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Signal(object):
"""Database signal"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._dbc_attributes = None
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand All @@ -33,7 +34,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Signal(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def byte_ordr(self):
Expand Down
3 changes: 2 additions & 1 deletion nixnet/database/_subframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SubFrame(object):

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
self._dyn_signals = _collection.DbCollection(
self._handle, constants.ObjectClass.SIGNAL, _cconsts.NX_PROP_SUBFRM_DYN_SIG_REFS, _signal.Signal)
Expand All @@ -34,7 +35,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'SubFrame(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def config_status(self):
Expand Down
3 changes: 2 additions & 1 deletion nixnet/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class Database(object):

def __init__(self, database_name):
# type: (typing.Text) -> None
self._handle = None # To satisfy `__del__` in case nxdb_open_database throws
self._handle = _funcs.nxdb_open_database(database_name)
self._clusters = _collection.DbCollection(
Expand Down Expand Up @@ -53,7 +54,7 @@ def __hash__(self):
return hash(self._handle)

def __repr__(self):
return 'Database(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def close(self, close_all_refs=False):
if self._handle is None:
Expand Down
2 changes: 1 addition & 1 deletion nixnet/system/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, handle, prop_id, factory):
self._factory = factory

def __repr__(self):
return 'SystemCollection(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down
5 changes: 3 additions & 2 deletions nixnet/system/_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, handle):
self._handle = handle

def __repr__(self):
return 'System.AliasCollection(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down Expand Up @@ -164,7 +164,8 @@ def __init__(
self._database_filepath = database_filepath

def __repr__(self):
return 'System.Alias(alias={}, filepath={})'.format(self._database_alias, self._database_filepath)
return '{}(alias={}, filepath={})'.format(
type(self).__name__, self._database_alias, self._database_filepath)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down
2 changes: 1 addition & 1 deletion nixnet/system/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __hash__(self):

def __repr__(self):
# type: () -> typing.Text
return 'Device(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

@property
def form_fac(self):
Expand Down
2 changes: 1 addition & 1 deletion nixnet/system/_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __str__(self):

def __repr__(self):
# type: () -> typing.Text
return 'Interface(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

# `dev_ref`: Intentionally not exposed to avoid circular imports

Expand Down
2 changes: 1 addition & 1 deletion nixnet/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __hash__(self):

def __repr__(self):
# type: () -> typing.Text
return 'System(handle={0})'.format(self._handle)
return '{}(handle={})'.format(type(self).__name__, self._handle)

def close(self):
# type: () -> None
Expand Down
27 changes: 17 additions & 10 deletions nixnet/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ def __repr__(self):
CanIdentifier(0x1, extended=True)
"""
if self.extended:
return "CanIdentifier(0x{:x}, extended={})".format(
return "{}(0x{:x}, extended={})".format(
type(self).__name__,
self.identifier,
self.extended)
else:
return "CanIdentifier(0x{:x})".format(
return "{}(0x{:x})".format(
type(self).__name__,
self.identifier)


Expand Down Expand Up @@ -364,7 +366,8 @@ def __repr__(self):
optional_params = ', {}'.format(", ".join(optional))
else:
optional_params = ''
return "RawFrame(timestamp=0x{:x}, identifier=0x{:x}, type={}{})".format(
return "{}(timestamp=0x{:x}, identifier=0x{:x}, type={}{})".format(
type(self).__name__,
self.timestamp,
self.identifier,
self.type,
Expand Down Expand Up @@ -469,7 +472,8 @@ def __repr__(self):
optional_params = ', {}'.format(", ".join(optional))
else:
optional_params = ''
return "CanFrame({}{})".format(
return "{}({}{})".format(
type(self).__name__,
self.identifier,
optional_params)

Expand Down Expand Up @@ -568,7 +572,8 @@ def __repr__(self):
>>> CanBusErrorFrame(100, constants.CanCommState.BUS_OFF, True, constants.CanLastErr.STUFF, 1, 2)
CanBusErrorFrame(0x64, CanCommState.BUS_OFF, True, CanLastErr.STUFF, 1, 2)
"""
return "CanBusErrorFrame(0x{:x}, {}, {}, {}, {}, {})".format(
return "{}(0x{:x}, {}, {}, {}, {}, {})".format(
type(self).__name__,
self.timestamp,
self.state,
self.tcvr_err,
Expand Down Expand Up @@ -701,7 +706,8 @@ def __repr__(self):
optional_params = ', {}'.format(", ".join(optional))
else:
optional_params = ''
return "LinFrame(identifier=0x{:x}{})".format(
return "{}(identifier=0x{:x}{})".format(
type(self).__name__,
self.identifier,
optional_params)

Expand Down Expand Up @@ -800,7 +806,8 @@ def __repr__(self):
>>> LinBusErrorFrame(100, constants.LinCommState.INACTIVE, constants.LinLastErr.CRC, 1, 2, 3)
LinBusErrorFrame(0x64, LinCommState.INACTIVE, LinLastErr.CRC, 0x1, 2, 3)
"""
return "LinBusErrorFrame(0x{:x}, {}, {}, 0x{:x}, {}, {})".format(
return "{}(0x{:x}, {}, {}, 0x{:x}, {}, {})".format(
type(self).__name__,
self.timestamp,
self.state,
self.bus_err,
Expand Down Expand Up @@ -866,7 +873,7 @@ def __repr__(self):
>>> DelayFrame(250)
DelayFrame(250)
"""
return "DelayFrame({})".format(self.offset)
return "{}({})".format(type(self).__name__, self.offset)


class LogTriggerFrame(Frame):
Expand Down Expand Up @@ -930,7 +937,7 @@ def __repr__(self):
>>> LogTriggerFrame(250)
LogTriggerFrame(0xfa)
"""
return "LogTriggerFrame(0x{:x})".format(self.timestamp)
return "{}(0x{:x})".format(type(self).__name__, self.timestamp)


class StartTriggerFrame(Frame):
Expand Down Expand Up @@ -990,7 +997,7 @@ def __repr__(self):
>>> StartTriggerFrame(250)
StartTriggerFrame(0xfa)
"""
return "StartTriggerFrame(0x{:x})".format(self.timestamp)
return "{}(0x{:x})".format(type(self).__name__, self.timestamp)


class XnetFrame(FrameFactory):
Expand Down

0 comments on commit c7f9f0e

Please sign in to comment.