Skip to content

Refactoring suggestins - #1

Open
frip wants to merge 9 commits into
Orasund:mainfrom
frip:refactoring
Open

Refactoring suggestins#1
frip wants to merge 9 commits into
Orasund:mainfrom
frip:refactoring

Conversation

@frip

@frip frip commented Apr 21, 2024

Copy link
Copy Markdown

My first shot at a github pull-request.
More may follow...

@Orasund

Orasund commented Apr 21, 2024

Copy link
Copy Markdown
Owner

Hi, by removing test.sh you have broken the CI pipeline.

The reason for having a generic test.sh is so that the CI pipeline can be language independed. I intend to do more languages besides python

@Orasund

Orasund commented Apr 21, 2024

Copy link
Copy Markdown
Owner

Hi, please rebase. I've moved the CI code into a ci.sh file.

As far as i can tell adding pyproject.toml broke the CI because now pytest is not included in the requirements.txt

@frip

frip commented Apr 21, 2024

Copy link
Copy Markdown
Author

Sorry, didn't see your answer in time!
But I found something interesting (I think) in diff_files.py L77ff: did you know, that your get_node() is called with y=-1? (What I am doing here is not stricktly refactoring, because I'm not returning the first element in the line...)

Comment thread diffFiles/src/diff_files.py
Comment thread diffFiles/tests/test_diff_files.py
Comment thread diffFiles/src/diff_files.py
def get_node(p: Position) -> Node:
result = nodes.get_node(p)
if result is None:
return Node(Position(0, 0), 0)

@frip frip Apr 21, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This here is my "tricky" fix for p.y=-1. It occurs in the "standard-test-case"!

@Orasund Orasund Apr 22, 2024

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm a bit puzzled. This is only possible if len(nodes.nodes[0] - 1) = -1 or next_pos.y = -1.

The first case occurs if the second file is empty. Second case occurs if I forgot a guard inside compute_node. In particular, this would mean that the cast is not current.

next_pos = candidate2
length = node2.length
else:
next_pos = candidate1

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In order for next_pos.y = -1 we would need to enter this branch with node1 is None (as there is a guard inside get_node). However, if node1 is None, then either branch 1 or 2 will be entered depending on node1 is None.

So im not seeing what should be wrong here.

@frip

frip commented Apr 22, 2024 via email

Copy link
Copy Markdown
Author

@Orasund

Orasund commented Apr 22, 2024

Copy link
Copy Markdown
Owner

Thanks a lot. I found the missing guard:

def compute_node(i1: int, i2: int) -> Node:
        next_pos: tuple[int, int] | None
        length: int

        if l1[i1] == l2[i2]:
            if i1 >= 0 and i2 >= 0:
                next_pos = (i1 - 1, i2 - 1)
                length = nodes[next_pos[0]][next_pos[1]].length + 1
            else:
                # this else branch was missing
                next_pos = None
                length = 0

@frip

frip commented Apr 23, 2024

Copy link
Copy Markdown
Author

I tried adding your guard in the hope that I could then reduce the second closure get_node() to the (new) Matrix-method, but it didn't work... :-(

@Orasund

Orasund commented Apr 23, 2024

Copy link
Copy Markdown
Owner

Oh! bad luck :/

Hope it's no a dealbreaker. Sadly, I don't have the time to look more into it.

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