Movatterモバイル変換
[0]ホーム
[Python-Dev] #pragmas in Python source code
Peter Funkpf@artcom-gmbh.de
Wed, 12 Apr 2000 17:37:05 +0200 (MEST)
Hi!Fred L. Drake, Jr.:> M.-A. Lemburg writes:> > Here's a simple strawman for the syntax:> ...> > The compiler would scan these pragma defs, add them to an> > internal temporary dictionary and use them for all subsequent> > code it finds during the compilation process. The dictionary> > would have to stay around until the original compile() call has> > completed (spanning recursive calls).>> Marc-Andre,> The problem with this proposal is that the pragmas are embedded in> the comments; I'd rather see a new keyword and statement. It could be> defined something like:>> pragma_atom: NAME | NUMBER | STRING+> pragma_stmt: 'pragma' NAME ':' pragma_atom (',' pragma_atom)*This would defeat an important goal: backward compatibility: Youcan't add 'pragma division: old' or something like this to a sourcefile, which should be able to run with both Python 1.5.2 and Py3k.This would make this mechanism useless for several importantapplications of pragmas. Here comes David Scherers idea into play. The relevant emails of this thread are in the archive at:<URL:http://www.python.org/pipermail/idle-dev/2000-April/000138.html><URL:http://www.python.org/pipermail/idle-dev/2000-April/000140.html><URL:http://www.python.org/pipermail/python-dev/2000-April/004761.html>> The biggest problem with embedding it in comments is that it is no> longer part of the syntax tree generated by the parser. The pragmas> become global to the module on a de-facto basis. While this is> probably reasonable for the sorts of pragmas we've thought of so far,> this seems an unnecessary restriction; future tools may support scoped> pragmas to help out with selection of optimization strategies, for> instance, or other applications.[...]IMO this is overkill. For all real applications that have been discussed so far, global pragmas are sufficient:- source file character encoding- language level- generated division operator byte codes- generated comparision operators byte codes (comparing strings and numbers)I really like Davids idea to use 'global' at module level for the purpose of pragmas. And this idea has also the advantage that Guido already wrote the idea is "kind of cute and backwards compatible".Regards, Peter-- Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)
[8]ページ先頭