Skip to content

Expand type annotations and add classes for path item handling#412

Open
pappnu wants to merge 32 commits into
loonghao:mainfrom
pappnu:type-annotation
Open

Expand type annotations and add classes for path item handling#412
pappnu wants to merge 32 commits into
loonghao:mainfrom
pappnu:type-annotation

Conversation

@pappnu

@pappnu pappnu commented Aug 12, 2025

Copy link
Copy Markdown

This PR adds extensive type annotations, various missing properties, classes for interacting with path items and tries to lessen some of the repetition within the code. The type annotations don't cover everything, especially things that would have required creating new wrapper classes. The annotations are mostly based on Photoshop Scripting Reference and Photoshop VBS Scripting Reference 2020.

Breaking Changes

  • Python requirement is raised to 3.10 because of the used syntax.
  • Removes Application.compareWithNumbers, Application.system and Session.echo functions as they simply wrapped basic Python actions without adding any extra functionality to them, so I assumed they aren't really necessary.
  • getByName now returns None instead of throwing, as I find that easier to work with in a strictly typed codebase.

Testing

I added some tests of my own and ran some of the existing tests, though many of them didn't pass even when using the version from main branch. I have also used this extensively with Proxyshop, which uses especially the basic layer modification and action manager parts of the API. There's still many untested properties and functions, so bugs are quite likely.

This might also help with #405.

Please let me know what further changes would be required to get this merged.

@pappnu

pappnu commented May 26, 2026

Copy link
Copy Markdown
Author

@loonghao The hound bot seems to complain about valid overload definitions and its documentation suggests that it is using a very old version of Flake8. Should it be removed from the project? I assume that there would be more up to date alternatives, though I'm not familiar with such tools. The pull request workflows also check at least partially the same things that the hound bot does.

pappnu added 2 commits June 13, 2026 06:21
Ruff does basically everything that the aforementioned tools do, but more efficiently and with less configuration.
resolution (int): The resolution of the document (in pixels per inch)
width (float): The width of the document. Non-integer values are converted to integers.
height (float): The height of the document. Non-integer values are converted to integers.
resolution (float): The resolution of the document (in pixels per inch)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (83 > 79 characters)

height (int): The height of the document.
resolution (int): The resolution of the document (in pixels per inch)
width (float): The width of the document. Non-integer values are converted to integers.
height (float): The height of the document. Non-integer values are converted to integers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (101 > 79 characters)

width (int): The width of the document.
height (int): The height of the document.
resolution (int): The resolution of the document (in pixels per inch)
width (float): The width of the document. Non-integer values are converted to integers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (99 > 79 characters)

"""
dup = self.app.duplicate(relativeObject, insertionLocation)
return ArtLayer(dup)
return ArtLayer(self.app.duplicate(relativeObject.app if relativeObject else None, insertionLocation))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (110 > 79 characters)

self.app.applyOceanRipple(size, magnitude)

def applyOffset(self, horizontal, vertical, undefinedAreas):
def applyOffset(self, horizontal: int, vertical: int, undefinedAreas: OffsetUndefinedAreas) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (104 > 79 characters)

resolution: The resolution (in pixels per inch)
automatic: Value for automatic.
resampleMethod: The downsample method.
amount: Amount of noise value when using preserve details (range: 0 - 100)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (86 > 79 characters)

self.app.splitChannels()

def suspendHistory(self, historyString, javaScriptString):
def suspendHistory(self, historyString: str, javaScriptString: str) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

asCopy: Saves the document as a copy, leaving the original open.
"""
return self.app.saveAs(file_path, options, asCopy, extensionType)
self.app.saveAs(file_path, options.app if options else None, asCopy, extensionType)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 79 characters)

self.app.rasterizeAllLayers()

def recordMeasurements(self, source, dataPoints):
def recordMeasurements(self, source: MeasurementSource, dataPoints: str) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (85 > 79 characters)

self.app.export(file_path, exportAs, options.app)

def duplicate(self, name=None, merge_layers_only=False):
def duplicate(self, name: str | None = None, merge_layers_only: bool = False) -> "Document":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (96 > 79 characters)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant