Skip to content

Commit c7d3315

Browse files
committed
Clarify prefix check on interned string type
1 parent 21c35b2 commit c7d3315

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pyc_module.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class PycModule {
6464
return (m_maj >= 3) || (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
6565
}
6666

67+
bool internIsBytes() const
68+
{
69+
return (m_maj < 3) && (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
70+
}
71+
6772
PycRef<PycCode> code() const { return m_code; }
6873

6974
void intern(PycRef<PycString> str) { m_interns.emplace_back(std::move(str)); }

pyc_string.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ void PycString::print(std::ostream &pyc_output, PycModule* mod, bool triple,
6868
prefix = mod->strIsUnicode() ? 0 : 'u';
6969
break;
7070
case PycObject::TYPE_INTERNED:
71+
prefix = mod->internIsBytes() ? 'b' : 0;
72+
break;
7173
case PycObject::TYPE_ASCII:
7274
case PycObject::TYPE_ASCII_INTERNED:
7375
case PycObject::TYPE_SHORT_ASCII:
7476
case PycObject::TYPE_SHORT_ASCII_INTERNED:
75-
if (mod->majorVer() >= 3)
76-
prefix = 0;
77-
else
78-
prefix = mod->strIsUnicode() ? 'b' : 0;
77+
// These types don't exist until Python 3.4
78+
prefix = 0;
7979
break;
8080
default:
8181
throw std::runtime_error("Invalid string type");

0 commit comments

Comments
 (0)