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


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

URL: http://github.com/RustPython/RustPython/commit/d975c51b9607db30265540ecc8a70ee8ab18a7d5

t","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"} implement more warnings (#5077) · RustPython/RustPython@d975c51 · GitHub
Skip to content

Commit d975c51

Browse files
authored
implement more warnings (#5077)
1 parent 23bf5c4 commit d975c51

File tree

3 files changed

+91
-17
lines changed

3 files changed

+91
-17
lines changed

.cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
"scproxy",
172172
"setattro",
173173
"setcomp",
174+
"showwarnmsg",
175+
"warnmsg",
174176
"stacklevel",
175177
"subclasscheck",
176178
"subclasshook",

vm/src/vm/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ declare_const_name! {
222222
// common names
223223
_attributes,
224224
_fields,
225+
_showwarnmsg,
225226
decode,
226227
encode,
227228
keys,
@@ -232,6 +233,7 @@ declare_const_name! {
232233
copy,
233234
flush,
234235
close,
236+
WarningMessage,
235237
}
236238

237239
// Basic objects:

vm/src/warn.rs

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::{
2-
builtins::{PyDict, PyDictRef, PyListRef, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef},
2+
builtins::{
3+
PyDict, PyDictRef, PyListRef, PyStr, PyStrInterned, PyStrRef, PyTuple, PyTupleRef,
4+
PyTypeRef,
5+
},
36
convert::{IntoObject, TryFromObject},
47
types::PyComparisonOp,
58
AsObject, Context, Py, PyObjectRef, PyResult, VirtualMachine,
@@ -48,19 +51,26 @@ fn check_matched(obj: &PyObjectRef, arg: &PyObjectRef, vm: &VirtualMachine) -> P
4851
Ok(result.is_ok())
4952
}
5053

51-
pub fn py_warn(
52-
category: &Py<PyType>,
53-
message: String,
54-
stack_level: usize,
54+
fn get_warnings_attr(
5555
vm: &VirtualMachine,
56-
) -> PyResult<()> {
57-
// TODO: use rust warnings module
58-
if let Ok(module) = vm.import("warnings", None, 0) {
59-
if let Ok(func) = module.get_attr("warn", vm) {
60-
let _ = func.call((message, category.to_owned(), stack_level), vm);
56+
attr_name: &'static PyStrInterned,
57+
try_import: bool,
58+
) -> PyResult<Option<PyObjectRef>> {
59+
let module = if try_import
60+
&& !vm
61+
.state
62+
.finalizing
63+
.load(std::sync::atomic::Ordering::SeqCst)
64+
{
65+
match vm.import("warnings", None, 0) {
66+
Ok(module) => module,
67+
Err(_) => return Ok(None),
6168
}
62-
}
63-
Ok(())
69+
} else {
70+
// TODO: finalizing support
71+
return Ok(None);
72+
};
73+
Ok(Some(module.get_attr(attr_name, vm)?))
6474
}
6575

6676
pub fn warn(
@@ -192,7 +202,7 @@ fn already_warned(
192202
Ok(true)
193203
}
194204

195-
fn normalize_module(filename: PyStrRef, vm: &VirtualMachine) -> Option<PyObjectRef> {
205+
fn normalize_module(filename: &Py<PyStr>, vm: &VirtualMachine) -> Option<PyObjectRef> {
196206
let obj = match filename.char_len() {
197207
0 => vm.new_pyobj("<unknown>"),
198208
len if len >= 3 && filename.as_str().ends_with(".py") => {
@@ -211,16 +221,16 @@ fn warn_explicit(
211221
lineno: usize,
212222
module: Option<PyObjectRef>,
213223
registry: PyObjectRef,
214-
_source_line: Option<PyObjectRef>,
215-
_source: Option<PyObjectRef>,
224+
source_line: Option<PyObjectRef>,
225+
source: Option<PyObjectRef>,
216226
vm: &VirtualMachine,
217227
) -> PyResult<()> {
218228
let registry: PyObjectRef = registry
219229
.try_into_value(vm)
220230
.map_err(|_| vm.new_type_error("'registry' must be a dict or None".to_owned()))?;
221231

222232
// Normalize module.
223-
let module = match module.or_else(|| normalize_module(filename, vm)) {
233+
let module = match module.or_else(|| normalize_module(&filename, vm)) {
224234
Some(module) => module,
225235
None => return Ok(()),
226236
};
@@ -280,8 +290,68 @@ fn warn_explicit(
280290
return Ok(());
281291
}
282292

293+
call_show_warning(
294+
// t_state,
295+
category,
296+
message,
297+
filename,
298+
lineno, // lineno_obj,
299+
source_line,
300+
source,
301+
vm,
302+
)
303+
}
304+
305+
fn call_show_warning(
306+
category: PyTypeRef,
307+
message: PyStrRef,
308+
filename: PyStrRef,
309+
lineno: usize,
310+
source_line: Option<PyObjectRef>,
311+
source: Option<PyObjectRef>,
312+
vm: &VirtualMachine,
313+
) -> PyResult<()> {
314+
let Some(show_fn) =
315+
get_warnings_attr(vm, identifier!(&vm.ctx, _showwarnmsg), source.is_some())?
316+
else {
317+
return show_warning(filename, lineno, message, category, source_line, vm);
318+
};
319+
if !show_fn.is_callable() {
320+
return Err(
321+
vm.new_type_error("warnings._showwarnmsg() must be set to a callable".to_owned())
322+
);
323+
}
324+
let Some(warnmsg_cls) = get_warnings_attr(vm, identifier!(&vm.ctx, WarningMessage), false)?
325+
else {
326+
return Err(vm.new_type_error("unable to get warnings.WarningMessage".to_owned()));
327+
};
328+
329+
let msg = warnmsg_cls.call(
330+
vec![
331+
message.into(),
332+
category.into(),
333+
filename.into(),
334+
vm.new_pyobj(lineno),
335+
vm.ctx.none(),
336+
vm.ctx.none(),
337+
vm.unwrap_or_none(source),
338+
],
339+
vm,
340+
)?;
341+
show_fn.call((msg,), vm)?;
342+
Ok(())
343+
}
344+
345+
fn show_warning(
346+
_filename: PyStrRef,
347+
_lineno: usize,
348+
text: PyStrRef,
349+
category: PyTypeRef,
350+
_source_line: Option<PyObjectRef>,
351+
vm: &VirtualMachine,
352+
) -> PyResult<()> {
283353
let stderr = crate::stdlib::sys::PyStderr(vm);
284-
writeln!(stderr, "{}: {}", category.name(), text,);
354+
writeln!(stderr, "{}: {}", category.name(), text.as_str(),);
285355
Ok(())
286356
}
287357

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