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

Issue with Python 3.2 #41

Closed
guyzmo opened this issue Sep 5, 2016 · 4 comments
Closed

Issue with Python 3.2 #41

guyzmo opened this issue Sep 5, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@guyzmo
Copy link
Contributor

guyzmo commented Sep 5, 2016

I installed pendulum on Python 3.2 install, and when I run it, here's what I get:

 % python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pendulum
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/pendulum/__init__.py", line 3, in <module>
    from .pendulum import Pendulum
  File "/usr/local/lib/python3.2/dist-packages/pendulum/pendulum.py", line 19, in <module>
    from .tz import Timezone, UTC, FixedTimezone, local_timezone
  File "/usr/local/lib/python3.2/dist-packages/pendulum/tz/__init__.py", line 3, in <module>
    from .timezone import Timezone, FixedTimezone, UTC
  File "/usr/local/lib/python3.2/dist-packages/pendulum/tz/timezone.py", line 6, in <module>
    from .loader import Loader
  File "/usr/local/lib/python3.2/dist-packages/pendulum/tz/loader.py", line 10, in <module>
    from .. import _compat
  File "/usr/local/lib/python3.2/dist-packages/pendulum/_compat.py", line 19, in <module>
    FileNotFoundError = FileNotFoundError
NameError: name 'FileNotFoundError' is not defined

It looks like the FileNotFoundErrorexception, along with the rework of the OS/IO exceptions has been introduced in Python 3.3.
cf

I do not understand why FileNotFoundError could not defined in Python 3.2. cf PEP-3151

Instead of relying on major python versions to check for features, I'd suggest to check for the feature and fallback to the alternative. Such as:

try:
   FileNotFoundError = FileNotFoundError
except NameError:
   FileNotFoundError = IOError

The Python3.2.3 I'm using, is the one from Debian Wheezy (old-stable) and I installed pendulum v0.5.5 from Pypi. I tried with the suggested fix above, and it works.

@sdispater sdispater added the bug label Sep 5, 2016
@sdispater sdispater self-assigned this Sep 5, 2016
@sdispater
Copy link
Owner

It is linked to #34 and its associated pull request #35.

I will make the change to fix this :-)

@guyzmo
Copy link
Contributor Author

guyzmo commented Sep 5, 2016

indeed ☺

I was actually thinking of doing a PR anyway, just wanted to understand the .so issue in the other ticket first, though ☺

@guyzmo
Copy link
Contributor Author

guyzmo commented Sep 5, 2016

actually, a good fix could be:

FileNotFoundError = getattr(__builtins__, 'FileNotFoundError', IOError)

though it's always nicer to avoid using introspection builtins like getattr, I think it's a pretty good way to cover all cases.

@sdispater
Copy link
Owner

Go ahead if you want to make a PR :-)

I prefer:

try:
   FileNotFoundError = FileNotFoundError
except NameError:
   FileNotFoundError = IOError

to be honest. It seems more explicit.

guyzmo added a commit to guyzmo/pendulum that referenced this issue Sep 5, 2016
The `IOError` refactoring has been introduced by PEP-3151 which has
been implemented in Python 3.3+. This patch fixes the bug by having
`FileNotFoundError` assigned as `IOError` on ≤3.2 pythons.

* fixes issue sdispater#41

Signed-off-by: Bernard `Guyzmo` Pratz <guyzmo+github+pub@m0g.net>
sdispater pushed a commit that referenced this issue Sep 5, 2016
The `IOError` refactoring has been introduced by PEP-3151 which has
been implemented in Python 3.3+. This patch fixes the bug by having
`FileNotFoundError` assigned as `IOError` on ≤3.2 pythons.

* fixes issue #41

Signed-off-by: Bernard `Guyzmo` Pratz <guyzmo+github+pub@m0g.net>
@sdispater sdispater added this to the 0.6 milestone Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants