-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
refactor: Don’t directly import numpy and add gen_types
decorator
#966
Open
hoxbro
wants to merge
22
commits into
main
Choose a base branch
from
no_numpy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−42
Open
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c0c0d89
Add option for using generators for instance check
hoxbro 15f89b8
Update Comparator to work with generators
hoxbro 8aacfa7
Remove numpy import
hoxbro 3935d11
Move error handling below logic
hoxbro 876f092
Update if statement
hoxbro b3d507c
Fix error message
hoxbro 43e81af
Update message
hoxbro ddac37f
Add test to verify no numpy is imported
hoxbro c5f6d08
Simplify
hoxbro 6550976
Allow List item_type to also be an iterable
hoxbro b6ebc61
Simplify isinstance
hoxbro 138426d
Update param/parameters.py
hoxbro 5b8f25f
Update param/parameterized.py
hoxbro 2225dab
Remove anyinstance and anysubclass
hoxbro b6456eb
Add gen_types decorator
hoxbro 3a98d8f
Merge branch 'main' into no_numpy
hoxbro 665ee54
Try class iter
hoxbro fe5345e
Also add __iter__ for metaclass
hoxbro 36fc0cb
Walrus gen_types
hoxbro 249bcf2
Add _random for gen types
hoxbro 0e273cf
Add test
hoxbro 10f27b5
Merge branch 'main' into no_numpy
hoxbro 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
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
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
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,20 @@ | ||
import sys | ||
from subprocess import check_output | ||
from textwrap import dedent | ||
|
||
|
||
def test_no_blocklist_imports(): | ||
check = """\ | ||
import sys | ||
import param | ||
blocklist = {"numpy", "IPython", "pandas"} | ||
mods = blocklist & set(sys.modules) | ||
if mods: | ||
print(", ".join(mods), end="") | ||
""" | ||
|
||
output = check_output([sys.executable, '-c', dedent(check)]) | ||
|
||
assert output == b"" |
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.
Could an approach like this be used to avoid creating these functions? https://peps.python.org/pep-3119/#overloading-isinstance-and-issubclass
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 don't think so, though I haven't read the PEP in detail.
However, it seems pretty advanced to use for a simple conversion.
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.
It seems it'd be something like:
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.
Thank you.
I still thinks it is pretty advanced (even though you don't need it to be iterable in your example).
You could likely move the advanced logic into a decorator, but then you would need to import that into our other libraries. My main point with accepting iterator is not so much for param itself but for HoloViews.
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.
Oh yeah I agree users shouldn't have to pass this custom class, a generator seems appropriate. Instead I was wondering if there couldn't be a way to use the metaclass approach internally to avoid the special
anyisinstance
andanyissubclass
functions, they seem to be easy to forget in the future.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 have switched to a metaclass approach with a decorator for easy access.