diff --git a/photoshop/api/action_manager/__init__.py b/photoshop/api/action_manager/__init__.py index a579d1e8..b9ab3d35 100644 --- a/photoshop/api/action_manager/__init__.py +++ b/photoshop/api/action_manager/__init__.py @@ -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 diff --git a/photoshop/api/action_manager/_main_types/_type_mapper.py b/photoshop/api/action_manager/_main_types/_type_mapper.py index 06f5b88c..37016520 100644 --- a/photoshop/api/action_manager/_main_types/_type_mapper.py +++ b/photoshop/api/action_manager/_main_types/_type_mapper.py @@ -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"] @@ -34,7 +35,7 @@ def unpack(val): typestr = pytype2str[vtype] try: args = val._unpacker() - except: + except BaseException: args = (val,) return (typestr, args) diff --git a/photoshop/api/action_manager/_main_types/action_descriptor.py b/photoshop/api/action_manager/_main_types/action_descriptor.py index 70256db8..3208afad 100644 --- a/photoshop/api/action_manager/_main_types/action_descriptor.py +++ b/photoshop/api/action_manager/_main_types/action_descriptor.py @@ -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.""" diff --git a/photoshop/api/action_manager/_main_types/action_descriptor_iterator.py b/photoshop/api/action_manager/_main_types/action_descriptor_iterator.py index 066a8069..e2ee3303 100644 --- a/photoshop/api/action_manager/_main_types/action_descriptor_iterator.py +++ b/photoshop/api/action_manager/_main_types/action_descriptor_iterator.py @@ -1,10 +1,10 @@ -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 @@ -12,7 +12,7 @@ def __next__(self) -> str: self.n += 1 try: keyid = self.curobj.getKey(self.n) - except: + except BaseException: raise StopIteration keystr = id2str(keyid) return keystr diff --git a/photoshop/api/action_manager/_main_types/action_list.py b/photoshop/api/action_manager/_main_types/action_list.py index 5d719bf8..601cef73 100644 --- a/photoshop/api/action_manager/_main_types/action_list.py +++ b/photoshop/api/action_manager/_main_types/action_list.py @@ -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 diff --git a/photoshop/api/action_manager/_main_types/action_list_iterator.py b/photoshop/api/action_manager/_main_types/action_list_iterator.py index 9de7e352..b269ea56 100644 --- a/photoshop/api/action_manager/_main_types/action_list_iterator.py +++ b/photoshop/api/action_manager/_main_types/action_list_iterator.py @@ -5,7 +5,7 @@ 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 @@ -13,7 +13,7 @@ def __next__(self) -> Any: self.n += 1 try: elem = self.curobj.uget(self.n) - except: + except BaseException: raise StopIteration() return elem diff --git a/photoshop/api/action_manager/_main_types/action_reference.py b/photoshop/api/action_manager/_main_types/action_reference.py index 75f57680..d35bb5ba 100644 --- a/photoshop/api/action_manager/_main_types/action_reference.py +++ b/photoshop/api/action_manager/_main_types/action_reference.py @@ -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) @@ -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 @@ -54,7 +53,7 @@ def __len__(self): try: target = target.getContainer() rlen += 1 - except: + except BaseException: rlen -= 1 break return rlen diff --git a/photoshop/api/action_manager/_main_types/action_reference_iterator.py b/photoshop/api/action_manager/_main_types/action_reference_iterator.py index 6eb6e8d9..2f93ac29 100644 --- a/photoshop/api/action_manager/_main_types/action_reference_iterator.py +++ b/photoshop/api/action_manager/_main_types/action_reference_iterator.py @@ -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 @@ -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) diff --git a/photoshop/api/action_manager/desc_value_types/enumerated.py b/photoshop/api/action_manager/desc_value_types/enumerated.py index bc97b00a..97607b2e 100644 --- a/photoshop/api/action_manager/desc_value_types/enumerated.py +++ b/photoshop/api/action_manager/desc_value_types/enumerated.py @@ -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"]) diff --git a/photoshop/api/action_manager/desc_value_types/typeid.py b/photoshop/api/action_manager/desc_value_types/typeid.py index 2897f352..0fc10a19 100644 --- a/photoshop/api/action_manager/desc_value_types/typeid.py +++ b/photoshop/api/action_manager/desc_value_types/typeid.py @@ -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"]) diff --git a/photoshop/api/action_manager/desc_value_types/unitdouble.py b/photoshop/api/action_manager/desc_value_types/unitdouble.py index 83b734bd..0d0ee5a9 100644 --- a/photoshop/api/action_manager/desc_value_types/unitdouble.py +++ b/photoshop/api/action_manager/desc_value_types/unitdouble.py @@ -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"]) diff --git a/photoshop/api/action_manager/jprint.py b/photoshop/api/action_manager/jprint.py index 56e2d72f..fe1daf4f 100644 --- a/photoshop/api/action_manager/jprint.py +++ b/photoshop/api/action_manager/jprint.py @@ -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 diff --git a/photoshop/api/action_manager/js_converter/__init__.py b/photoshop/api/action_manager/js_converter/__init__.py index 2d29a8f1..b12651f5 100644 --- a/photoshop/api/action_manager/js_converter/__init__.py +++ b/photoshop/api/action_manager/js_converter/__init__.py @@ -1 +1,4 @@ from .convert import dump + + +__all__ = ["dump"] diff --git a/photoshop/api/action_manager/js_converter/convert.py b/photoshop/api/action_manager/js_converter/convert.py index cfe671c7..6f84fa82 100644 --- a/photoshop/api/action_manager/js_converter/convert.py +++ b/photoshop/api/action_manager/js_converter/convert.py @@ -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 @@ -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"]) diff --git a/photoshop/api/action_manager/js_converter/injection_js.py b/photoshop/api/action_manager/js_converter/injection_js.py index db14ad05..6d2c07a4 100644 --- a/photoshop/api/action_manager/js_converter/injection_js.py +++ b/photoshop/api/action_manager/js_converter/injection_js.py @@ -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. diff --git a/photoshop/api/action_manager/js_converter/node_execjs.py b/photoshop/api/action_manager/js_converter/node_execjs.py index 0604c6a8..a8789a49 100644 --- a/photoshop/api/action_manager/js_converter/node_execjs.py +++ b/photoshop/api/action_manager/js_converter/node_execjs.py @@ -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!") diff --git a/photoshop/api/action_manager/ref_form_types/_marker.py b/photoshop/api/action_manager/ref_form_types/_marker.py index 50d60fec..5a0c20b2 100644 --- a/photoshop/api/action_manager/ref_form_types/_marker.py +++ b/photoshop/api/action_manager/ref_form_types/_marker.py @@ -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 diff --git a/photoshop/api/action_manager/ref_form_types/referencekey.py b/photoshop/api/action_manager/ref_form_types/referencekey.py index 955478b4..20e5333d 100644 --- a/photoshop/api/action_manager/ref_form_types/referencekey.py +++ b/photoshop/api/action_manager/ref_form_types/referencekey.py @@ -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 = { @@ -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 diff --git a/photoshop/api/action_manager/utils.py b/photoshop/api/action_manager/utils.py index 293238e0..69464515 100644 --- a/photoshop/api/action_manager/utils.py +++ b/photoshop/api/action_manager/utils.py @@ -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)