-
Notifications
You must be signed in to change notification settings - Fork 12
analyze.py started to pick up stdlib functions #160
Comments
ah! it was probably from #155 In my opinion, if you do Have you seen that this only applies to stdlib functions? Like if you do
Could you tell me what you'd want the interface for "ignore stdlib functions" to look like? It could be:
|
This won't be limited to standard library functions. Any time you import something, you're adding it to the namespace of that module. So if you have If you then do This is going to be a pitfall of doing |
@jayqi sorry, to be clear I'm asking what the observed behavior with doppel-cli is, not generically how such imports work in Python.
I can try to repro tonight with a simple package. |
Yep, this all makes sense! Let me try to clarify my original question. Given:
I thought stdlib functions qualified as one of those special exceptions (no pun intended), especially because that's how it was handled before 0.3.0. However, I agree that people could want it either way (ex. cloudpickle re-exports IMO it's still valuable to try to repro, so that doppel-describe is consistent in its treatment of stdlib vs third-party functions. |
Thanks for the summary! I didn't catch that anything in the 0.3.0 was changing previous behavior (other than bugfixes) because all my test packages use explicit imports (none have an And I was inspired by examples like the For anyone else arriving at this thread, the workaround if you want
|
Update: I removed all instances of
from setuptools import find_packages, setup
setup(
name='testpkg',
version='0.0.1',
packages=find_packages(),
)
from .module import create_warning
from warnings import warn
def create_warning():
print('uh oh')
warn('not good') After doing {
"name": "testpkg [python]",
"language": "python",
"functions": {
"create_warning": {
"args": []
},
"warn": {
"args": []
}
},
"classes": {}
} I would not expect |
@austin3dickey thanks for the producible example! So, this is interesting. It is the current behavior that you don't have to explicitly import something in
And got
As for imports from other packages...that's where this gets weird. Did you notice that I think I found the cause, too. this check is not sufficient: # built-ins like 'min()' are not classes, functions, or modules,
# according to the previous checks, but if they're callable
# they should count as exported functions
elif _is_builtin(obj) and callable(obj):
out["functions"][obj_name] = {
"args": []
} I think it should be more like # built-ins like 'min()' are not classes, functions, or modules,
# according to the previous checks, but if they're callable
# they should count as exported functions
elif _is_builtin(obj) and callable(obj):
if not obj.__module__.startswith(PKG_NAME):
_log_info("Callable '{}' is a built-in not included in this package's namespace. Skipping it.".format(obj.__name__))
next
out["functions"][obj_name] = {
"args": []
} I'm working on a PR. Your reproducible example is just directly going to become a test case, thanks again for putting it together! |
@austin3dickey ok I tried to add a fix in #161 . I'll leave it open for a a few days. Could you try doing what your'e doing from that branch and see if it fixes the issue? If it does, I'll merge that and cut a 0.3.1 release. |
Yes, your PR completely fixes it! Thanks for the quick turnaround :) |
One addition to this.. @austin3dickey while working on #171 , I realized that one case is not working the way I expected. If you do something like this: wrap_min = min
This was found in #171 because |
Hi!
With the recent release, I noticed that analyze.py started classifying stdlib functions like the following as exported from python packages:
If I put these at the top of
my_module.py
, and in my__init__.py
do something likefrom my_module import *
, these 3 functions get picked up and counted as part of the public interface (though they didn't before the release).To be fair, these functions are exported from my package. Perhaps it would be better to do something like
from functools import reduce as _reduce
or justimport functools
in my package instead. But I was wondering if that's this tool's official stance, or if we're interested in adding functionality to discount stdlib functions like these from the exported list.The text was updated successfully, but these errors were encountered: