Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4d67799b
Commit
4d67799b
authored
Oct 13, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge heads
parents
e6798bb5
4fa7a9fd
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
103 additions
and
5 deletions
+103
-5
Lib/socketserver.py
Lib/socketserver.py
+6
-2
Lib/test/test_import/__init__.py
Lib/test/test_import/__init__.py
+41
-1
Lib/test/test_import/__main__.py
Lib/test/test_import/__main__.py
+3
-0
Lib/test/test_import/data/circular_imports/basic.py
Lib/test/test_import/data/circular_imports/basic.py
+2
-0
Lib/test/test_import/data/circular_imports/basic2.py
Lib/test/test_import/data/circular_imports/basic2.py
+1
-0
Lib/test/test_import/data/circular_imports/indirect.py
Lib/test/test_import/data/circular_imports/indirect.py
+1
-0
Lib/test/test_import/data/circular_imports/rebinding.py
Lib/test/test_import/data/circular_imports/rebinding.py
+3
-0
Lib/test/test_import/data/circular_imports/rebinding2.py
Lib/test/test_import/data/circular_imports/rebinding2.py
+3
-0
Lib/test/test_import/data/circular_imports/subpackage.py
Lib/test/test_import/data/circular_imports/subpackage.py
+2
-0
Lib/test/test_import/data/circular_imports/subpkg/subpackage2.py
...t/test_import/data/circular_imports/subpkg/subpackage2.py
+2
-0
Lib/test/test_import/data/circular_imports/subpkg/util.py
Lib/test/test_import/data/circular_imports/subpkg/util.py
+2
-0
Lib/test/test_import/data/circular_imports/util.py
Lib/test/test_import/data/circular_imports/util.py
+2
-0
Lib/test/test_socketserver.py
Lib/test/test_socketserver.py
+10
-0
Misc/NEWS
Misc/NEWS
+5
-0
Python/ceval.c
Python/ceval.c
+20
-2
No files found.
Lib/socketserver.py
View file @
4d67799b
...
...
@@ -439,8 +439,12 @@ class TCPServer(BaseServer):
self
.
socket
=
socket
.
socket
(
self
.
address_family
,
self
.
socket_type
)
if
bind_and_activate
:
try
:
self
.
server_bind
()
self
.
server_activate
()
except
:
self
.
server_close
()
raise
def
server_bind
(
self
):
"""Called by constructor to bind the socket.
...
...
Lib/test/test_import.py
→
Lib/test/test_import
/__init__
.py
View file @
4d67799b
...
...
@@ -568,7 +568,7 @@ class RelativeImportTests(unittest.TestCase):
def
test_relimport_star
(
self
):
# This will import * from .test_import.
from
.
import
relimport
from
.
.
import
relimport
self
.
assertTrue
(
hasattr
(
relimport
,
"RelativeImportTests"
))
def
test_issue3221
(
self
):
...
...
@@ -1068,6 +1068,46 @@ class ImportTracebackTests(unittest.TestCase):
__isolated
=
False
)
class
CircularImportTests
(
unittest
.
TestCase
):
"""See the docstrings of the modules being imported for the purpose of the
test."""
def
tearDown
(
self
):
"""Make sure no modules pre-exist in sys.modules which are being used to
test."""
for
key
in
list
(
sys
.
modules
.
keys
()):
if
key
.
startswith
(
'test.test_import.data.circular_imports'
):
del
sys
.
modules
[
key
]
def
test_direct
(
self
):
try
:
import
test.test_import.data.circular_imports.basic
except
ImportError
:
self
.
fail
(
'circular import through relative imports failed'
)
def
test_indirect
(
self
):
try
:
import
test.test_import.data.circular_imports.indirect
except
ImportError
:
self
.
fail
(
'relative import in module contributing to circular '
'import failed'
)
def
test_subpackage
(
self
):
try
:
import
test.test_import.data.circular_imports.subpackage
except
ImportError
:
self
.
fail
(
'circular import involving a subpackage failed'
)
def
test_rebinding
(
self
):
try
:
import
test.test_import.data.circular_imports.rebinding
as
rebinding
except
ImportError
:
self
.
fail
(
'circular import with rebinding of module attribute failed'
)
from
test.test_import.data.circular_imports.subpkg
import
util
self
.
assertIs
(
util
.
util
,
rebinding
.
util
)
if
__name__
==
'__main__'
:
# Test needs to be a package, so we can do relative imports.
unittest
.
main
()
Lib/test/test_import/__main__.py
0 → 100644
View file @
4d67799b
import
unittest
unittest
.
main
(
'test.test_import'
)
Lib/test/test_import/data/circular_imports/basic.py
0 → 100644
View file @
4d67799b
"""Circular imports through direct, relative imports."""
from
.
import
basic2
Lib/test/test_import/data/circular_imports/basic2.py
0 → 100644
View file @
4d67799b
from
.
import
basic
Lib/test/test_import/data/circular_imports/indirect.py
0 → 100644
View file @
4d67799b
from
.
import
basic
,
basic2
Lib/test/test_import/data/circular_imports/rebinding.py
0 → 100644
View file @
4d67799b
"""Test the binding of names when a circular import shares the same name as an
attribute."""
from
.rebinding2
import
util
Lib/test/test_import/data/circular_imports/rebinding2.py
0 → 100644
View file @
4d67799b
from
.subpkg
import
util
from
.
import
rebinding
util
=
util
.
util
Lib/test/test_import/data/circular_imports/subpackage.py
0 → 100644
View file @
4d67799b
"""Circular import involving a sub-package."""
from
.subpkg
import
subpackage2
Lib/test/test_import/data/circular_imports/subpkg/subpackage2.py
0 → 100644
View file @
4d67799b
#from .util import util
from
..
import
subpackage
Lib/test/test_import/data/circular_imports/subpkg/util.py
0 → 100644
View file @
4d67799b
def
util
():
pass
Lib/test/test_import/data/circular_imports/util.py
0 → 100644
View file @
4d67799b
def
util
():
pass
Lib/test/test_socketserver.py
View file @
4d67799b
...
...
@@ -270,6 +270,16 @@ class SocketServerTest(unittest.TestCase):
t
.
join
()
s
.
server_close
()
def
test_tcpserver_bind_leak
(
self
):
# Issue #22435: the server socket wouldn't be closed if bind()/listen()
# failed.
# Create many servers for which bind() will fail, to see if this result
# in FD exhaustion.
for
i
in
range
(
1024
):
with
self
.
assertRaises
(
OverflowError
):
socketserver
.
TCPServer
((
HOST
,
-
1
),
socketserver
.
StreamRequestHandler
)
def
test_main
():
if
imp
.
lock_held
():
...
...
Misc/NEWS
View file @
4d67799b
...
...
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
-----------------
- Issue #17636: Circular imports involving relative imports are now
supported.
- Issue #22604: Fix assertion error in debug mode when dividing a complex
number by (nan+0j).
...
...
@@ -174,6 +177,8 @@ Core and Builtins
Library
-------
-
Issue
#
22435
:
Fix
a
file
descriptor
leak
when
SocketServer
bind
fails
.
-
Issue
#
13096
:
Fixed
segfault
in
CTypes
POINTER
handling
of
large
values
.
...
...
Python/ceval.c
View file @
4d67799b
...
...
@@ -4693,11 +4693,29 @@ static PyObject *
import_from
(
PyObject
*
v
,
PyObject
*
name
)
{
PyObject
*
x
;
_Py_IDENTIFIER
(
__name__
);
PyObject
*
fullmodname
,
*
pkgname
;
x
=
PyObject_GetAttr
(
v
,
name
);
if
(
x
==
NULL
&&
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
if
(
x
!=
NULL
||
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
x
;
/* Issue #17636: in case this failed because of a circular relative
import, try to fallback on reading the module directly from
sys.modules. */
PyErr_Clear
();
pkgname
=
_PyObject_GetAttrId
(
v
,
&
PyId___name__
);
if
(
pkgname
==
NULL
)
return
NULL
;
fullmodname
=
PyUnicode_FromFormat
(
"%U.%U"
,
pkgname
,
name
);
Py_DECREF
(
pkgname
);
if
(
fullmodname
==
NULL
)
return
NULL
;
x
=
PyDict_GetItem
(
PyImport_GetModuleDict
(),
fullmodname
);
if
(
x
==
NULL
)
PyErr_Format
(
PyExc_ImportError
,
"cannot import name %R"
,
name
);
}
else
Py_INCREF
(
x
);
Py_DECREF
(
fullmodname
);
return
x
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment