diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-24 11:54:55 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-24 11:54:55 +0200 |
commit | 78eab36d0953c7960dd281a68f688f314af2fccc (patch) | |
tree | 839d81ba46704d63b74afbe4d549f20cc2aa241d | |
parent | 426b1207b2af6335d398f207a1138261cca967bd (diff) | |
download | cython-78eab36d0953c7960dd281a68f688f314af2fccc.tar.gz |
Fix unicode name handling of no-args functions when allowing keywords.
-rw-r--r-- | Cython/Compiler/Nodes.py | 8 | ||||
-rw-r--r-- | tests/run/unicode_identifiers.pyx | 24 |
2 files changed, 24 insertions, 8 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 0827e1783..d617053af 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3663,8 +3663,8 @@ class DefNodeWrapper(FuncDefNode): code.globalstate.use_utility_code( UtilityCode.load_cached("RaiseArgTupleInvalid", "FunctionArguments.c")) code.putln("if (unlikely(%s > 0)) {" % Naming.nargs_cname) - code.put('__Pyx_RaiseArgtupleInvalid("%s", 1, 0, 0, %s); return %s;' % ( - self.name, Naming.nargs_cname, self.error_value())) + code.put('__Pyx_RaiseArgtupleInvalid(%s, 1, 0, 0, %s); return %s;' % ( + self.name.as_c_string_literal(), Naming.nargs_cname, self.error_value())) code.putln("}") if self.starstar_arg: @@ -3678,8 +3678,8 @@ class DefNodeWrapper(FuncDefNode): code.globalstate.use_utility_code( UtilityCode.load_cached("KeywordStringCheck", "FunctionArguments.c")) code.putln( - "if (%s && unlikely(!__Pyx_CheckKeywordStrings(%s, \"%s\", %d))) return %s;" % ( - kwarg_check, Naming.kwds_cname, self.name, + "if (%s && unlikely(!__Pyx_CheckKeywordStrings(%s, %s, %d))) return %s;" % ( + kwarg_check, Naming.kwds_cname, self.name.as_c_string_literal(), bool(self.starstar_arg), self.error_value())) if self.starstar_arg and self.starstar_arg.entry.cf_used: diff --git a/tests/run/unicode_identifiers.pyx b/tests/run/unicode_identifiers.pyx index 76b7f3cbc..767e3283e 100644 --- a/tests/run/unicode_identifiers.pyx +++ b/tests/run/unicode_identifiers.pyx @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# cython: language_level=3 # mode: run # tag: pep3131, traceback +# cython: language_level=3 + # Code with unicode identifiers can be compiled with Cython running either Python 2 or 3. # However Python access to unicode identifiers is only possible in Python 3. In Python 2 # it's only really safe to use the unicode identifiers for purely Cython interfaces @@ -11,10 +12,13 @@ # This is controlled by putting the Python3 only tests in the module __doc__ attribute # Most of the individual function and class docstrings are only present as a compile test +cimport cython + import sys -if sys.version_info[0]>2: - __doc__ = """ + +if sys.version_info[0] > 2: + __doc__ = u""" >>> f()() 2 >>> f().__name__ @@ -37,6 +41,9 @@ if sys.version_info[0]>2: >>> print(x.α) 200 + >>> B().Ƒ() + >>> C().Ƒ() + Test generation of locals() >>> sorted(Γναμε2().boring_function(1,2).keys()) ['self', 'somevalue', 'x', 'ναμε5', 'ναμε6'] @@ -45,6 +52,8 @@ if sys.version_info[0]>2: 0 >>> function_taking_fancy_argument(Γναμε2()).ναμε3 1 + >>> metho_function_taking_fancy_argument(Γναμε2()).ναμε3 + 1 >>> NormalClassΓΓ().ναμε 10 >>> NormalClassΓΓ().εxciting_function(None).__qualname__ @@ -81,7 +90,7 @@ cdef class A: def __init__(self): self.ναμε = 1 cdef Ƒ(self): - return self.ναμε==1 + return self.ναμε == 1 def regular_function(self): """ Can use unicode cdef functions and (private) attributes internally @@ -174,9 +183,16 @@ cdef class Derived(Γναμε2): cdef Γναμε2 global_ναμε3 = Γναμε2() + +@cython.always_allow_keywords(False) # METH_O signature +def metho_function_taking_fancy_argument(Γναμε2 αrγ): + return αrγ + +@cython.always_allow_keywords(True) def function_taking_fancy_argument(Γναμε2 αrγ): return αrγ + class NormalClassΓΓ(Γναμε2): """ docstring |