question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading __reduce_cython__ error on import

See original GitHub issue

Whenever 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
da-woodscommented, Apr 24, 2020

@scoder Move the exception before the class definition and it does break in master though. I’ve edited the example above

0reactions
dvarrazzocommented, Apr 26, 2020

Confirmed fixed for my use case too. Thank you for working on it even if my test wasn’t easy to reproduce! 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found