Skip to content

chore: update pre-commit#199

Open
danielsirakov wants to merge 3 commits into
diffpy:mainfrom
danielsirakov:pre-commit_edits
Open

chore: update pre-commit#199
danielsirakov wants to merge 3 commits into
diffpy:mainfrom
danielsirakov:pre-commit_edits

Conversation

@danielsirakov

Copy link
Copy Markdown

I re-did this as I forgot the news file

@danielsirakov

Copy link
Copy Markdown
Author

@stevenhua0320, ready to review

@stevenhua0320

Copy link
Copy Markdown
Contributor

@danielsirakov Have you run the pre-commit hook before you commit this? Seems that we have failing pre-commit test here. To do so, first do git pull origin pre-commit_edits and rerun pre-commit run --all-files, then make another commit to push everything to this PR.

@sbillinge

Copy link
Copy Markdown
Contributor

I don't love the changes that docformatter is introducing here either, by capitalizing the type.

This could be our fault. It is probably not a good idea to use the str: whatever the string is formalism. More normal would be describe what the thing is and then what the type is. Please can you guys look into what good standards are for this and let's see if it is too much work to bring this legacy code up to those standards.

@stevenhua0320

Copy link
Copy Markdown
Contributor

@sbillinge I have looked at the docstring changes that changed by docformatter and they could be categorized into two. One is the descriptive docstring that set after the variable and the other is the string attribute variable. I suggest for some of the docstring that we only have the descriptive functionality(the former case), we could change the descriptive style. Eg.

"""float: Conversion factor from B values to U values."""

to

"""The conversion factor from B values to U values, as a float

For some of the attribute definition string(the latter case), what I suggest is shadow the type of attribute with a pair of quote. So we ca do for example

title = ""
    """Str: The default value for `title`."""

to

title = ""
"""``str``: The default value for `title`."""

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I gave some thought here. Please can we try and make these fixes when finals are over and move this to a p3.14 release?


BtoU = 1.0 / (8 * numpy.pi**2)
"""float: Conversion factor from B values to U values."""
"""Float: Conversion factor from B values to U values."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@danielsirakov @stevenhua0320 we don't want string literals floating around in the code, so whenever we find things like this we want to clean them up. The correct fix in general is to move them to the docstring at the top of the function and put them into a standard format. Here, this may just be a constant and this should be changed from a string to a comment and placed above line 154.

"END",
]
"""list: Ordered list of PDB record labels."""
"""List: Ordered list of PDB record labels."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

another floating string literal. It is documenting the static data list. Gemini suggested that even though it is not declared as self. it is still considered as a class attribute and so should be documented in the class docstring, something like:

class P_pdb(StructureParser):
    """Simple parser for PDB format.

    The parser understands following PDB records: `TITLE, CRYST1, SCALE1,
    SCALE2, SCALE3, ATOM, SIGATM, ANISOU, SIGUIJ, TER, HETATM, END`.

    Attributes
    ----------
    format : str
        Format name, default "pdb".
    orderOfRecords : list
        The ordered list of PDB record labels.
    validRecords : dict
        The set of valid PDB record labels.
    """

We can discuss this more, but in general I think taking this advice and using it also in other places in the PR is the right approach

# instance attributes that have immutable default values
element = ""
"""str: Default values of `element`."""
"""Str: Default values of `element`."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this code seems just to be setting defaults, so the default values just have to be moved up to the attribute description in the docstring above and deleted from here, something like that.

# default values for instance attributes
title = ""
"""str: default values for `title`."""
"""Str: default values for `title`."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is default setting again.

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.

3 participants