@@ -265,13 +265,20 @@ private CacheItem parseWithANTLR(ParserMode mode, ParserErrorCallback errors, Py
265
265
FrameDescriptor inlineLocals = mode == ParserMode .InlineEvaluation ? currentFrame .getFrameDescriptor () : null ;
266
266
String sourceText = source .getCharacters ().toString ();
267
267
// Preprocessing
268
- // Check that declared encoding (if any) is valid. The file detector picks an encoding for
269
- // the file, but it doesn't have a means of communicating that the declared encoding wasn't
270
- // valid or supported, so in that case it defaults to Latin-1 and we have to recheck it here
271
- try {
272
- PythonFileDetector .findEncodingStrict (sourceText );
273
- } catch (PythonFileDetector .InvalidEncodingException e ) {
274
- throw errors .raiseInvalidSyntax (source , source .createUnavailableSection (), "encoding problem: %s" , e .getEncodingName ());
268
+
269
+ // Check that declared encoding (if any) is valid. The file detector picks an encoding
270
+ // for the file, but it doesn't have a means of communicating that the declared encoding
271
+ // wasn't valid or supported, so in that case it defaults to Latin-1 and we have to
272
+ // recheck it here.
273
+ // msimacek: The encoding check should happen only when the source encoding was
274
+ // determined by PythonFileDetector. But we currently have no way to tell, so we
275
+ // assume that it is the case when it is a file.
276
+ if (source .getURI ().getScheme ().equals ("file" )) {
277
+ try {
278
+ PythonFileDetector .findEncodingStrict (sourceText );
279
+ } catch (PythonFileDetector .InvalidEncodingException e ) {
280
+ throw errors .raiseInvalidSyntax (source , source .createUnavailableSection (), "encoding problem: %s" , e .getEncodingName ());
281
+ }
275
282
}
276
283
// ANTLR parsing
277
284
Python3Parser parser = getPython3Parser (source , errors );
0 commit comments