@@ -120,23 +120,17 @@ def __repr__(self):
120
120
assert s1 == s2
121
121
122
122
malformed_utf8 = b"\x80 "
123
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ):
124
+ assert m .str_from_object (malformed_utf8 ) is malformed_utf8
125
+ elif env .PY2 :
126
+ with pytest .raises (UnicodeDecodeError ):
127
+ m .str_from_object (malformed_utf8 )
128
+ else :
129
+ assert m .str_from_object (malformed_utf8 ) == "b'\\ x80'"
123
130
if env .PY2 :
124
- if hasattr (m , "has_str_non_permissive" ):
125
- with pytest .raises (UnicodeDecodeError ):
126
- m .str_from_object (malformed_utf8 )
127
- else :
128
- m .str_from_object (
129
- malformed_utf8
130
- ) is malformed_utf8 # To be fixed; see #2380
131
131
with pytest .raises (UnicodeDecodeError ):
132
132
m .str_from_handle (malformed_utf8 )
133
133
else :
134
- if hasattr (m , "has_str_non_permissive" ):
135
- assert m .str_from_object (malformed_utf8 ) == "b'\\ x80'"
136
- else :
137
- assert (
138
- m .str_from_object (malformed_utf8 ) is malformed_utf8
139
- ) # To be fixed; see #2380
140
134
assert m .str_from_handle (malformed_utf8 ) == "b'\\ x80'"
141
135
142
136
@@ -310,26 +304,26 @@ def test_pybind11_str_raw_str():
310
304
valid_orig = u"DZ"
311
305
valid_utf8 = valid_orig .encode ("utf-8" )
312
306
valid_cvt = cvt (valid_utf8 )
313
- if hasattr (m , "has_str_non_permissive" ):
307
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ):
308
+ assert valid_cvt is valid_utf8
309
+ else :
314
310
assert type (valid_cvt ) is unicode if env .PY2 else str # noqa: F821
315
311
if env .PY2 :
316
312
assert valid_cvt == valid_orig
317
313
else :
318
- assert valid_cvt == u"b'\\ xc7\\ xb1'"
319
- else :
320
- assert valid_cvt is valid_utf8
314
+ assert valid_cvt == "b'\\ xc7\\ xb1'"
321
315
322
316
malformed_utf8 = b"\x80 "
323
- if hasattr (m , "has_str_non_permissive" ):
317
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ):
318
+ assert cvt (malformed_utf8 ) is malformed_utf8
319
+ else :
324
320
if env .PY2 :
325
321
with pytest .raises (UnicodeDecodeError ):
326
322
cvt (malformed_utf8 )
327
323
else :
328
324
malformed_cvt = cvt (malformed_utf8 )
329
- assert type (malformed_cvt ) is unicode if env .PY2 else str # noqa: F821
330
- assert malformed_cvt == u"b'\\ x80'"
331
- else :
332
- assert cvt (malformed_utf8 ) is malformed_utf8
325
+ assert type (malformed_cvt ) is str
326
+ assert malformed_cvt == "b'\\ x80'"
333
327
334
328
335
329
def test_implicit_casting ():
@@ -515,34 +509,33 @@ def test_isinstance_string_types():
515
509
assert not m .isinstance_pybind11_bytes (u"" )
516
510
517
511
assert m .isinstance_pybind11_str (u"" )
518
- if hasattr (m , "has_str_non_permissive" ):
519
- assert not m .isinstance_pybind11_str (b"" )
520
- else :
512
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ):
521
513
assert m .isinstance_pybind11_str (b"" )
514
+ else :
515
+ assert not m .isinstance_pybind11_str (b"" )
522
516
523
517
524
518
def test_pass_bytes_or_unicode_to_string_types ():
525
519
assert m .pass_to_pybind11_bytes (b"Bytes" ) == 5
526
520
with pytest .raises (TypeError ):
527
521
m .pass_to_pybind11_bytes (u"Str" )
528
522
529
- if hasattr (m , "has_str_caster_no_implicit_decode" ):
523
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ) or env .PY2 :
524
+ assert m .pass_to_pybind11_str (b"Bytes" ) == 5
525
+ else :
530
526
with pytest .raises (TypeError ):
531
527
m .pass_to_pybind11_str (b"Bytes" )
532
- else :
533
- assert m .pass_to_pybind11_str (b"Bytes" ) == 5
534
528
assert m .pass_to_pybind11_str (u"Str" ) == 3
535
529
536
530
assert m .pass_to_std_string (b"Bytes" ) == 5
537
531
assert m .pass_to_std_string (u"Str" ) == 3
538
532
539
533
malformed_utf8 = b"\x80 "
540
- if hasattr (m , "has_str_non_permissive" ):
541
- if hasattr (m , "has_str_caster_no_implicit_decode" ):
542
- with pytest .raises (TypeError ):
543
- m .pass_to_pybind11_str (malformed_utf8 )
544
- else :
545
- with pytest .raises (UnicodeDecodeError ):
546
- m .pass_to_pybind11_str (malformed_utf8 )
547
- else :
534
+ if hasattr (m , "PYBIND11_STR_LEGACY_PERMISSIVE" ):
548
535
assert m .pass_to_pybind11_str (malformed_utf8 ) == 1
536
+ elif env .PY2 :
537
+ with pytest .raises (UnicodeDecodeError ):
538
+ m .pass_to_pybind11_str (malformed_utf8 )
539
+ else :
540
+ with pytest .raises (TypeError ):
541
+ m .pass_to_pybind11_str (malformed_utf8 )
0 commit comments