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

bpo-40179: Fix translation of #elif in Argument Clinic #19364

Merged
merged 2 commits into from
Apr 18, 2020

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 4, 2020

@ZackerySpytz
Copy link
Contributor

It seems that some of the code added in this PR does not adhere to PEP 8.

@serhiy-storchaka
Copy link
Member Author

Do you mean that some line is 84 characters long? It is slightly longer that the limit recommended by PEP 8. But there are much longer lines in the surrounded code (up to 104 characters), and I prefer to keep the consistent style.

@ammaraskar
Copy link
Member

ammaraskar commented Apr 12, 2020

Should we consider adding a direct test for this in clinic.test with something like:

/*[clinic input]
output push
output preset buffer
[clinic start generated code]*/

#ifdef CONDITION_A
/*[clinic input]
test_preprocessor_guarded_condition_a
[clinic start generated code]*/
#elif CONDITION_B
/*[clinic input]
test_preprocessor_guarded_elif_condition_b
[clinic start generated code]*/
#else
/*[clinic input]
test_preprocessor_guarded_else
[clinic start generated code]*/
#endif

/*[clinic input]
dump buffer
output pop
[clinic start generated code]*/
Fully expands to:
/*[clinic input]
output push
output preset buffer
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5bff3376ee0df0b5]*/

#ifdef CONDITION_A
/*[clinic input]
test_preprocessor_guarded_condition_a
[clinic start generated code]*/

static PyObject *
test_preprocessor_guarded_condition_a_impl(PyObject *module)
/*[clinic end generated code: output=ad012af18085add6 input=8edb8706a98cda7e]*/
#elif CONDITION_B
/*[clinic input]
test_preprocessor_guarded_elif_condition_b
[clinic start generated code]*/

static PyObject *
test_preprocessor_guarded_elif_condition_b_impl(PyObject *module)
/*[clinic end generated code: output=615f2dee82b138d1 input=53777cebbf7fee32]*/
#else
/*[clinic input]
test_preprocessor_guarded_else
[clinic start generated code]*/

static PyObject *
test_preprocessor_guarded_else_impl(PyObject *module)
/*[clinic end generated code: output=13af7670aac51b12 input=6657ab31d74c29fc]*/
#endif

/*[clinic input]
dump buffer
output pop
[clinic start generated code]*/

#if defined(CONDITION_A)

PyDoc_STRVAR(test_preprocessor_guarded_condition_a__doc__,
"test_preprocessor_guarded_condition_a($module, /)\n"
"--\n"
"\n");

#define TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF    \
    {"test_preprocessor_guarded_condition_a", (PyCFunction)test_preprocessor_guarded_condition_a, METH_NOARGS, test_preprocessor_guarded_condition_a__doc__},

static PyObject *
test_preprocessor_guarded_condition_a(PyObject *module, PyObject *Py_UNUSED(ignored))
{
    return test_preprocessor_guarded_condition_a_impl(module);
}

#endif /* defined(CONDITION_A) */

#if !defined(CONDITION_A) && (CONDITION_B)

PyDoc_STRVAR(test_preprocessor_guarded_elif_condition_b__doc__,
"test_preprocessor_guarded_elif_condition_b($module, /)\n"
"--\n"
"\n");

#define TEST_PREPROCESSOR_GUARDED_ELIF_CONDITION_B_METHODDEF    \
    {"test_preprocessor_guarded_elif_condition_b", (PyCFunction)test_preprocessor_guarded_elif_condition_b, METH_NOARGS, test_preprocessor_guarded_elif_condition_b__doc__},

static PyObject *
test_preprocessor_guarded_elif_condition_b(PyObject *module, PyObject *Py_UNUSED(ignored))
{
    return test_preprocessor_guarded_elif_condition_b_impl(module);
}

#endif /* !defined(CONDITION_A) && (CONDITION_B) */

#if !defined(CONDITION_A) && !(CONDITION_B)

PyDoc_STRVAR(test_preprocessor_guarded_else__doc__,
"test_preprocessor_guarded_else($module, /)\n"
"--\n"
"\n");

#define TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF    \
    {"test_preprocessor_guarded_else", (PyCFunction)test_preprocessor_guarded_else, METH_NOARGS, test_preprocessor_guarded_else__doc__},

static PyObject *
test_preprocessor_guarded_else(PyObject *module, PyObject *Py_UNUSED(ignored))
{
    return test_preprocessor_guarded_else_impl(module);
}

#endif /* !defined(CONDITION_A) && !(CONDITION_B) */

#ifndef TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
    #define TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_CONDITION_A_METHODDEF) */

#ifndef TEST_PREPROCESSOR_GUARDED_ELIF_CONDITION_B_METHODDEF
    #define TEST_PREPROCESSOR_GUARDED_ELIF_CONDITION_B_METHODDEF
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_ELIF_CONDITION_B_METHODDEF) */

#ifndef TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
    #define TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF
#endif /* !defined(TEST_PREPROCESSOR_GUARDED_ELSE_METHODDEF) */
/*[clinic end generated code: output=3804bb18d454038c input=3fc80c9989d2f2e1]*/

@serhiy-storchaka
Copy link
Member Author

Great idea @ammaraskar! I tried to add tests, but without output preset buffer Argument Clinic did not produce useful output. Thank you for your tests!

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
@serhiy-storchaka
Copy link
Member Author

@larryhastings could you please take a look? It is a blocker for #19360.

@serhiy-storchaka serhiy-storchaka merged commit 12446e6 into python:master Apr 18, 2020
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.8 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 12446e6a605f066d837d3a595d0a73e4f3b43b65 3.8

@miss-islington
Copy link
Contributor

Sorry @serhiy-storchaka, I had trouble checking out the 3.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 12446e6a605f066d837d3a595d0a73e4f3b43b65 3.7

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Apr 18, 2020
…nGH-19364)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>.
(cherry picked from commit 12446e6)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Apr 18, 2020
@bedevere-bot
Copy link

GH-19583 is a backport of this pull request to the 3.8 branch.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Apr 18, 2020
…nGH-19364)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>.
(cherry picked from commit 12446e6)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot
Copy link

GH-19584 is a backport of this pull request to the 3.7 branch.

serhiy-storchaka added a commit that referenced this pull request Apr 18, 2020
… (GH-19583)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
(cherry picked from commit 12446e6)
serhiy-storchaka added a commit that referenced this pull request Apr 18, 2020
… (GH-19584)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
(cherry picked from commit 12446e6)
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request May 29, 2020
* master: (1985 commits)
  bpo-40179: Fix translation of #elif in Argument Clinic (pythonGH-19364)
  bpo-35967: Skip test with `uname -p` on Android (pythonGH-19577)
  bpo-40257: Improve help for the typing module (pythonGH-19546)
  Fix two typos in multiprocessing (pythonGH-19571)
  bpo-40286: Use random.randbytes() in tests (pythonGH-19575)
  bpo-40286: Makes simpler the relation between randbytes() and getrandbits() (pythonGH-19574)
  bpo-39894: Route calls from pathlib.Path.samefile() to os.stat() via the path accessor (pythonGH-18836)
  bpo-39897: Remove needless `Path(self.parent)` call, which makes `is_mount()` misbehave in `Path` subclasses. (pythonGH-18839)
  bpo-40282: Allow random.getrandbits(0) (pythonGH-19539)
  bpo-40302: UTF-32 encoder SWAB4() macro use a|b rather than a+b (pythonGH-19572)
  bpo-40302: Replace PY_INT64_T with int64_t (pythonGH-19573)
  bpo-40286: Add randbytes() method to random.Random (pythonGH-19527)
  bpo-39901: Move `pathlib.Path.owner()` and `group()` implementations into the path accessor. (pythonGH-18844)
  bpo-40300: Allow empty logging.Formatter.default_msec_format. (pythonGH-19551)
  bpo-40302: Add pycore_byteswap.h header file (pythonGH-19552)
  bpo-40287: Fix SpooledTemporaryFile.seek() return value (pythonGH-19540)
  Minor modernization and readability improvement to the tokenizer example (pythonGH-19558)
  bpo-40294: Fix _asyncio when module is loaded/unloaded multiple times (pythonGH-19542)
  Fix parameter names in assertIn() docs (pythonGH-18829)
  bpo-39793: use the same domain on make_msgid tests (python#18698)
  ...
@serhiy-storchaka serhiy-storchaka removed their assignment Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants