Is it something specific to the environment? I tried the test on Ubuntu 16.04 on both master and on v3.6.3 with no errors. Maybe if you can execute the following code based on which the test is executed then it will be helpful to debug this. import locale foo, enc = locale.getlocale(locale.LC_CTYPE) # Search non-ASCII letter for i in range(128, 256): try: c = bytes([i]).decode(enc) sletter = c.lower() if sletter == c: continue bletter = sletter.encode(enc) if len(bletter) != 1: continue if bletter.decode(enc) != sletter: continue bpat = re.escape(bytes([i])) break except (UnicodeError, TypeError): pass else: bletter = None bpat = b'A' # Bytes patterns print(bletter) print(bpat) print(foo) print(enc) Thanks