This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年10月31日 05:41 by terry.reedy, last changed 2022年04月11日 14:58 by admin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 17051 | open | ZackerySpytz, 2019年11月05日 00:38 | |
| Messages (8) | |||
|---|---|---|---|
| msg253775 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2015年10月31日 05:41 | |
When users 'saveas', warn if name matches that of a stdlib modules. Note that shadowing is opposite for lib and binary (builtin) modules, so message needs to be different. I am not worrying about 3rd party modules on the search path (ie, site-packages), which would be shadowed like lib modules. Rough outline of code to add to IOBinding.
from os,path import dirname
import sys
# this part on initiallzation or first saveas call
def libmodules():
with open(dirname(dirname(__file__))) as lib:
for f in lib:
if <directory containing __init__.py#> or f.endswith(.py):
yield f
# test.test__all__ has this code
islibmodule = frozenset(libmodules()).__contains__
isbinmodule = frozenset(sys.builtin_module_names).__contains__
# this part after saveas dialog returns
if islibmodule(name):
go = warn("This name matches a stdlib name in /Lib. If you run python in this directory, you will not be able to import the stdlib module. Continue?".)
elif isbinmodule(name):
go = warn("This name matches a builtin stdlib name. You will not be able to import this file. Continue?".)
else:
go = True
if go:
<save as requested>
else:
(get name again> # or put in while not go loop
|
|||
| msg253777 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2015年10月31日 05:56 | |
The lib messages should say "Neither you nor python will be able to import the stdlib module". Example of python-imported lib names that a beginner might write are abc, io, os, nt, and stat. |
|||
| msg253829 - (view) | Author: Laura Creighton (lac) | Date: 2015年11月01日 07:26 | |
I'm not sure about "Neither you nor Python will be able to import the stdlib." Depending on what the file is, you may be able to import it later. I'd prefer: "If you run Python in this directory, your version of <stdlibname> will be used instead of the one in the standard library. This may cause Idle to behave strangely, or possibly not run at all." |
|||
| msg253830 - (view) | Author: Laura Creighton (lac) | Date: 2015年11月01日 07:36 | |
Do we need a full path name here as well? Probably not. |
|||
| msg333944 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年01月18日 06:35 | |
Also check if the name is not an identifier and therefore could not be imported. Example:
>>> exec('import abc--bb')
import abc--bb
^
SyntaxError: invalid syntax
|
|||
| msg333952 - (view) | Author: Vedran Čačić (veky) * | Date: 2019年01月18日 08:26 | |
Many beginners don't write files in order to import them. For them, these name-checking is simply adding noise. If you want to do something in this area, I think a much more useful (and difficult) course of action would be to check on the opposite end. If an AttributeError "module blah has no attribute foo" is raised, then check whether a file in the current directory (or simply the current file) is named blah, and there is also a stdlib blah that has fool. |
|||
| msg334279 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年01月24日 04:39 | |
Beginners import stdlib files such as random. And they save scripts with such name, and accidentally import the script when not desired. Beginners should learn how to test a script by running a test file provided by an instructor or written themselves. In either case, they *will* have to import the script. |
|||
| msg355988 - (view) | Author: Zackery Spytz (ZackerySpytz) * (Python triager) | Date: 2019年11月05日 00:40 | |
I have created a pull request for this issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:23 | admin | set | github: 69708 |
| 2019年11月05日 00:40:06 | ZackerySpytz | set | nosy:
+ ZackerySpytz messages: + msg355988 |
| 2019年11月05日 00:38:14 | ZackerySpytz | set | keywords:
+ patch stage: needs patch -> patch review pull_requests: + pull_request16565 |
| 2019年01月24日 04:39:08 | terry.reedy | set | messages: + msg334279 |
| 2019年01月18日 08:26:45 | veky | set | nosy:
+ veky messages: + msg333952 |
| 2019年01月18日 06:35:38 | terry.reedy | set | messages: + msg333944 |
| 2017年06月19日 19:07:50 | terry.reedy | set | assignee: terry.reedy components: + IDLE versions: + Python 3.7, - Python 2.7, Python 3.4, Python 3.5 |
| 2015年11月28日 01:15:20 | THRlWiTi | set | nosy:
+ THRlWiTi |
| 2015年11月01日 07:36:57 | lac | set | messages: + msg253830 |
| 2015年11月01日 07:26:49 | lac | set | messages: + msg253829 |
| 2015年10月31日 05:56:24 | terry.reedy | set | messages: + msg253777 |
| 2015年10月31日 05:41:42 | terry.reedy | create | |