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

python3: scrapy.__version__, NoneType, urlparse_monkeypatches #452

Merged
merged 1 commit into from
Nov 4, 2013

Conversation

alexanderlukanin13
Copy link
Contributor

Python 3 compatibility changes:

  1. __version__ will be str in both 2 and 3. Necessary because pkgutil.get_data returns bytes in 3.
  2. NoneType is not available in 3
  3. Apply urlparse_monkeypatches in Python 2 only. Patches are not needed in 3 (tested in 3.2-3.4).

@@ -4,6 +4,8 @@
from __future__ import print_function
import pkgutil
__version__ = pkgutil.get_data(__package__, 'VERSION').strip()
if not isinstance(__version__, str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when string must be a bytestring in 2.x and unicode string in 3.x it is easier to write __version__ = str(pkgutil.get_data(__package__, 'VERSION').strip())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> str(b'1.2.3')
"b'1.2.3'"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i see

kmike added a commit that referenced this pull request Nov 4, 2013
PY3: scrapy.__version__, NoneType, urlparse_monkeypatches
@kmike kmike merged commit f80f10a into scrapy:master Nov 4, 2013
@kmike
Copy link
Member

kmike commented Nov 4, 2013

Thanks!

@alexanderlukanin13 alexanderlukanin13 deleted the python3 branch November 4, 2013 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants