Skip to content

Commit

Permalink
style(action_manager): extinguish flake8 error
Browse files Browse the repository at this point in the history
  • Loading branch information
TsXor committed Sep 7, 2022
1 parent 4461d91 commit fe848d5
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 40 deletions.
15 changes: 11 additions & 4 deletions photoshop/api/action_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from .desc_value_types import *
from .jprint import *
from .desc_value_types import Enumerated
from .desc_value_types import TypeID
from .desc_value_types import UnitDouble
from .jprint import jformat
from .jprint import jprint
from .js_converter import dump as dumpjs
from .ref_form_types import *
from .utils import *
from .ref_form_types import Identifier
from .ref_form_types import Index
from .ref_form_types import Offset
from .ref_form_types import ReferenceKey
from .utils import id2str
from .utils import str2id


__all__ = [ # noqa: F405
Expand Down
9 changes: 5 additions & 4 deletions photoshop/api/action_manager/_main_types/_type_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Handles almost all type mappings. (Some else are in ReferenceKey.)
This module is INTERNAL. You should not import functions from it."""

from ..desc_value_types import *
from ..ref_form_types import *
from ..utils import *
from ..desc_value_types import Enumerated
from ..desc_value_types import TypeID
from ..desc_value_types import UnitDouble
from ..utils import id2str


__all__ = ["unpack", "pack", "parsetype"]
Expand Down Expand Up @@ -34,7 +35,7 @@ def unpack(val):
typestr = pytype2str[vtype]
try:
args = val._unpacker()
except:
except BaseException:
args = (val,)
return (typestr, args)

Expand Down
8 changes: 5 additions & 3 deletions photoshop/api/action_manager/_main_types/action_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from abc import abstractclassmethod
from typing import Any

from ..utils import *
from ._type_mapper import *
from ..utils import str2id
from ._type_mapper import pack
from ._type_mapper import parsetype
from ._type_mapper import unpack
from .action_descriptor_iterator import ActionDescriptor_Iterator


class ActionDescriptor:
class ActionDescriptor(ABC):
"""A vessel for my extra utils.
You should not use, and cannot initialize it
because it is an abstract class."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from ..utils import *
from ..utils import id2str


class ActionDescriptor_Iterator:
"""An iterator. You don't need to initialize it manually."""

def __init__(self, psobj: "ActionDescriptor"):
def __init__(self, psobj):
self.curobj = psobj
self.n = -1

def __next__(self) -> str:
self.n += 1
try:
keyid = self.curobj.getKey(self.n)
except:
except BaseException:
raise StopIteration
keystr = id2str(keyid)
return keystr
Expand Down
5 changes: 3 additions & 2 deletions photoshop/api/action_manager/_main_types/action_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from abc import abstractclassmethod
from typing import Any

from ..utils import *
from ._type_mapper import *
from ._type_mapper import pack
from ._type_mapper import parsetype
from ._type_mapper import unpack
from .action_list_iterator import ActionList_Iterator


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
class ActionList_Iterator:
"""An iterator. You don't need to initialize it manually."""

def __init__(self, psobj: "ActionList"):
def __init__(self, psobj):
self.curobj = psobj
self.n = -1

def __next__(self) -> Any:
self.n += 1
try:
elem = self.curobj.uget(self.n)
except:
except BaseException:
raise StopIteration()
return elem

Expand Down
5 changes: 2 additions & 3 deletions photoshop/api/action_manager/_main_types/action_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def uget(self, index: int) -> ReferenceKey:
for i in range(index + 1):
try:
target = target.getContainer()
except:
except BaseException:
raise IndexError("index out of range")
return ReferenceKey._packer(target)

Expand All @@ -42,7 +42,6 @@ def uput(self, rkey: ReferenceKey):

def dump(self) -> list:
"""Convert an ActionReference to a python object."""
target = self
tlist = ["!ref"]
tlist.extend([elem for elem in self])
return tlist
Expand All @@ -54,7 +53,7 @@ def __len__(self):
try:
target = target.getContainer()
rlen += 1
except:
except BaseException:
rlen -= 1
break
return rlen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ActionReference_Iterator:
"""An iterator. You don't need to initialize it manually."""

def __init__(self, psobj: "ActionReference"):
def __init__(self, psobj):
self.curobj = psobj
self.init = True
self.n = -1
Expand All @@ -17,7 +17,7 @@ def __next__(self) -> ReferenceKey:
self.curobj = self.curobj.getContainer()
try:
self.curobj.getContainer()
except:
except BaseException:
raise StopIteration
return ReferenceKey._packer(self.curobj)

Expand Down
3 changes: 2 additions & 1 deletion photoshop/api/action_manager/desc_value_types/enumerated.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Import built-in modules
from collections import namedtuple

from ..utils import *
from ..utils import id2str
from ..utils import str2id


Enumerated_proto = namedtuple("Enumerated_proto", ["type", "value"])
Expand Down
3 changes: 2 additions & 1 deletion photoshop/api/action_manager/desc_value_types/typeid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Import built-in modules
from collections import namedtuple

from ..utils import *
from ..utils import id2str
from ..utils import str2id


TypeID_proto = namedtuple("TypeID_proto", ["string"])
Expand Down
3 changes: 2 additions & 1 deletion photoshop/api/action_manager/desc_value_types/unitdouble.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Import built-in modules
from collections import namedtuple

from ..utils import *
from ..utils import id2str
from ..utils import str2id


UnitDouble_proto = namedtuple("UnitDouble_proto", ["unit", "double"])
Expand Down
2 changes: 1 addition & 1 deletion photoshop/api/action_manager/jprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def jformat(astr, indent=4, prefix=None):
indent_level -= 1
char = "\n" + " " * (indent * indent_level) + char
nstr += char
if not prefix is None:
if prefix is not None:
for kwd in all_am_keywords:
nstr = nstr.replace(kwd, prefix + "." + kwd)
return nstr
Expand Down
3 changes: 3 additions & 0 deletions photoshop/api/action_manager/js_converter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .convert import dump


__all__ = ["dump"]
13 changes: 8 additions & 5 deletions photoshop/api/action_manager/js_converter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
# Import built-in modules
import json

from ..desc_value_types import *
from ..ref_form_types import *
from ..utils import hash2str
from ..desc_value_types import Enumerated
from ..desc_value_types import TypeID
from ..desc_value_types import UnitDouble
from ..ref_form_types import Identifier
from ..ref_form_types import Index
from ..ref_form_types import Offset
from ..ref_form_types import ReferenceKey
from ..utils import id2str
from ..utils import str2hash
from ..utils import str2id
from .injection_js import injection
from .node_execjs import execjs

Expand Down Expand Up @@ -59,7 +62,7 @@ def unhead(string):


def parsedict(tdict):
if not "_classID" in tdict:
if "_classID" not in tdict:
tdict["_classID"] = None
else:
tdict["_classID"] = unhead(tdict["_classID"])
Expand Down
2 changes: 2 additions & 0 deletions photoshop/api/action_manager/js_converter/injection_js.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# flake8: noqa

"""Defines injection, a variable which contains js code.
These js code implements Photoshop functions, and lures a piece of js code
to output all its information on executing executeAction function.
Expand Down
2 changes: 1 addition & 1 deletion photoshop/api/action_manager/js_converter/node_execjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Node.js check
nodestate = os.popen("node --version")
if not re.match("^v\d*\.\d*\.\d*", nodestate.read()):
if not re.match(r"^v\d*\.\d*\.\d*", nodestate.read()):
raise RuntimeError("Please check if Node.js is installed to PATH!")


Expand Down
2 changes: 1 addition & 1 deletion photoshop/api/action_manager/ref_form_types/_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def __repr__(self):
def __eq__(self, other):
try:
return self.name == other.name and self.value == other.value
except:
except BaseException:
return False
13 changes: 8 additions & 5 deletions photoshop/api/action_manager/ref_form_types/referencekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

from ..desc_value_types import Enumerated
from ..desc_value_types import TypeID
from ..utils import *
from ..utils import id2str
from ..utils import str2id
from ._marker import marker
from .identifier import Identifier
from .index import Index
from .offset import Offset

# Identifier, Index, Offset are used by getting them in globals().
from .identifier import Identifier # noqa: F401
from .index import Index # noqa: F401
from .offset import Offset # noqa: F401


psreftype2str = {
Expand All @@ -31,7 +34,7 @@ def _packer(cls, obj):
dcls = id2str(obj.getDesiredClass())
try:
get_func = getattr(obj, "get" + ftype)
except:
except BaseException:
get_func = None
if ftype == "Class":
v = None
Expand Down
2 changes: 1 addition & 1 deletion photoshop/api/action_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def str2id(psstr: str) -> str:
typeid = str2hash(psstr)
try:
restr = converter.id2str(psstr)
except:
except BaseException:
restr = ""
if not restr:
typeid = converter.str2id(psstr)
Expand Down

0 comments on commit fe848d5

Please sign in to comment.