Misleading __reduce_cython__ error on import
See original GitHub issueWhenever you use an import
instead of a cimport
compiling will work but you might be graced with an unrelated error message at import time.
Can’t create easily a self-contained test: I tried and the code was failing with an expected ImportError
, however you can reproduce it it with:
git clone git@github.com:psycopg/psycopg3.git mypyerr
cd mypyerr
git checkout 5647fb04dc6eb3e46e2a7bde490feea5be11f2c1
cat <<HERE | patch -p1
--- a/psycopg3/types/text.pyx
+++ b/psycopg3/types/text.pyx
@@ -1,3 +1,4 @@
+from cpython.unicode import PyUnicode_DecodeAscii
from cpython.unicode cimport PyUnicode_DecodeUTF8
cdef object load_text_binary(const char *data, size_t length, void *context):
HERE
python setup.py develop
python -c "import psycopg3._psycopg3"
Which raises the error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "psycopg3/pq/pq_cython.pyx", line 34, in init psycopg3._psycopg3
cdef class PGconn:
AttributeError: type object 'psycopg3._psycopg3.PGconn' has no attribute '__reduce_cython__'
I believe many help requests about __reduce_cython__
are related to this.
Tested with Python 3.6 and Cython 3.0a1.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (6 by maintainers)
Top Results From Across the Web
NameError: name 'reduce' is not defined in Python
Reduce function is not defined in the Python built-in function. So first, you should import the reduce function from functools import reduce.
Read more >Avoid "reduce" in Python
Python's reduce function can "reduce" an iterable to a single value. But the reduce function is often more hassle than it's worth.
Read more >Python's reduce(): From Functional to Pythonic Style
Python's reduce () implements a mathematical technique commonly known as folding or reduction. You're doing a fold or reduction when you reduce a...
Read more >Apparent false positive when using reduce with dictionaries
When using reduce on an Iterable/List of dictionaries, mypy seems to be confused about the signature of the function and seems to be...
Read more >functools — Higher-order functions and operations on callable ...
New in version 3.4. Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@scoder Move the exception before the class definition and it does break in master though. I’ve edited the example above
Confirmed fixed for my use case too. Thank you for working on it even if my test wasn’t easy to reproduce! 👍