Closed 42B closed 5 years ago
Hi @42B ,
Both of these fixes seems totally reasonable Can you open a PR with the changes rebased against our master so we can get them into the codebase?
Adressed in https://github.com/quandl/quandl-python/pull/131. Closing
1
117 introduced a bug in regards to Python 2 compatibility since
pathlib
is Python 3.4+ only.Currently, the only way to hit these import statements is to not pass a
filename
argument to either function (or passfilename=None
). Here are the two sections causing the issue:https://github.com/quandl/quandl-python/blob/33149816637b239db6a6436cc3d4a2d5a60d5fe4/quandl/api_config.py#L15-L18
https://github.com/quandl/quandl-python/blob/33149816637b239db6a6436cc3d4a2d5a60d5fe4/quandl/api_config.py#L26-L29
This problem would likely have been caught earlier if the imports were at the top of the file as mentioned in PEP8.
https://github.com/quandl/quandl-python/blob/33149816637b239db6a6436cc3d4a2d5a60d5fe4/quandl/__init__.py#L3
A simple fix seems to be indicated in the Python docs themselves:
There is a problem with simply replacing
str(pathlib.Path.home())
withos.path.expanduser('~')
in these two lines though. The string concatenation is prepending forward slash in front of.quandl_apikey
which (if I remember correctly) is not compatible with Windows which uses backslashes.I'm a fan of
pathlib
and one way to solve this would be like this:But since Python 2 compatibility is the issue, using
os.path.join
seems like an appropriate fix.2
There is also a smaller bug where the
try/except
inread_key
is looking for the wrong exception. In Python 2,open
raises anIOError
if a file isn't found. In Python 3, anOSError
is raised.Neither of these exceptions have a parent exception of
ValueError
though.In my opinion, these exceptions are already very clear about what went wrong and it seems unnecessary to catch them in
read_key
just to simply re-raise them with a custom message.tl;dr
Ignoring the fact that these two functions are mutating the state of a class and seem like they could be class methods instead... maybe something like this?