Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

PR: Static analysis pass.#82

Merged
KelSolaar merged 1 commit intogtaylor:masterfrom
colour-science:feature/static_analysis
Feb 21, 2018
Merged

PR: Static analysis pass.#82
KelSolaar merged 1 commit intogtaylor:masterfrom
colour-science:feature/static_analysis

Conversation

@KelSolaar
Copy link
Copy Markdown
Collaborator

I performed an first static analysis pass over the codebase with PyCharm and Codacy.

Copy link
Copy Markdown

@rec rec left a comment

Choose a reason for hiding this comment

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

Just a few comments from a bystander...


lchab = LCHabColor(40.0, 104.0, 40.0)
rgb = convert_color(lchab, AdobeRGBColor)
_rgb = convert_color(lchab, AdobeRGBColor)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change seems pointless, as rgb is a local variable.

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.

Agreed. We're also a bit inconsistent with `test_conversion_to_rgb_zero_div and others now, too.

Comment thread colormath/color_conversions.py Outdated
hsv_h = var_H
hsv_s = var_S
hsv_v = var_V
# TODO: Investigate intent of following code block.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're simply making work for the next person. Those variables are not used - just delete them.

Copy link
Copy Markdown
Collaborator Author

@KelSolaar KelSolaar Jan 29, 2018

Choose a reason for hiding this comment

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

You're simply making work for the next person.

The next person would actually be me and the note is actually for me. To give you some context I have been discussing with @gtaylor during the last few weeks to take over the maintenance of python-colormath.

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.

We probably could go on ahead and remove these. If we're worried about needing to back them out in the future, these can be done in atomic, easily-reverted commits.

rgb_type = target_rgb
else:
rgb_type = cobj.rgb_type
# if target_rgb is not None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are changing the meaning of the code here, by commenting out this block. Are you 100% sure that no clients use this functionality?

(Also, if you keep the code, it could be more easily written as rgb_type = target_rgb or cobj.rgb_type.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

rgb_type is not used in the remaining definition code and I have just noticed that I missed a similar construct here: https://github.com/colour-science/python-colormath/blob/6d4ac23c7913974f6d5a2072b17ea94fb62ced24/colormath/color_conversions.py#L769

I introspected the codebase with a debugger to understand what was the intent of the code block without much clue, commented the block and the unit tests are running successfully.

If there is a hidden magical behaviour, I would be happy to know about it.

Comment thread colormath/__init__.py Outdated
@@ -1 +1,3 @@
#!/usr/bin/env python
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't understand why you are adding this first line to all the files. You aren't ever going to call __init__.py directly as a script, and you couldn't do it anyway because it isn't marked as +x and because you don't have a if __name__ == '__main': clause.

Generally, you add #!/usr/bin/env python to the top of Python files exactly if they are going to be called as standalone scripts. Typically this is only for a couple of files in a project.

Copy link
Copy Markdown
Collaborator Author

@KelSolaar KelSolaar Jan 29, 2018

Choose a reason for hiding this comment

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

Hi @rec!

I brought this line along with the encoding one. I actually needed and still need to launch quickly any of the modules, i.e. good when introspecting a codebase. You don't need a if __name__ == '__main': clause to run content of any Python module and on Windows you don't need to make the script executable at all, see PEP 397.

The fact the line is here does not really hurt and makes some things easier for me.

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.

Definitely understand how it may help your particular workflow, but this is a bit of an anti-pattern. We should probably be optimizing worfkflows around the test suite.

Copy link
Copy Markdown
Owner

@gtaylor gtaylor left a comment

Choose a reason for hiding this comment

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

Many apologies for the delay, and many thanks for the PR! Just a few assorted comments.

Comment thread colormath/color_conversions.py Outdated
hsv_h = var_H
hsv_s = var_S
hsv_v = var_V
# TODO: Investigate intent of following code block.
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.

We probably could go on ahead and remove these. If we're worried about needing to back them out in the future, these can be done in atomic, easily-reverted commits.

else:
raise ValueError("Unable to convert HSL->RGB due to value error.")

# TODO: Investigate intent of following code block.
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'd suggest an issue tracker with a link to the line, pinned to a certain git sha (to prevent code shifting from breaking your link).


lchab = LCHabColor(40.0, 104.0, 40.0)
rgb = convert_color(lchab, AdobeRGBColor)
_rgb = convert_color(lchab, AdobeRGBColor)
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.

Agreed. We're also a bit inconsistent with `test_conversion_to_rgb_zero_div and others now, too.

# In case the white-points are still input as strings
# Get white-points for illuminant
if type(wp_src) == str:
if isinstance(wp_src, str):
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.

Worth considering basestring instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

basestring does not exist in Python 3.x so we would need to either account for it or use six which is cleaner and more portable.

Comment thread colormath/__init__.py Outdated
@@ -1 +1,3 @@
#!/usr/bin/env python
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.

Definitely understand how it may help your particular workflow, but this is a bit of an anti-pattern. We should probably be optimizing worfkflows around the test suite.

@KelSolaar KelSolaar force-pushed the feature/static_analysis branch from 7baf4d7 to 22a8ba5 Compare February 12, 2018 07:27
@KelSolaar
Copy link
Copy Markdown
Collaborator Author

I have implemented the code review changes except for the basestring stuff as per my above comment.

Copy link
Copy Markdown
Owner

@gtaylor gtaylor left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Just make sure you squash/clean up the commit history before merge!

Squashed commits:
[22a8ba5] Remove unused variables in "colormath.color_conversions.RGB_to_HSV" definition.
[ecf5216] Handle and add "TODO" note to investigate remaining unused variable.
[0978310] Remove interpreter shebangs.
[df93e8d] Specify modules encoding.
[b0e2ef4] Fix "colormath.density.ansi_density" definition docstring.
[d2fc110] Fix incorrect string formatting in "colormath.color_appearance_models.CIECAM02.__init__" method.
[85a73f5] Improve type checking in various "colormath.chromatic_adaptation" module definitions.
[0077e3e] Remove unused imports.
[6d4ac23] Handle and add "TODO" notes to investigate various unused variables.
[200caba] Fix trailing whitespaces.
@KelSolaar KelSolaar force-pushed the feature/static_analysis branch from 22a8ba5 to 189ec1a Compare February 14, 2018 06:28
@KelSolaar
Copy link
Copy Markdown
Collaborator Author

@gtaylor: /done!

Copy link
Copy Markdown
Owner

@gtaylor gtaylor left a comment

Choose a reason for hiding this comment

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

Feel free to merge at your leisure

@KelSolaar KelSolaar merged commit 0f5e043 into gtaylor:master Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants