-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add import compat layer to __init__ #24
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
db70362
Add import compat layer to __init__
bdraco bc71f91
coverage
bdraco 7668e25
changelog
bdraco 6315f60
add more coverage
bdraco 7006bae
Update tests/test_init.py
bdraco 4a5c904
add test to verify import error
bdraco 5385d3f
Update tests/test_init.py
bdraco 166b8b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 84d9e86
revert version to 0.2.0.dev0
bdraco 61b37b4
changelog
bdraco 8f21e75
some of the facade will not hit the typing coverage
bdraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,6 @@ coverage: | |
typing: | ||
flags: | ||
- MyPy | ||
target: 70% # 100% | ||
target: 68.5% # 100% | ||
|
||
... |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Moved :func:`propcache.api.under_cached_property` and :func:`propcache.api.cached_property` to ``propcache.api`` -- by :user:`bdraco`. | ||
|
||
Both decorators remain importable from the top-level package, however importing from `propcache.api` is now the recommended way to use them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
19.packaging.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
"""propcache: An accelerated property cache for Python classes.""" | ||
|
||
__version__ = "1.0.0.dev0" | ||
from typing import TYPE_CHECKING, List | ||
|
||
__version__ = "0.2.0.dev0" | ||
|
||
# Imports have moved to `propcache.api` in 1.0.0+. | ||
__all__ = () | ||
# This module is now a facade for the API. | ||
if TYPE_CHECKING: | ||
from .api import cached_property, under_cached_property | ||
bdraco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
__all__ = ("cached_property", "under_cached_property") | ||
bdraco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def _import_facade(attr: str) -> object: | ||
"""Import the public API from the `api` module.""" | ||
if attr in __all__: | ||
from . import api # pylint: disable=import-outside-toplevel | ||
|
||
return getattr(api, attr) | ||
raise AttributeError(f"module 'propcache' has no attribute '{attr}'") | ||
bdraco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def _dir_facade() -> List[str]: | ||
"""Include the public API in the module's dir() output.""" | ||
return [*__all__, *globals().keys()] | ||
|
||
|
||
__getattr__ = _import_facade | ||
__dir__ = _dir_facade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Test imports can happen from top-level.""" | ||
|
||
import pytest | ||
|
||
import propcache | ||
|
||
from propcache import _helpers | ||
|
||
|
||
def test_api_at_top_level(): | ||
"""Verify the public API is accessible at top-level.""" | ||
assert propcache.cached_property is not None | ||
assert propcache.under_cached_property is not None | ||
assert propcache.cached_property is _helpers.cached_property | ||
assert propcache.under_cached_property is _helpers.under_cached_property | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"prop_name", | ||
("cached_property", "under_cached_property"), | ||
) | ||
@pytest.mark.parametrize( | ||
"api_list", (dir(propcache), propcache.__all__), ids=("dir", "__all__") | ||
) | ||
def test_public_api_is_in_inspectable_object_lists(prop_name, api_list): | ||
"""Verify the public API is discoverable programmatically. | ||
|
||
This checks for presence of known public decorators module's | ||
``__all__`` and ``dir()``. | ||
""" | ||
assert prop_name in api_list | ||
|
||
|
||
def test_importing_invalid_attr_raises(): | ||
"""Verify importing an invalid attribute raises an AttributeError.""" | ||
match = r"^module 'propcache' has no attribute 'invalid_attr'$" | ||
with pytest.raises(AttributeError, match=match): | ||
propcache.invalid_attr | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_import_error_invalid_attr(): | ||
"""Verify importing an invalid attribute raises an ImportError.""" | ||
# No match here because the error is raised by the import system | ||
# and may vary between Python versions. | ||
with pytest.raises(ImportError): | ||
from propcache import invalid_attr # noqa: F401 | ||
bdraco marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdraco why did you lower this? The currently reported number is 87.50% per https://app.codecov.io/gh/aio-libs/propcache?flags%5B0%5D=MyPy. Honestly, I'd prefer MyPy coverage to be fixed rather than discarded. Looking into https://app.codecov.io/gh/aio-libs/propcache/blob/master/tests%2Ftest_init.py?flags%5B0%5D=MyPy, most of it is not that hard to address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept getting different results on each run so I under the impression it was an order of delivery problem to Codecov.
Do you have a suggestion on how to type
propcache_module
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess
ModuleType
will work herepropcache/tests/conftest.py
Line 36 in f7ac8b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doors closing, switching to mobile, will do more if wifi works in flight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why its missing on these lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdraco try using the
from .api import cached_property as cached_property
syntax in__init__.py
. I've been trying to figure out similar things recently, and the experience needs improving: https://discuss.python.org/t/is-there-any-tool-that-can-report-type-coverage-of-a-project/34962/4.It might be a rule we disable, but it still influences the coverage precision metric. So it wouldn't show up in the console output, but type coverage would be incomplete. I also saw mentions of when something in the type resolves to
Any
, that would make the line imprecise/uncovered. And MyPy does not have a# pragma: no cover
to make it go away.