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

Fix and enable flake8 error "imported but unused" #109

Merged
merged 4 commits into from
Apr 2, 2020

Conversation

timokau
Copy link
Collaborator

@timokau timokau commented Mar 30, 2020

Description

Continuation of #104.

Motivation and Context

How Has This Been Tested?

Does this close/impact existing issues?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

from .tunable import Tunable
from .tuning import ParameterOptimizer

__all__ = ["Tunable", "ParameterOptimizer"]
__all__.extend(choicefunction)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm unsure about this. We could also use # noqa to just skip the check here. Maybe we should reconsider whether re-exporting everything at the top level is even desirable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also looks like the current solution is not working as expected:

ImportError while importing test module '/home/travis/build/kiudee/cs-ranking/csrank/tests/test_choice_functions.py'.

Hint: make sure your test modules/packages have valid Python names.

Traceback:

csrank/tests/test_choice_functions.py:27: in <module>

    from csrank.tests.test_ranking import check_params_tunable

csrank/tests/test_ranking.py:8: in <module>

    from csrank import PairedCombinatorialLogit

E   ImportError: cannot import name 'PairedCombinatorialLogit' from 'csrank' (/home/travis/build/kiudee/cs-ranking/csrank/__init__.py)

Copy link
Owner

Choose a reason for hiding this comment

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

Regarding the second comment: I think in tests it is better to import using the full path anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed on slack, we might want to reduce the re-exports in the future but this is not the place to do it. So I'm going with # noqa comments for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also see #105.

@timokau timokau requested a review from kiudee March 30, 2020 13:38
@timokau timokau force-pushed the flake8-f401 branch 3 times, most recently from c396ba3 to b674fb1 Compare April 1, 2020 18:30
@timokau
Copy link
Collaborator Author

timokau commented Apr 1, 2020

Weird, I'm pretty sure I ran the black check before committing.

The travis issue should be fixed now. Ready for review.

timokau added 2 commits April 1, 2020 20:48
As suggested by pep8:

https://www.python.org/dev/peps/pep-0008/#public-and-internal-interfaces

Not doing so trips up flake8's F401, since the imports are not used.
Imports are an implementation detail and should not directly be relied
upon to declare the public API.

Two exceptions to this are csrank/__init__.py and
csrank/dataset_reader/__init__.py, where the API is too big. This will
likely change in the future. See kiudee#105.
We have now fixed all occurrences of this issue.
@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #109 into master will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #109      +/-   ##
==========================================
+ Coverage   59.15%   59.22%   +0.06%     
==========================================
  Files         116      116              
  Lines        7475     7472       -3     
==========================================
+ Hits         4422     4425       +3     
+ Misses       3053     3047       -6     
Impacted Files Coverage Δ
csrank/core/feta_network.py 62.73% <ø> (-0.18%) ⬇️
...r/discretechoice/discrete_choice_data_generator.py 18.18% <ø> (-0.95%) ⬇️
...der/objectranking/object_ranking_data_generator.py 22.72% <ø> (-0.93%) ⬇️
csrank/tests/test_metrics.py 100.00% <ø> (ø)
csrank/__init__.py 100.00% <100.00%> (ø)
csrank/choicefunction/__init__.py 100.00% <100.00%> (ø)
csrank/core/__init__.py 100.00% <100.00%> (ø)
csrank/dataset_reader/__init__.py 100.00% <100.00%> (ø)
csrank/dataset_reader/choicefunctions/__init__.py 100.00% <100.00%> (ø)
csrank/dataset_reader/discretechoice/__init__.py 100.00% <100.00%> (ø)
... and 5 more

@timokau timokau merged commit 88a3947 into kiudee:master Apr 2, 2020
@timokau timokau deleted the flake8-f401 branch April 2, 2020 10:03
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.

2 participants