Skip to content

Conversation

@HSY-999
Copy link

@HSY-999 HSY-999 commented Nov 21, 2025

see #3467

there are a couple different solutions. this is the one i made.

for my solution, i have to assume that the key name inside DictionaryObject == __init__ parameter names. for example /Vertices and vertices. with these changes the example in #3467 exits normally.

i had to modify the __init__ logic for Polygon and PolyLine, as they both expected tuples which is not the format they are stored in DictionaryObject

if we agree this is acceptable solution, i will also add test case adapted from the issue.

@HSY-999 HSY-999 changed the title BUG: fix for merge page #3467 BUG: fix for merge page with annotation #3467 Nov 21, 2025
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

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

Please have a look at the test failures and add appropriate tests.

Additionally, while your current approach might work for the current cases, I see some limitations/aspects to discuss:

  • What happens to keyword-only arguments?
  • What happens to unmatched keys?
  • What happens to keys which have to be renamed for some reasons, for example because they conflict with an existing name (like a builtin)?

Please provide some details on how you think about this and what your proposals for mitigating them are.

super().__init__(**kwargs)
if len(vertices) == 0:
raise ValueError("A polygon needs at least 1 vertex with two coordinates")
if len(vertices) == 0 or len(vertices) % 2 != 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this new check relate to your changes and why does the error message need a rewording?

Copy link
Author

Choose a reason for hiding this comment

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

there exists a case where an ArrayObject could be passed with an odd number of positions. len(vertices) % 2 checks for an even number of positions.

i modified the error message to be more precise to the case i was considering.

for x, y in vertices:
coord_list.append(NumberObject(x))
coord_list.append(NumberObject(y))
if type(vertices) is ArrayObject:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not isinstance(vertices, ArrayObject)?

Copy link
Author

Choose a reason for hiding this comment

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

you have taught me something about python 😃

if type(vertices) is ArrayObject:
import itertools
coord_list = vertices
vertices = [vertex for vertex in itertools.batched(vertices, 2)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

itertools.batched requires Python >= 3.12, while we have to support Python >= 3.9.

super().__init__(**kwargs)
if len(vertices) == 0:
raise ValueError("A polygon needs at least 1 vertex with two coordinates")
if len(vertices) == 0 or len(vertices) % 2 != 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please avoid unnecessary repetition by extracting common functionality.

Copy link
Author

Choose a reason for hiding this comment

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

PolyLine could be considered a parent class of Polygon. i could also make a abstract class for these two if that is better.

both implementations we can remove repetition

@HSY-999
Copy link
Author

HSY-999 commented Nov 24, 2025

* What happens to keyword-only arguments?

it does not work in a small example, but inspect does support matching on keyword arguments in a different list[str] with kwonlyargs. an additional check for this would suffice.

* What happens to unmatched keys?

they are not passed along to __init__ of the class we are trying to clone.

* What happens to keys which have to be renamed for some reasons, for example because they conflict with an existing name (like a builtin)?

good point. i will think on this. i am thinking of having some internal value in DictionaryObject or PdfObject which allow a developer to write its own key value pair if they are not the same.

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.

2 participants