Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place automaton Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: Ic81c8d6f1270895437132bfccd676c79e6dfce30
This commit is contained in:
parent
68317f5bd7
commit
3e2d7a2094
@ -23,3 +23,8 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: hacking
|
- id: hacking
|
||||||
additional_dependencies: []
|
additional_dependencies: []
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.18.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py3-only]
|
||||||
|
@ -37,4 +37,4 @@ class FrozenMachine(AutomatonException):
|
|||||||
"""Exception raised when a frozen machine is modified."""
|
"""Exception raised when a frozen machine is modified."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(FrozenMachine, self).__init__("Frozen machine can't be modified")
|
super().__init__("Frozen machine can't be modified")
|
||||||
|
@ -20,7 +20,7 @@ from automaton import _utils as utils
|
|||||||
from automaton import exceptions as excp
|
from automaton import exceptions as excp
|
||||||
|
|
||||||
|
|
||||||
class State(object):
|
class State:
|
||||||
"""Container that defines needed components of a single state.
|
"""Container that defines needed components of a single state.
|
||||||
|
|
||||||
Usage of this and the :meth:`~.FiniteMachine.build` make creating finite
|
Usage of this and the :meth:`~.FiniteMachine.build` make creating finite
|
||||||
@ -58,7 +58,7 @@ def _orderedkeys(data, sort=True):
|
|||||||
return list(data)
|
return list(data)
|
||||||
|
|
||||||
|
|
||||||
class _Jump(object):
|
class _Jump:
|
||||||
"""A FSM transition tracks this data while jumping."""
|
"""A FSM transition tracks this data while jumping."""
|
||||||
def __init__(self, name, on_enter, on_exit):
|
def __init__(self, name, on_enter, on_exit):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -66,7 +66,7 @@ class _Jump(object):
|
|||||||
self.on_exit = on_exit
|
self.on_exit = on_exit
|
||||||
|
|
||||||
|
|
||||||
class FiniteMachine(object):
|
class FiniteMachine:
|
||||||
"""A finite state machine.
|
"""A finite state machine.
|
||||||
|
|
||||||
This state machine can be used to automatically run a given set of
|
This state machine can be used to automatically run a given set of
|
||||||
@ -413,7 +413,7 @@ class FiniteMachine(object):
|
|||||||
postfix_markings.append("^")
|
postfix_markings.append("^")
|
||||||
if self._states[state]['terminal']:
|
if self._states[state]['terminal']:
|
||||||
postfix_markings.append("$")
|
postfix_markings.append("$")
|
||||||
pretty_state = "%s%s" % ("".join(prefix_markings), state)
|
pretty_state = "{}{}".format("".join(prefix_markings), state)
|
||||||
if postfix_markings:
|
if postfix_markings:
|
||||||
pretty_state += "[%s]" % "".join(postfix_markings)
|
pretty_state += "[%s]" % "".join(postfix_markings)
|
||||||
if self._transitions[state]:
|
if self._transitions[state]:
|
||||||
@ -453,7 +453,7 @@ class HierarchicalFiniteMachine(FiniteMachine):
|
|||||||
'reaction,terminal,machine')
|
'reaction,terminal,machine')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(HierarchicalFiniteMachine, self).__init__()
|
super().__init__()
|
||||||
self._nested_machines = {}
|
self._nested_machines = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -475,15 +475,15 @@ class HierarchicalFiniteMachine(FiniteMachine):
|
|||||||
if machine is not None and not isinstance(machine, FiniteMachine):
|
if machine is not None and not isinstance(machine, FiniteMachine):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Nested state machines must themselves be state machines")
|
"Nested state machines must themselves be state machines")
|
||||||
super(HierarchicalFiniteMachine, self).add_state(
|
super().add_state(
|
||||||
state, terminal=terminal, on_enter=on_enter, on_exit=on_exit)
|
state, terminal=terminal, on_enter=on_enter, on_exit=on_exit)
|
||||||
if machine is not None:
|
if machine is not None:
|
||||||
self._states[state]['machine'] = machine
|
self._states[state]['machine'] = machine
|
||||||
self._nested_machines[state] = machine
|
self._nested_machines[state] = machine
|
||||||
|
|
||||||
def copy(self, shallow=False, unfreeze=False):
|
def copy(self, shallow=False, unfreeze=False):
|
||||||
c = super(HierarchicalFiniteMachine, self).copy(shallow=shallow,
|
c = super().copy(shallow=shallow,
|
||||||
unfreeze=unfreeze)
|
unfreeze=unfreeze)
|
||||||
if shallow:
|
if shallow:
|
||||||
c._nested_machines = self._nested_machines
|
c._nested_machines = self._nested_machines
|
||||||
else:
|
else:
|
||||||
@ -512,7 +512,7 @@ class HierarchicalFiniteMachine(FiniteMachine):
|
|||||||
also be used to initialize any state
|
also be used to initialize any state
|
||||||
machines they contain (recursively).
|
machines they contain (recursively).
|
||||||
"""
|
"""
|
||||||
super(HierarchicalFiniteMachine, self).initialize(
|
super().initialize(
|
||||||
start_state=start_state)
|
start_state=start_state)
|
||||||
for data in self._states.values():
|
for data in self._states.values():
|
||||||
if 'machine' in data:
|
if 'machine' in data:
|
||||||
|
@ -61,7 +61,7 @@ class FiniteRunner(Runner):
|
|||||||
"""Create a runner for the given machine."""
|
"""Create a runner for the given machine."""
|
||||||
if not isinstance(machine, (machines.FiniteMachine,)):
|
if not isinstance(machine, (machines.FiniteMachine,)):
|
||||||
raise TypeError("FiniteRunner only works with FiniteMachine(s)")
|
raise TypeError("FiniteRunner only works with FiniteMachine(s)")
|
||||||
super(FiniteRunner, self).__init__(machine)
|
super().__init__(machine)
|
||||||
|
|
||||||
def run(self, event, initialize=True):
|
def run(self, event, initialize=True):
|
||||||
for transition in self.run_iter(event, initialize=initialize):
|
for transition in self.run_iter(event, initialize=initialize):
|
||||||
@ -104,7 +104,7 @@ class HierarchicalRunner(Runner):
|
|||||||
if not isinstance(machine, (machines.HierarchicalFiniteMachine,)):
|
if not isinstance(machine, (machines.HierarchicalFiniteMachine,)):
|
||||||
raise TypeError("HierarchicalRunner only works with"
|
raise TypeError("HierarchicalRunner only works with"
|
||||||
" HierarchicalFiniteMachine(s)")
|
" HierarchicalFiniteMachine(s)")
|
||||||
super(HierarchicalRunner, self).__init__(machine)
|
super().__init__(machine)
|
||||||
|
|
||||||
def run(self, event, initialize=True):
|
def run(self, event, initialize=True):
|
||||||
for transition in self.run_iter(event, initialize=initialize):
|
for transition in self.run_iter(event, initialize=initialize):
|
||||||
|
@ -39,7 +39,7 @@ class FSMTest(testcase.TestCase):
|
|||||||
return m
|
return m
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(FSMTest, self).setUp()
|
super().setUp()
|
||||||
# NOTE(harlowja): this state machine will never stop if run() is used.
|
# NOTE(harlowja): this state machine will never stop if run() is used.
|
||||||
self.jumper = self._create_fsm("down", add_states=['up', 'down'])
|
self.jumper = self._create_fsm("down", add_states=['up', 'down'])
|
||||||
self.jumper.add_transition('down', 'up', 'jump')
|
self.jumper.add_transition('down', 'up', 'jump')
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
|
Loading…
x
Reference in New Issue
Block a user