2626#ifndef PSYCOPG_PYTHON_H
2727#define PSYCOPG_PYTHON_H 1
2828
29- #include <structmember.h>
30- #if PY_MAJOR_VERSION < 3
31- #include <stringobject.h>
29+ #define PY_2 (PY_MAJOR_VERSION == 2)
30+ #define PY_3 (PY_MAJOR_VERSION == 3)
31+
32+ #if PY_2 && PY_VERSION_HEX < 0x02070000
33+ #error "psycopg requires Python 2.7"
3234#endif
3335
34- #if ((PY_VERSION_HEX < 0x02070000 ) \
35- || ((PY_VERSION_HEX >= 0x03000000 ) \
36- && (PY_VERSION_HEX < 0x03040000 )) )
37- # error "psycopg requires Python 2.7 or 3.4+"
36+ #if PY_3 && PY_VERSION_HEX < 0x03040000
37+ #error "psycopg requires Python 3.4"
38+ #endif
39+
40+ #include <structmember.h>
41+ #if PY_2
42+ #include <stringobject.h>
3843#endif
3944
4045/* hash() return size changed around version 3.2a4 on 64bit platforms. Before
@@ -59,7 +64,7 @@ typedef unsigned long Py_uhash_t;
5964#endif
6065
6166/* Abstract from text type. Only supported for ASCII and UTF-8 */
62- #if PY_MAJOR_VERSION < 3
67+ #if PY_2
6368#define Text_Type PyString_Type
6469#define Text_Check (s ) PyString_Check(s)
6570#define Text_Format (f ,a ) PyString_Format(f,a)
@@ -73,7 +78,7 @@ typedef unsigned long Py_uhash_t;
7378#define Text_FromUTF8AndSize (s ,n ) PyUnicode_FromStringAndSize(s,n)
7479#endif
7580
76- #if PY_MAJOR_VERSION > 2
81+ #if PY_3
7782#define PyInt_Type PyLong_Type
7883#define PyInt_Check PyLong_Check
7984#define PyInt_AsLong PyLong_AsLong
@@ -89,9 +94,9 @@ typedef unsigned long Py_uhash_t;
8994#define PyNumber_Int PyNumber_Long
9095#endif
9196
92- #endif /* PY_MAJOR_VERSION > 2 */
97+ #endif /* PY_3 */
9398
94- #if PY_MAJOR_VERSION < 3
99+ #if PY_2
95100#define Bytes_Type PyString_Type
96101#define Bytes_Check PyString_Check
97102#define Bytes_CheckExact PyString_CheckExact
@@ -131,7 +136,7 @@ typedef unsigned long Py_uhash_t;
131136HIDDEN PyObject * Bytes_Format (PyObject * format , PyObject * args );
132137
133138/* Mangle the module name into the name of the module init function */
134- #if PY_MAJOR_VERSION > 2
139+ #if PY_3
135140#define INIT_MODULE (m ) PyInit_ ## m
136141#else
137142#define INIT_MODULE (m ) init ## m
0 commit comments