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

odd rendering of dataclass __init__ method #404

Closed
Lx opened this issue Jun 8, 2022 · 4 comments
Closed

odd rendering of dataclass __init__ method #404

Lx opened this issue Jun 8, 2022 · 4 comments
Labels

Comments

@Lx
Copy link

Lx commented Jun 8, 2022

Problem Description

Given this dataclass definition:

@dataclass(frozen=True, slots=True)
class ShiftChange:
    """A single instance of one shift being added or deleted, and when."""

    shift: Shift
    """The shift that this change concerns."""

    exists: bool
    """Whether the shift exists after the operation (i.e. it was added)."""

    window: TimeWindow
    """When the change occurred."""

pdoc renders the __init__ method like this:

image

I noted in particular:

  • the comma placement between the shift and exists parameters
  • the placement of the window parameter on the same line as the exists parameter, but not the shift parameter.

System Information

❯ pdoc --version
pdoc: 12.0.1
Python: 3.10.4
Platform: macOS-12.4-arm64-arm-64bit
@Lx Lx added the bug label Jun 8, 2022
@mhils
Copy link
Member

mhils commented Jun 8, 2022

Could you please post a full self-contained example? The following works just fine for me:

clerk.py

from dataclasses import dataclass

class objects:
    class shift:
        class Shift: pass
    class timewindow:
        class TimeWindow: pass

Shift = objects.shift.Shift
TimeWindow = objects.timewindow.TimeWindow

@dataclass(frozen=True, slots=True)
class ShiftChange:
    """A single instance of one shift being added or deleted, and when."""

    shift: Shift
    """The shift that this change concerns."""

    exists: bool
    """Whether the shift exists after the operation (i.e. it was added)."""

    window: TimeWindow
    """When the change occurred."""

image

@Lx
Copy link
Author

Lx commented Jun 8, 2022

If I put all the classes into one single file (in an attempt to offer you a self-contained example), then the problem disappears. So this:

from dataclasses import dataclass

# from .shift import Shift


class Shift:
    pass


class TimeWindow:
    pass


@dataclass(frozen=True, slots=True)
class ShiftChange:
    """A single instance of one shift being added or deleted, and when."""

    shift: Shift
    """The shift that this change concerns."""

    exists: bool
    """Whether the shift exists after the operation (i.e. it was added)."""

    window: TimeWindow
    """When the change occurred."""

renders with no issue:

image

but if the class Shift: pass is commented out and the from .shift import Shift line is re-introduced, it looks like this again:

image

However, notably, even if the sibling shift.py file contains only this:

class Shift:
    pass

the formatting is still broken, so it's not a matter of what's in shift.py.


Also for what it's worth, it's apparently not limited to __init__—here's some odd rendering from another file:

image

noting in particular the splitting of my old parameter's type definition across different lines and indentation levels.

@mhils
Copy link
Member

mhils commented Jun 8, 2022

Ah, now I can repro. Thanks! Fixed in a34e22c, a new release should be out in a few minutes. 😃

@mhils mhils closed this as completed Jun 8, 2022
@Lx
Copy link
Author

Lx commented Jun 9, 2022

All looking perfect in v12.0.2. Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants