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

Drop support for EOL Python 2.7 #1198

Merged
merged 6 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ environment:
- {APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015, PY_VER: "37", PY_ARCH: "64"}
- {APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015, PY_VER: "36", PY_ARCH: "32"}
- {APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015, PY_VER: "36", PY_ARCH: "64"}
- {APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015, PY_VER: "27", PY_ARCH: "32"}
- {APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015, PY_VER: "27", PY_ARCH: "64"}

OPENSSL_VERSION: "1_1_1h"
POSTGRES_VERSION: "11_4"
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ python:
- 3.7
- 3.8

matrix:
include:
- python: 2.7

install:
- sudo apt-get install -y bc
- pip install -U pip setuptools wheel
Expand Down
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Current release
What's new in psycopg 2.9
-------------------------

- Dropped support for Python 3.4, 3.5 (:tickets:#1000, #1197).
- Dropped support for Python 2.7, 3.4, 3.5 (:tickets:#1198, #1000, #1197).

What's new in psycopg 2.8.6
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -13,7 +13,7 @@ What's new in psycopg 2.8.6
(:ticket:`#1101`).
- Fixed search of mxDateTime headers in virtualenvs (:ticket:`#996`).
- Added missing values from errorcodes (:ticket:`#1133`).
- `cursor.query` reports the query of the last :sql:`COPY` opearation too
- `cursor.query` reports the query of the last :sql:`COPY` operation too
(:ticket:`#1141`).
- `~psycopg2.errorcodes` map and `~psycopg2.errors` classes updated to
PostgreSQL 13.
Expand Down
9 changes: 4 additions & 5 deletions doc/src/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Psycopg documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 7 13:48:41 2010.
Expand Down Expand Up @@ -48,9 +47,9 @@
master_doc = 'index'

# General information about the project.
project = u'Psycopg'
project = 'Psycopg'
copyright = (
u'2001-2020, Federico Di Gregorio, Daniele Varrazzo, The Psycopg Team'
'2001-2020, Federico Di Gregorio, Daniele Varrazzo, The Psycopg Team'
)

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -235,8 +234,8 @@
(
'index',
'psycopg.tex',
u'Psycopg Documentation',
u'Federico Di Gregorio',
'Psycopg Documentation',
'Federico Di Gregorio',
'manual',
)
]
Expand Down
3 changes: 1 addition & 2 deletions doc/src/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ The current `!psycopg2` implementation supports:
..
NOTE: keep consistent with setup.py and the /features/ page.

- Python version 2.7
- Python 3 versions from 3.6 to 3.9
- Python versions from 3.6 to 3.9
- PostgreSQL server versions from 7.4 to 13
- PostgreSQL client library version from 9.1

Expand Down
1 change: 0 additions & 1 deletion doc/src/tools/lib/dbapi_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
extension
~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion doc/src/tools/lib/sql_role.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
sql role
~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion doc/src/tools/lib/ticket_role.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ticket role
~~~~~~~~~~~
Expand Down
7 changes: 3 additions & 4 deletions doc/src/tools/make_sqlstate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Create the docs table of the sqlstate errors.
"""

from __future__ import print_function

import re
import sys
Expand All @@ -26,8 +25,8 @@ def main():
for k in sorted(sqlstate_errors):
exc = sqlstate_errors[k]
lines.append(Line(
"``%s``" % k, "`!%s`" % exc.__name__,
"`!%s`" % get_base_exception(exc).__name__, k))
f"``{k}``", f"`!{exc.__name__}`",
f"`!{get_base_exception(exc).__name__}`", k))

widths = [max(len(l[c]) for l in lines) for c in range(3)]
h = Line(*(['=' * w for w in widths] + [None]))
Expand All @@ -40,7 +39,7 @@ def main():
for l in lines:
cls = l.sqlstate[:2] if l.sqlstate else None
if cls and cls != sqlclass:
print("**Class %s**: %s" % (cls, sqlclasses[cls]))
print(f"**Class {cls}**: {sqlclasses[cls]}")
print(h1)
sqlclass = cls

Expand Down
5 changes: 2 additions & 3 deletions lib/_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from psycopg2.extensions import (
new_type, new_array_type, register_type, register_adapter, QuotedString)
from psycopg2.compat import text_type

# The module is imported on register_ipaddress
ipaddress = None
Expand Down Expand Up @@ -78,13 +77,13 @@ def cast_interface(s, cur=None):
if s is None:
return None
# Py2 version force the use of unicode. meh.
return ipaddress.ip_interface(text_type(s))
return ipaddress.ip_interface(str(s))


def cast_network(s, cur=None):
if s is None:
return None
return ipaddress.ip_network(text_type(s))
return ipaddress.ip_network(str(s))


def adapt_ipaddress(obj):
Expand Down
17 changes: 6 additions & 11 deletions lib/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

from psycopg2._psycopg import ISQLQuote, QuotedString
from psycopg2._psycopg import new_type, new_array_type, register_type
from psycopg2.compat import PY2


# oids from PostgreSQL 9.2
Expand All @@ -44,7 +43,7 @@
JSONBARRAY_OID = 3807


class Json(object):
class Json:
"""
An `~psycopg2.extensions.ISQLQuote` wrapper to adapt a Python object to
:sql:`json` data type.
Expand Down Expand Up @@ -82,13 +81,9 @@ def getquoted(self):
qs.prepare(self._conn)
return qs.getquoted()

if PY2:
def __str__(self):
return self.getquoted()
else:
def __str__(self):
# getquoted is binary in Py3
return self.getquoted().decode('ascii', 'replace')
def __str__(self):
# getquoted is binary
return self.getquoted().decode('ascii', 'replace')


def register_json(conn_or_curs=None, globally=False, loads=None,
Expand Down Expand Up @@ -168,7 +163,7 @@ def typecast_json(s, cur):

JSON = new_type((oid, ), name, typecast_json)
if array_oid is not None:
JSONARRAY = new_array_type((array_oid, ), "%sARRAY" % name, JSON)
JSONARRAY = new_array_type((array_oid, ), f"{name}ARRAY", JSON)
else:
JSONARRAY = None

Expand Down Expand Up @@ -199,6 +194,6 @@ def _get_json_oids(conn_or_curs, name='json'):
conn.rollback()

if not r:
raise conn.ProgrammingError("%s data type not found" % name)
raise conn.ProgrammingError(f"{name} data type not found")

return r
104 changes: 0 additions & 104 deletions lib/_lru_cache.py

This file was deleted.

24 changes: 11 additions & 13 deletions lib/_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
from psycopg2._psycopg import ProgrammingError, InterfaceError
from psycopg2.extensions import ISQLQuote, adapt, register_adapter
from psycopg2.extensions import new_type, new_array_type, register_type
from psycopg2.compat import string_types


class Range(object):
class Range:
"""Python representation for a PostgreSQL |range|_ type.

:param lower: lower bound for the range. `!None` means unbound
Expand All @@ -48,7 +47,7 @@ class Range(object):
def __init__(self, lower=None, upper=None, bounds='[)', empty=False):
if not empty:
if bounds not in ('[)', '(]', '()', '[]'):
raise ValueError("bound flags not valid: %r" % bounds)
raise ValueError(f"bound flags not valid: {bounds!r}")

self._lower = lower
self._upper = upper
Expand All @@ -58,9 +57,9 @@ def __init__(self, lower=None, upper=None, bounds='[)', empty=False):

def __repr__(self):
if self._bounds is None:
return "%s(empty=True)" % self.__class__.__name__
return f"{self.__class__.__name__}(empty=True)"
else:
return "%s(%r, %r, %r)" % (self.__class__.__name__,
return "{}({!r}, {!r}, {!r})".format(self.__class__.__name__,
self._lower, self._upper, self._bounds)

def __str__(self):
Expand Down Expand Up @@ -239,7 +238,7 @@ def register_range(pgrange, pyrange, conn_or_curs, globally=False):
return caster


class RangeAdapter(object):
class RangeAdapter:
"""`ISQLQuote` adapter for `Range` subclasses.

This is an abstract class: concrete classes must set a `name` class
Expand Down Expand Up @@ -287,7 +286,7 @@ def getquoted(self):
+ b", '" + r._bounds.encode('utf8') + b"')"


class RangeCaster(object):
class RangeCaster:
"""Helper class to convert between `Range` and PostgreSQL range types.

Objects of this class are usually created by `register_range()`. Manual
Expand Down Expand Up @@ -315,7 +314,7 @@ def _create_ranges(self, pgrange, pyrange):
# an implementation detail and is not documented. It is currently used
# for the numeric ranges.
self.adapter = None
if isinstance(pgrange, string_types):
if isinstance(pgrange, str):
self.adapter = type(pgrange, (RangeAdapter,), {})
self.adapter.name = pgrange
else:
Expand All @@ -332,7 +331,7 @@ def _create_ranges(self, pgrange, pyrange):

self.range = None
try:
if isinstance(pyrange, string_types):
if isinstance(pyrange, str):
self.range = type(pyrange, (Range,), {})
if issubclass(pyrange, Range) and pyrange is not Range:
self.range = pyrange
Expand Down Expand Up @@ -392,7 +391,7 @@ def _from_db(self, name, pyrange, conn_or_curs):

if not rec:
raise ProgrammingError(
"PostgreSQL type '%s' not found" % name)
f"PostgreSQL type '{name}' not found")

type, subtype, array = rec

Expand Down Expand Up @@ -424,7 +423,7 @@ def parse(self, s, cur=None):

m = self._re_range.match(s)
if m is None:
raise InterfaceError("failed to parse range: '%s'" % s)
raise InterfaceError(f"failed to parse range: '{s}'")

lower = m.group(3)
if lower is None:
Expand Down Expand Up @@ -504,8 +503,7 @@ def getquoted(self):
else:
upper = ''

return ("'%s%s,%s%s'" % (
r._bounds[0], lower, upper, r._bounds[1])).encode('ascii')
return (f"'{r._bounds[0]}{lower},{upper}{r._bounds[1]}'").encode('ascii')


# TODO: probably won't work with infs, nans and other tricky cases.
Expand Down
Loading