Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC605 error is not specific enough, making its fixation a stuggle #211

Open
ssbarnea opened this issue Jan 27, 2025 · 1 comment
Open

Comments

@ssbarnea
Copy link

ssbarnea commented Jan 27, 2025

I do have a special care with a Class with more than 100 attributes and finding which attributes are not in order seems like finding the needle in the haystack. The error should at least give the first culprit in order to make it actionable.

DOC604: Class `ClassName`: Attributes are the same in docstring and class def, but are in a different order.  (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)

It also seems that there is no verbosity option available for pydoclint.

@jsh9
Copy link
Owner

jsh9 commented Jan 31, 2025

Hi @ssbarnea ,

Is this the instructions you are looking for? (ChatGPT helped me write this script; I haven't thoroughly tested it.)

def generate_reordering_steps(a: list, b: list) -> list[str]:
    if a == b:
        return ["b is already in the correct order."]
    
    index_map = {value: i for i, value in enumerate(b)}
    b_sorted = b[:]
    
    steps = []
    
    for i, expected in enumerate(a):
        current_index = index_map[expected]
        if current_index != i:
            steps.append(
                f"Swap '{b_sorted[i]}' at index {i} with '{b_sorted[current_index]}' at index {current_index}."
            )
            # Perform swap in the copy
            b_sorted[i], b_sorted[current_index] = b_sorted[current_index], b_sorted[i]
            # Update index map
            index_map[b_sorted[current_index]] = current_index
            index_map[b_sorted[i]] = i
    
    return steps

# Example usage:
a = list(range(10))
b = [8, 7, 2, 6, 4, 5, 3, 1, 0, 9]


steps = generate_reordering_steps(a, b)
for step in steps:
    print(step)

The output is:

Swap '8' at index 0 with '0' at index 8.
Swap '7' at index 1 with '1' at index 7.
Swap '6' at index 3 with '3' at index 6.

And both time and space complexity is O(n) (again, according to ChatGPT, and I haven't thoroughly tested 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

No branches or pull requests

2 participants