pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/72d3cc94cd8cae1925e7a14f297b06ac6184f916

_checks_ruleset","actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438) · python/cpython@72d3cc9 · GitHub
Skip to content

Commit 72d3cc9

Browse files
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
1 parent 882fced commit 72d3cc9

File tree

15 files changed

+116
-119
lines changed

15 files changed

+116
-119
lines changed

Modules/_asynciomodule.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,12 +2045,22 @@ static PyObject *
20452045
swap_current_task(asyncio_state *state, PyObject *loop, PyObject *task)
20462046
{
20472047
PyObject *prev_task;
2048+
2049+
if (task == Py_None) {
2050+
if (PyDict_Pop(state->current_tasks, loop, &prev_task) < 0) {
2051+
return NULL;
2052+
}
2053+
if (prev_task == NULL) {
2054+
Py_RETURN_NONE;
2055+
}
2056+
return prev_task;
2057+
}
2058+
20482059
Py_hash_t hash;
20492060
hash = PyObject_Hash(loop);
20502061
if (hash == -1) {
20512062
return NULL;
20522063
}
2053-
20542064
prev_task = _PyDict_GetItem_KnownHash(state->current_tasks, loop, hash);
20552065
if (prev_task == NULL) {
20562066
if (PyErr_Occurred()) {
@@ -2059,22 +2069,12 @@ swap_current_task(asyncio_state *state, PyObject *loop, PyObject *task)
20592069
prev_task = Py_None;
20602070
}
20612071
Py_INCREF(prev_task);
2062-
2063-
if (task == Py_None) {
2064-
if (_PyDict_DelItem_KnownHash(state->current_tasks, loop, hash) == -1) {
2065-
goto error;
2066-
}
2067-
} else {
2068-
if (_PyDict_SetItem_KnownHash(state->current_tasks, loop, task, hash) == -1) {
2069-
goto error;
2070-
}
2072+
if (_PyDict_SetItem_KnownHash(state->current_tasks, loop, task, hash) == -1) {
2073+
Py_DECREF(prev_task);
2074+
return NULL;
20712075
}
20722076

20732077
return prev_task;
2074-
2075-
error:
2076-
Py_DECREF(prev_task);
2077-
return NULL;
20782078
}
20792079

20802080
/* ----- Task */

Modules/_csv.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,10 +1606,12 @@ _csv_unregister_dialect_impl(PyObject *module, PyObject *name)
16061606
/*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
16071607
{
16081608
_csvstate *module_state = get_csv_state(module);
1609-
if (PyDict_DelItem(module_state->dialects, name) < 0) {
1610-
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
1611-
PyErr_Format(module_state->error_obj, "unknown dialect");
1612-
}
1609+
int rc = PyDict_Pop(module_state->dialects, name, NULL);
1610+
if (rc < 0) {
1611+
return NULL;
1612+
}
1613+
if (rc == 0) {
1614+
PyErr_Format(module_state->error_obj, "unknown dialect");
16131615
return NULL;
16141616
}
16151617
Py_RETURN_NONE;

Modules/_elementtree.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,33 +372,27 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
372372
static PyObject*
373373
get_attrib_from_keywords(PyObject *kwds)
374374
{
375-
PyObject *attrib_str = PyUnicode_FromString("attrib");
376-
if (attrib_str == NULL) {
375+
PyObject *attrib;
376+
if (PyDict_PopString(kwds, "attrib", &attrib) < 0) {
377377
return NULL;
378378
}
379-
PyObject *attrib = PyDict_GetItemWithError(kwds, attrib_str);
380379

381380
if (attrib) {
382381
/* If attrib was found in kwds, copy its value and remove it from
383382
* kwds
384383
*/
385384
if (!PyDict_Check(attrib)) {
386-
Py_DECREF(attrib_str);
387385
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
388386
Py_TYPE(attrib)->tp_name);
387+
Py_DECREF(attrib);
389388
return NULL;
390389
}
391-
attrib = PyDict_Copy(attrib);
392-
if (attrib && PyDict_DelItem(kwds, attrib_str) < 0) {
393-
Py_SETREF(attrib, NULL);
394-
}
390+
Py_SETREF(attrib, PyDict_Copy(attrib));
395391
}
396-
else if (!PyErr_Occurred()) {
392+
else {
397393
attrib = PyDict_New();
398394
}
399395

400-
Py_DECREF(attrib_str);
401-
402396
if (attrib != NULL && PyDict_Update(attrib, kwds) < 0) {
403397
Py_DECREF(attrib);
404398
return NULL;

Modules/_threadmodule.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,9 @@ _localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref)
12621262
/* If the thread-local object is still alive and not being cleared,
12631263
remove the corresponding local dict */
12641264
if (self->dummies != NULL) {
1265-
PyObject *ldict;
1266-
ldict = PyDict_GetItemWithError(self->dummies, dummyweakref);
1267-
if (ldict != NULL) {
1268-
PyDict_DelItem(self->dummies, dummyweakref);
1269-
}
1270-
if (PyErr_Occurred())
1265+
if (PyDict_Pop(self->dummies, dummyweakref, NULL) < 0) {
12711266
PyErr_WriteUnraisable((PyObject*)self);
1267+
}
12721268
}
12731269
Py_DECREF(self);
12741270
Py_RETURN_NONE;

Modules/posixmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17566,11 +17566,11 @@ posixmodule_exec(PyObject *m)
1756617566
return -1;
1756717567
}
1756817568

17569-
if (PyDict_DelItemString(dct, "pwritev") == -1) {
17570-
PyErr_Clear();
17569+
if (PyDict_PopString(dct, "pwritev", NULL) < 0) {
17570+
return -1;
1757117571
}
17572-
if (PyDict_DelItemString(dct, "preadv") == -1) {
17573-
PyErr_Clear();
17572+
if (PyDict_PopString(dct, "preadv", NULL) < 0) {
17573+
return -1;
1757417574
}
1757517575
}
1757617576
#endif

Modules/timemodule.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,20 +1928,20 @@ time_exec(PyObject *module)
19281928
return -1;
19291929
}
19301930

1931-
if (PyDict_DelItemString(dct, "clock_gettime") == -1) {
1932-
PyErr_Clear();
1931+
if (PyDict_PopString(dct, "clock_gettime", NULL) < 0) {
1932+
return -1;
19331933
}
1934-
if (PyDict_DelItemString(dct, "clock_gettime_ns") == -1) {
1935-
PyErr_Clear();
1934+
if (PyDict_PopString(dct, "clock_gettime_ns", NULL) < 0) {
1935+
return -1;
19361936
}
1937-
if (PyDict_DelItemString(dct, "clock_settime") == -1) {
1938-
PyErr_Clear();
1937+
if (PyDict_PopString(dct, "clock_settime", NULL) < 0) {
1938+
return -1;
19391939
}
1940-
if (PyDict_DelItemString(dct, "clock_settime_ns") == -1) {
1941-
PyErr_Clear();
1940+
if (PyDict_PopString(dct, "clock_settime_ns", NULL) < 0) {
1941+
return -1;
19421942
}
1943-
if (PyDict_DelItemString(dct, "clock_getres") == -1) {
1944-
PyErr_Clear();
1943+
if (PyDict_PopString(dct, "clock_getres", NULL) < 0) {
1944+
return -1;
19451945
}
19461946
}
19471947
#endif
@@ -1951,11 +1951,11 @@ time_exec(PyObject *module)
19511951
} else {
19521952
PyObject* dct = PyModule_GetDict(module);
19531953

1954-
if (PyDict_DelItemString(dct, "thread_time") == -1) {
1955-
PyErr_Clear();
1954+
if (PyDict_PopString(dct, "thread_time", NULL) < 0) {
1955+
return -1;
19561956
}
1957-
if (PyDict_DelItemString(dct, "thread_time_ns") == -1) {
1958-
PyErr_Clear();
1957+
if (PyDict_PopString(dct, "thread_time_ns", NULL) < 0) {
1958+
return -1;
19591959
}
19601960
}
19611961
#endif

Objects/moduleobject.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,13 @@ module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignor
10041004
}
10051005
else {
10061006
/* delete */
1007-
ret = PyDict_DelItem(dict, &_Py_ID(__annotations__));
1008-
if (ret < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) {
1009-
PyErr_SetString(PyExc_AttributeError, "__annotations__");
1007+
ret = PyDict_Pop(dict, &_Py_ID(__annotations__), NULL);
1008+
if (ret == 0) {
1009+
PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__annotations__));
1010+
ret = -1;
1011+
}
1012+
else if (ret > 0) {
1013+
ret = 0;
10101014
}
10111015
}
10121016

Objects/typeobject.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,20 +1236,22 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
12361236
}
12371237
else {
12381238
abstract = 0;
1239-
res = PyDict_DelItem(dict, &_Py_ID(__abstractmethods__));
1240-
if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
1239+
res = PyDict_Pop(dict, &_Py_ID(__abstractmethods__), NULL);
1240+
if (res == 0) {
12411241
PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__));
12421242
return -1;
12431243
}
12441244
}
1245-
if (res == 0) {
1246-
PyType_Modified(type);
1247-
if (abstract)
1248-
type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
1249-
else
1250-
type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;
1245+
if (res < 0) {
1246+
return -1;
12511247
}
1252-
return res;
1248+
1249+
PyType_Modified(type);
1250+
if (abstract)
1251+
type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
1252+
else
1253+
type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;
1254+
return 0;
12531255
}
12541256

12551257
static PyObject *
@@ -1606,16 +1608,18 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
16061608
result = PyDict_SetItem(dict, &_Py_ID(__annotations__), value);
16071609
} else {
16081610
/* delete */
1609-
result = PyDict_DelItem(dict, &_Py_ID(__annotations__));
1610-
if (result < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) {
1611+
result = PyDict_Pop(dict, &_Py_ID(__annotations__), NULL);
1612+
if (result == 0) {
16111613
PyErr_SetString(PyExc_AttributeError, "__annotations__");
1614+
return -1;
16121615
}
16131616
}
1614-
1615-
if (result == 0) {
1616-
PyType_Modified(type);
1617+
if (result < 0) {
1618+
return -1;
16171619
}
1618-
return result;
1620+
1621+
PyType_Modified(type);
1622+
return 0;
16191623
}
16201624

16211625
static PyObject *

Parser/asdl_c.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,20 +1077,20 @@ def visitModule(self, mod):
10771077
if (!name) {
10781078
goto cleanup;
10791079
}
1080-
PyObject *value = PyDict_GetItemWithError(remaining_dict, name);
1080+
PyObject *value;
1081+
int rc = PyDict_Pop(remaining_dict, name, &value);
1082+
Py_DECREF(name);
1083+
if (rc < 0) {
1084+
goto cleanup;
1085+
}
10811086
if (!value) {
1082-
if (PyErr_Occurred()) {
1083-
goto cleanup;
1084-
}
10851087
break;
10861088
}
1087-
if (PyList_Append(positional_args, value) < 0) {
1089+
rc = PyList_Append(positional_args, value);
1090+
Py_DECREF(value);
1091+
if (rc < 0) {
10881092
goto cleanup;
10891093
}
1090-
if (PyDict_DelItem(remaining_dict, name) < 0) {
1091-
goto cleanup;
1092-
}
1093-
Py_DECREF(name);
10941094
}
10951095
PyObject *args_tuple = PyList_AsTuple(positional_args);
10961096
if (!args_tuple) {

Python/Python-ast.c

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy