chore: update pre-commit#199
Conversation
|
@stevenhua0320, ready to review |
|
@danielsirakov Have you run the |
|
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 |
|
@sbillinge I have looked at the docstring changes that changed by to 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 to |
sbillinge
left a comment
There was a problem hiding this comment.
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.""" |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Sounds good, I cleaned up most of them, but I just now realized there are a few that I missed so I'll go back to address them as well
| "END", | ||
| ] | ||
| """list: Ordered list of PDB record labels.""" | ||
| """List: Ordered list of PDB record labels.""" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Sounds good, I followed your format for this case and I will make sure to move other similar string literals I find to be documented in the class docstring
| # instance attributes that have immutable default values | ||
| element = "" | ||
| """str: Default values of `element`.""" | ||
| """Str: Default values of `element`.""" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Here is the format I've been using for moving defaults to the attribute description, let me know if this is fine or if I should go back and change it:
title : str
String description of the structure, default "".
There was a problem hiding this comment.
Descriptions always start with "The". Otherwise, this is good.
There was a problem hiding this comment.
Would this be fine for all:
title : str
The string description of the structure, default "".
There was a problem hiding this comment.
Would this be fine for all:
title : str The string description of the structure, default "".
Yes, this is right, you need to inspect the edits and whereever the description of the variable is not starting with "The", make a change for that. Thanks!
There was a problem hiding this comment.
I went in and quickly changed all descriptions in the "Attributes" docstrings in diffpy.structure to be in that format. I could also look more thoroughly and update the format for all descriptions in the repository if you'd like
| # default values for instance attributes | ||
| title = "" | ||
| """str: default values for `title`.""" | ||
| """Str: default values for `title`.""" |
There was a problem hiding this comment.
this is default setting again.
|
@danielsirakov gentle ping on this. |
Sounds good, I'll make the changes first thing tomorrow morning and ping you when ready tomorrow. |
|
I made the reformatting edits and I also added an additional fix where the doc-formatter was capitalizing "bool", "float", and "ndarray", which I fixed by adding a non-cap line for doc-formatter in pyproject.toml. I fixed the issue I mentioned on Slack (#344) by moving all of the string literals in structure.py from # linked atom attributes into the attributes section of the class Structure(list) docstring, and I added Rundong's fix in a few more spots. @stevenhua0320, ready to review |
| Coordinate system for the fractional coordinates `xyz` and | ||
| the tensor of atomic displacement parameters `U`. | ||
| Use the absolute Cartesian coordinates when ``None``. | ||
| Use the absolute Cartesian coordinates when ``None``, the default. |
There was a problem hiding this comment.
let's make it None as the default instead of connecting it by a comma to make it clearer for future developer to read.
There was a problem hiding this comment.
Would this be fine: Use the absolute Cartesian coordinates when ``None`` as the default.
There was a problem hiding this comment.
Thanks, just pushed the edit
|
I just pushed the edits to the descriptions in the "Attributes" docstrings where I added "The" and I also added the change to line 97 of atom.py |
|
|
||
| element = _link_atom_attribute( | ||
| "element", | ||
| """Character array of `Atom` types. Assignment updates |
There was a problem hiding this comment.
Please confirm whether it is a safe edit, in my opinion this is a not correct fix because originally we should have the middle string as a docstring for the argument in the python function. So, I don't think we should delete this. The description for this private function is referenced below.
def _link_atom_attribute(attrname, doc, toarray=numpy.array):
"""Create property wrapper that maps the specified atom attribute.
The returned property object provides convenient access to atom
attributes from the owner `Structure` class.
Parameters
----------
attrname : str
The string name of the `Atom` class attribute to be mapped.
doc : str
The docstring for the property wrapper.
toarray : callable, Optional
Factory function that converts list of attributes to `numpy.ndarray`.
Use `numpy.char.array` for string attributes.
Return a property object.
"""
There was a problem hiding this comment.
How could I check to confirm whether it's safe? Should I bring the strings back for the other ones as well or just for element?
There was a problem hiding this comment.
How could I check to confirm whether it's safe? Should I bring the strings back for the other ones as well or just for element?
Even though from my base knowledge it is incorrect, You could run the functional testing/ pytest to confirm whether it is correct. To fix this, you need to paste the deleted string back and rerun the pre-commit and see if it could do the right fix to the formatting.
There was a problem hiding this comment.
I ran pytest just to check, and it seemed that my edits to _link_atom_attribute didn't actually end up breaking anything. I found that there were 10 failures, but I ran pytest on main as well, and it seemed that they showed up there too, meaning that they were related to a different PR (#187), and the other 219 tests passed with my edits. I'm not sure why this is or if it's something that pytest missed, and if you want, I could still try to reinsert the deleted string and see if the pre-commit reformats it correctly.
There was a problem hiding this comment.
I tried re-inserting the string, but it led to black and docformatter going back and forth again, and as far as I'm aware this doesn't have any other easy fix besides removing the string as it is issue #344 (PyCQA/docformatter#344)
There was a problem hiding this comment.
You can find a usage of this private function and see whether it could still be running properly. But from my observation here since you deleted one argument here, you only give the function one argument while it usually expects two arguments.
There was a problem hiding this comment.
I see, is there any other way that you recommend for me to reformat the deleted string to bypass the docformatter and black issues?
There was a problem hiding this comment.
@danielsirakov you could first try on this kind of edit:
label = _link_atom_attribute(
"label",
(
"Character array of `Atom` names. Assignment updates "
"the label attribute of all `Atoms`. "
"Set the maximum length of the label string to 5 characters."
),
toarray=lambda items: numpy.char.array(items, itemsize=5),
)
which bypass the triple quotes using quotes to concatenate the string. Then use this format to rerun the pre-commit hook to see whether we could bypass the bug.
There was a problem hiding this comment.
Good idea, I'll give it a try
There was a problem hiding this comment.
It worked! I'll make the same change to element as well and then push
| @property | ||
| def Uisoequiv(self): | ||
| """float : The isotropic displacement parameter or an equivalent value. | ||
| """float : The isotropic displacement parameter or an equivalent |
There was a problem hiding this comment.
Please put into standard form. Don't lead with the type
| @property | ||
| def Bisoequiv(self): | ||
| """float : The Debye-Waller isotropic displacement or an equivalent value. | ||
| """float : The Debye-Waller isotropic displacement or an |
| """int: Width of boundary around corners of non-periodic cluster. | ||
| Retained from the original AtomEye/XCFG parser for API compatibility. | ||
| VESTA handles periodicity natively so this value has no effect on output. | ||
| """Int: Width of boundary around corners of non-periodic cluster. |
|
|
||
| element = _link_atom_attribute( | ||
| "element", | ||
| """Character array of `Atom` types. Assignment updates |
There was a problem hiding this comment.
I agree with @stevenhua0320 that we need to check that the tests are still working. Tests passing is not a test of tests working. For example assert True will pass but not test anything.
|
I made a few more fixes to string formatting and also reinstated the strings in the format that bypasses triple quotes. |
I re-did this as I forgot the news file