Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127833: lexical analysis: Improve section on Numeric literals#134850

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
encukou wants to merge6 commits intopython:main
base:main
Choose a base branch
Loading
fromencukou:lex-analysis-numbers

Conversation

encukou
Copy link
Member

@encukouencukou commentedMay 28, 2025
edited by github-actionsbot
Loading

Each section is expanded, and now progresses from simple cases and examples to more involved ones, ending with the formal grammar.

This uses meta-syntax that I want to add to the introduction in#134443. I'm marking it as draft until that's merged.


📚 Documentation preview 📚:https://cpython-previews--134850.org.readthedocs.build/

Comment on lines +1090 to +1094
Instead, :ref:`complex numbers <typesnumeric>` can be written
as adding the complex number's real part and imaginary part.

.. productionlist:: python-grammar
imagnumber: (`floatnumber` | `digitpart`) ("j" | "J")
For example, the imaginary number 3.1+4\ *i* can be written as adding the
real number 3.1 to the imaginary number 4\ *i*.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, but this is a wrong picture.

The CPython has no pure-imaginary numbers and above decomposition is invalid in general. Simple counterexample:

>>>-0.0+0j0j>>>complex(-0.0,0)(-0+0j)

Previous description was valid: "An imaginary literal yields a complex number with a real part of 0.0."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The key point is this islexical analysis. Python indeed has no imaginary literals, but the tokeniser does --4+16j is three tokens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think L1093 should say 'the complex number ...', though.

encukou reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure, but16j is not an imaginary number. It's a complex number with a real part+0.0. And complex number in the Python currently can't be "written as adding the complex number's real part and imaginary part."

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

16j is not an imaginary number; but 16i is :)

I agree that this could be clearer. Will update. (Not surewhen, as I recently volunteered to focus on f-strings first.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

16j is not an imaginary number; but 16i is :)

But you are talking not about mathematics, but Python's complex numbers.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@skirpichevskirpichevskirpichev left review comments

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

Assignees
No one assigned
Labels
docsDocumentation in the Doc dirskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@encukou@skirpichev@AA-Turner

[8]ページ先頭

©2009-2025 Movatter.jp