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
dda58434
Commit
dda58434
authored
Dec 12, 2015
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19771: Omit irrelevant message if package could not be initialized
parent
f0c0318c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
0 deletions
+19
-0
Lib/runpy.py
Lib/runpy.py
+2
-0
Lib/test/test_cmd_line_script.py
Lib/test/test_cmd_line_script.py
+13
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/runpy.py
View file @
dda58434
...
@@ -132,6 +132,8 @@ def _get_module_details(mod_name, error=ImportError):
...
@@ -132,6 +132,8 @@ def _get_module_details(mod_name, error=ImportError):
pkg_main_name
=
mod_name
+
".__main__"
pkg_main_name
=
mod_name
+
".__main__"
return
_get_module_details
(
pkg_main_name
,
error
)
return
_get_module_details
(
pkg_main_name
,
error
)
except
error
as
e
:
except
error
as
e
:
if
mod_name
not
in
sys
.
modules
:
raise
# No module loaded; being a package is irrelevant
raise
error
((
"%s; %r is a package and cannot "
+
raise
error
((
"%s; %r is a package and cannot "
+
"be directly executed"
)
%
(
e
,
mod_name
))
"be directly executed"
)
%
(
e
,
mod_name
))
loader
=
spec
.
loader
loader
=
spec
.
loader
...
...
Lib/test/test_cmd_line_script.py
View file @
dda58434
...
@@ -442,6 +442,19 @@ class CmdLineTest(unittest.TestCase):
...
@@ -442,6 +442,19 @@ class CmdLineTest(unittest.TestCase):
self
.
assertRegex
(
err
,
regex
)
self
.
assertRegex
(
err
,
regex
)
self
.
assertNotIn
(
b'Traceback'
,
err
)
self
.
assertNotIn
(
b'Traceback'
,
err
)
def
test_dash_m_bad_pyc
(
self
):
with
support
.
temp_dir
()
as
script_dir
,
\
support
.
change_cwd
(
path
=
script_dir
):
os
.
mkdir
(
'test_pkg'
)
# Create invalid *.pyc as empty file
with
open
(
'test_pkg/__init__.pyc'
,
'wb'
):
pass
err
=
self
.
check_dash_m_failure
(
'test_pkg'
)
self
.
assertRegex
(
err
,
br'Error while finding spec.*'
br'ImportError.*bad magic number'
)
self
.
assertNotIn
(
b'is a package'
,
err
)
self
.
assertNotIn
(
b'Traceback'
,
err
)
def
test_dash_m_init_traceback
(
self
):
def
test_dash_m_init_traceback
(
self
):
# These were wrapped in an ImportError and tracebacks were
# These were wrapped in an ImportError and tracebacks were
# suppressed; see Issue 14285
# suppressed; see Issue 14285
...
...
Misc/NEWS
View file @
dda58434
...
@@ -41,6 +41,10 @@ Library
...
@@ -41,6 +41,10 @@ Library
"runpy"
module
now
lets
exceptions
from
package
initialization
pass
back
to
"runpy"
module
now
lets
exceptions
from
package
initialization
pass
back
to
the
caller
,
rather
than
raising
ImportError
.
the
caller
,
rather
than
raising
ImportError
.
-
Issue
#
19771
:
Also
in
runpy
and
the
"-m"
option
,
omit
the
irrelevant
message
". . . is a package and cannot be directly executed"
if
the
package
could
not
even
be
initialized
(
e
.
g
.
due
to
a
bad
*.
pyc
file
).
-
Issue
#
25177
:
Fixed
problem
with
the
mean
of
very
small
and
very
large
-
Issue
#
25177
:
Fixed
problem
with
the
mean
of
very
small
and
very
large
numbers
.
As
a
side
effect
,
statistics
.
mean
and
statistics
.
variance
should
numbers
.
As
a
side
effect
,
statistics
.
mean
and
statistics
.
variance
should
be
significantly
faster
.
be
significantly
faster
.
...
...
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