Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-bb flag gives error re: bytes and strings #147

Closed
rojalator opened this issue Nov 13, 2021 · 5 comments
Closed

-bb flag gives error re: bytes and strings #147

rojalator opened this issue Nov 13, 2021 · 5 comments

Comments

@rojalator
Copy link

rojalator commented Nov 13, 2021

We run our code with the python -bb flag to issue errors about string / byte comparisons. Doing so with psycopg3 results in:

python3.9/site-packages/psycopg/_encodings.py", line 64, in <module> py_codecs.update((k.encode(), v) for k, v in _py_codecs.items())
This was not the case with psycopg2 (we are in the process of moving to psycopg3 from psycopg2)
Obviously our workaround is to just use -b (or none at all) - I note though, that #122 also indicates a UNICODE error so perhaps _encodings.py requires a bit more work.

Python 3.9
psycopg 3.0.3

@dvarrazzo
Copy link
Member

Running the test suite on -bb reproduces the issue, so I should be good to fix it, thank you

@dvarrazzo
Copy link
Member

Looks like you simply can't have a dict with Union[str, bytes] keys under -bb.

I'm taking a look if it's practical to remove these occurrences.

#122 is related to the content and the use of a database which is not currently supported.

dvarrazzo added a commit that referenced this issue Nov 13, 2021
They were mostly internal ones, coming from dicts containing strings and
bytes as keys.

Close #147
dvarrazzo added a commit that referenced this issue Nov 13, 2021
They were mostly internal ones, coming from dicts containing strings and
bytes as keys.

Close #147
@dvarrazzo
Copy link
Member

A fix is on the way. Do you know if there is a practical way to enable running pytest with -bb? python -bb -m pytest seems the only way.

@rojalator
Copy link
Author

I think that is the only way, although you could add it to the #! of any script, perhaps
#!/usr/bin/env python -bb

I looked all over (including the ini files) but have never found out how!

Thanks for the rapid fix.
RJL

@rojalator
Copy link
Author

Thanks for the fix - I confirm that it works now for us with no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants