#12131 closed defect (fixed)
Transitive import in trac/web/main.py
Reported by: | Owned by: | Ryan J Ollos | |
---|---|---|---|
Priority: | normal | Milestone: | 1.2 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Fixed transitive import in |
||
API Changes: | |||
Internal Changes: |
Description
The linked block references StringIO but it's not imported (unless it's coming from one of the import *
imports (is it a goal to remove those?).
Attachments (0)
Change History (13)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Milestone: | → 1.0.8 |
---|
[14184,14186] adds import of StringIO
to trac.web.main
. Merged to trunk in [14185] (and the log message should say 1.2dev
rather than 1.1.7dev
, I figured I would make that error before too long …).
follow-up: 6 comment:3 by , 9 years ago
Defining __all__
for trac.web.api
results in this bit of ugliness.
-
trac/web/api.py
diff --git a/trac/web/api.py b/trac/web/api.py index 5041e49..14dca0a 100644
a b from trac.util.translation import _ 39 39 from trac.web.href import Href 40 40 from trac.web.wsgi import _FileWrapper 41 41 42 __all__ = ['IAuthenticator', 'IRequestHandler', 'is_valid_default_handler', 43 'IRequestFilter', 'ITemplateStreamFilter', 'parse_arg_list', 44 'arg_list_to_args', 'RequestDone', 'Cookie', 'Request'] 45 42 46 43 47 class IAuthenticator(Interface): 44 48 """Extension point interface for components that can provide the name … … for code in [code for code in HTTP_STATUS if code >= 400]: 228 232 setattr(sys.modules[__name__], exc_name, 229 233 HTTPException.subclass(exc_name, code)) 230 234 _HTTPException_subclass_names.append(exc_name) 235 __all__ += _HTTPException_subclass_names 231 236 del code, exc_name
We could break convention and put __all__
at the end of the file.
comment:4 by , 9 years ago
Milestone: | 1.0.8 → 1.0.9 |
---|
comment:5 by , 9 years ago
Milestone: | 1.0.9 → 1.2 |
---|
comment:6 by , 9 years ago
Replying to rjollos:
We could break convention and put
__all__
at the end of the file.
I'm thinking this is probably more clear.
-
trac/web/api.py
diff --git a/trac/web/api.py b/trac/web/api.py index 5041e49..7be9e32 100644
a b class Request(object): 840 840 for cookie in cookies.splitlines(): 841 841 self._outheaders.append(('Set-Cookie', cookie.strip())) 842 842 843 844 __all__ = ['IAuthenticator', 'IRequestHandler', 'is_valid_default_handler', 845 'IRequestFilter', 'ITemplateStreamFilter', 'parse_arg_list', 846 'arg_list_to_args', 'RequestDone', 'Cookie', 'Request'] + \ 847 _HTTPException_subclass_names 848 849 843 850 __no_apidoc__ = _HTTPException_subclass_names
comment:7 by , 9 years ago
Personally, I wouldn't worry too much about defining __all__
and just eliminate import *
.
comment:8 by , 9 years ago
Summary: | Possibly dead code in trac/web/main.py → Transitive import in trac/web/main.py |
---|
comment:9 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:10 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in [14214]. Thanks Tim!
comment:11 by , 9 years ago
Release Notes: | modified (diff) |
---|
comment:12 by , 9 years ago
Release Notes: | modified (diff) |
---|
comment:13 by , 9 years ago
I got AttributeError: class StringIO has no attribute 'StringIO'
with hdfdump=1
parameter, #12151. I dislike uses of star imports :<
Replying to Tim Graham <timograham@…>:
The code can be activated by appending
?hdfdump=1
to the URL, which enables a developer to view the values of the template parameters. The acronymshdf
is historical as far as I know, a holdover from when Trac used ClearSilver as the templating engine.I think both your observations are correct. We shouldn't use
from trac.web.api import *
, especially sincetrac.web.api
doesn't define__all__
, andStringIO
should be explicitly imported intrac.web.main
. I'll fix the latter now.