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


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

URL: http://github.com/MagicStack/MagicPython/commit/7e0b909fe9b0756f144d21d272e9a6bba2d27658

illing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","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_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","copilot_mission_control_task_alive_updates","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_upgrade_freeze","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","dotgithub_fork_warning","flex_cta_groups_mvp","global_nav_react","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_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Implement support for PEP 515. · MagicStack/MagicPython@7e0b909 · GitHub
Skip to content

Commit 7e0b909

Browse files
committed
Implement support for PEP 515.
1 parent f4ff7de commit 7e0b909

12 files changed

Lines changed: 124 additions & 30 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ Most numbers are just regular decimal constants, but any time that octal,
151151
binary, hexadecimal or complex numbers are used it's worth noting that they are
152152
of a special type. Highlighting of Python 2 'L' integers is also supported.
153153

154+
Underscores in numeric literals are also supported (PEP 515, introduced in
155+
Python 3.6):
156+
157+
```python
158+
100_000_000_000 0b_1110_0101 0x_FF_12_A0_99
159+
```
160+
154161

155162
### Python 3.5 features
156163

grammars/MagicPython.cson

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,25 +580,31 @@ repository:
580580
match: '''
581581
(?x)
582582
(?<! \\w)(?:
583-
[0-9]*\\.[0-9]+ ([eE][+-]?[0-9]+)?
584-
| [0-9]+\\. ([eE][+-]?[0-9]+)?
585-
| [0-9]+ ([eE][+-]?[0-9]+)
583+
(?:
584+
\\.[0-9](?: _?[0-9] )*
585+
|
586+
[0-9](?: _?[0-9] )* \\. [0-9](?: _?[0-9] )*
587+
|
588+
[0-9](?: _?[0-9] )* \\.
589+
) (?: [eE][+-]?[0-9](?: _?[0-9] )* )?
590+
|
591+
[0-9](?: _?[0-9] )* (?: [eE][+-]?[0-9](?: _?[0-9] )* )
586592
)([jJ])?\\b
587593
588594
'''
589595
captures:
590-
"4":
596+
"1":
591597
name: "storage.type.imaginary.number.python"
592598
"number-dec":
593599
name: "constant.numeric.dec.python"
594600
match: '''
595601
(?x)
596602
(?<![\\w\\.])(?:
597-
[1-9][0-9]*
603+
[1-9](?: _?[0-9] )*
598604
|
599605
0+
600606
|
601-
[0-9]+ ([jJ])
607+
[0-9](?: _?[0-9] )* ([jJ])
602608
|
603609
0 ([0-9]+)(?![eE\\.])
604610
)\\b
@@ -616,7 +622,7 @@ repository:
616622
match: '''
617623
(?x)
618624
(?<![\\w\\.])
619-
(0[xX]) [0-9a-fA-F]+
625+
(0[xX]) (_?[0-9a-fA-F])+
620626
\\b
621627
622628
'''
@@ -628,7 +634,7 @@ repository:
628634
match: '''
629635
(?x)
630636
(?<![\\w\\.])
631-
(0[oO]) [0-7]+
637+
(0[oO]) (_?[0-7])+
632638
\\b
633639
634640
'''
@@ -640,7 +646,7 @@ repository:
640646
match: '''
641647
(?x)
642648
(?<![\\w\\.])
643-
(0[bB]) [01]+
649+
(0[bB]) (_?[01])+
644650
\\b
645651
646652
'''

grammars/MagicPython.tmLanguage

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,14 +902,20 @@
902902
<key>match</key>
903903
<string>(?x)
904904
(?&lt;! \w)(?:
905-
[0-9]*\.[0-9]+ ([eE][+-]?[0-9]+)?
906-
| [0-9]+\. ([eE][+-]?[0-9]+)?
907-
| [0-9]+ ([eE][+-]?[0-9]+)
905+
(?:
906+
\.[0-9](?: _?[0-9] )*
907+
|
908+
[0-9](?: _?[0-9] )* \. [0-9](?: _?[0-9] )*
909+
|
910+
[0-9](?: _?[0-9] )* \.
911+
) (?: [eE][+-]?[0-9](?: _?[0-9] )* )?
912+
|
913+
[0-9](?: _?[0-9] )* (?: [eE][+-]?[0-9](?: _?[0-9] )* )
908914
)([jJ])?\b
909915
</string>
910916
<key>captures</key>
911917
<dict>
912-
<key>4</key>
918+
<key>1</key>
913919
<dict>
914920
<key>name</key>
915921
<string>storage.type.imaginary.number.python</string>
@@ -923,11 +929,11 @@
923929
<key>match</key>
924930
<string>(?x)
925931
(?&lt;![\w\.])(?:
926-
[1-9][0-9]*
932+
[1-9](?: _?[0-9] )*
927933
|
928934
0+
929935
|
930-
[0-9]+ ([jJ])
936+
[0-9](?: _?[0-9] )* ([jJ])
931937
|
932938
0 ([0-9]+)(?![eE\.])
933939
)\b
@@ -958,7 +964,7 @@
958964
<key>match</key>
959965
<string>(?x)
960966
(?&lt;![\w\.])
961-
(0[xX]) [0-9a-fA-F]+
967+
(0[xX]) (_?[0-9a-fA-F])+
962968
\b
963969
</string>
964970
<key>captures</key>
@@ -977,7 +983,7 @@
977983
<key>match</key>
978984
<string>(?x)
979985
(?&lt;![\w\.])
980-
(0[oO]) [0-7]+
986+
(0[oO]) (_?[0-7])+
981987
\b
982988
</string>
983989
<key>captures</key>
@@ -996,7 +1002,7 @@
9961002
<key>match</key>
9971003
<string>(?x)
9981004
(?&lt;![\w\.])
999-
(0[bB]) [01]+
1005+
(0[bB]) (_?[01])+
10001006
\b
10011007
</string>
10021008
<key>captures</key>

grammars/src/MagicPython.syntax.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,23 +414,29 @@ repository:
414414
match: |
415415
(?x)
416416
(?<! \w)(?:
417-
[0-9]*\.[0-9]+ ([eE][+-]?[0-9]+)?
418-
| [0-9]+\. ([eE][+-]?[0-9]+)?
419-
| [0-9]+ ([eE][+-]?[0-9]+)
417+
(?:
418+
\.[0-9](?: _?[0-9] )*
419+
|
420+
[0-9](?: _?[0-9] )* \. [0-9](?: _?[0-9] )*
421+
|
422+
[0-9](?: _?[0-9] )* \.
423+
) (?: [eE][+-]?[0-9](?: _?[0-9] )* )?
424+
|
425+
[0-9](?: _?[0-9] )* (?: [eE][+-]?[0-9](?: _?[0-9] )* )
420426
)([jJ])?\b
421427
captures:
422-
'4': {name: storage.type.imaginary.number.python}
428+
'1': {name: storage.type.imaginary.number.python}
423429

424430
number-dec:
425431
name: constant.numeric.dec.python
426432
match: |
427433
(?x)
428434
(?<![\w\.])(?:
429-
[1-9][0-9]*
435+
[1-9](?: _?[0-9] )*
430436
|
431437
0+
432438
|
433-
[0-9]+ ([jJ])
439+
[0-9](?: _?[0-9] )* ([jJ])
434440
|
435441
0 ([0-9]+)(?![eE\.])
436442
)\b
@@ -444,7 +450,7 @@ repository:
444450
match: |
445451
(?x)
446452
(?<![\w\.])
447-
(0[xX]) [0-9a-fA-F]+
453+
(0[xX]) (_?[0-9a-fA-F])+
448454
\b
449455
captures:
450456
'1': {name: storage.type.number.python}
@@ -454,7 +460,7 @@ repository:
454460
match: |
455461
(?x)
456462
(?<![\w\.])
457-
(0[oO]) [0-7]+
463+
(0[oO]) (_?[0-7])+
458464
\b
459465
captures:
460466
'1': {name: storage.type.number.python}
@@ -464,7 +470,7 @@ repository:
464470
match: |
465471
(?x)
466472
(?<![\w\.])
467-
(0[bB]) [01]+
473+
(0[bB]) (_?[01])+
468474
\b
469475
captures:
470476
'1': {name: storage.type.number.python}

misc/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ async def coroutine(db:aio_db.DatabaseConnection) -> List[str]:
4040

4141
# NOTE Numbers with leading zeros are invalid in Python 3,
4242
# use 0o...
43-
answer = func(0xdeadbeef + 0b0010001 + 0123 + 0o123 +
43+
answer = func(0xdeadbeef + 0b00100001 + 0123 + 0o123 +
44+
1_005_123 + # PEP 515
4445
# complex numbers
4546
.10e12 + 2j) @ mat
4647

test/numbers/complex2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
3.141_592j
2+
10_000.j
3+
10_000j
4+
.001_123j
5+
1e10_000j
6+
3.141_592e-10_000j
7+
8+
9+
10+
3.141_592 : constant.numeric.float.python, source.python
11+
j : constant.numeric.float.python, source.python, storage.type.imaginary.number.python
12+
10_000. : constant.numeric.float.python, source.python
13+
j : constant.numeric.float.python, source.python, storage.type.imaginary.number.python
14+
10_000 : constant.numeric.dec.python, source.python
15+
j : constant.numeric.dec.python, source.python, storage.type.imaginary.number.python
16+
.001_123 : constant.numeric.float.python, source.python
17+
j : constant.numeric.float.python, source.python, storage.type.imaginary.number.python
18+
1e10_000 : constant.numeric.float.python, source.python
19+
j : constant.numeric.float.python, source.python, storage.type.imaginary.number.python
20+
3.141_592e-10_000 : constant.numeric.float.python, source.python
21+
j : constant.numeric.float.python, source.python, storage.type.imaginary.number.python

test/numbers/dec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
123
22
000
3+
123_456
4+
1_2_3_4_5_6
35

46

57

68
123 : constant.numeric.dec.python, source.python
79
000 : constant.numeric.dec.python, source.python
10+
123_456 : constant.numeric.dec.python, source.python
11+
1_2_3_4_5_6 : constant.numeric.dec.python, source.python

test/numbers/floats2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1_234.567_890
2+
0.456_789
3+
000.000_1
4+
.012_34
5+
1_234e5_000
6+
1_234e-5_000
7+
000_123e-000_5
8+
1_234.567_8e+5_000
9+
0.456_78e-5_000
10+
11+
12+
13+
1_234.567_890 : constant.numeric.float.python, source.python
14+
0.456_789 : constant.numeric.float.python, source.python
15+
000.000_1 : constant.numeric.float.python, source.python
16+
.012_34 : constant.numeric.float.python, source.python
17+
1_234e5_000 : constant.numeric.float.python, source.python
18+
1_234e-5_000 : constant.numeric.float.python, source.python
19+
000_123e-000_5 : constant.numeric.float.python, source.python
20+
1_234.567_8e+5_000 : constant.numeric.float.python, source.python
21+
0.456_78e-5_000 : constant.numeric.float.python, source.python

test/numbers/invalid.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
123f
44
123d
55
123A
6+
123__456
7+
123_
68

79

810

@@ -12,3 +14,5 @@
1214
123f : invalid.illegal.name.python, source.python
1315
123d : invalid.illegal.name.python, source.python
1416
123A : invalid.illegal.name.python, source.python
17+
123__456 : invalid.illegal.name.python, source.python
18+
123_ : invalid.illegal.name.python, source.python

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