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-36280: Add Constant.kind field #12295

Merged
merged 6 commits into from
Mar 13, 2019

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Mar 12, 2019

The value is a string for string and byte literals, None otherwise.
It is 'u' for u"..." literals, 'b' for b"..." literals, '' for "..." literals.
The 'r' (raw) prefix is ignored.
Does not apply to f-strings.

This appears sufficient to make mypy capable of using the stdlib ast module instead of typed_ast (assuming a mypy patch I'm working on).

WIP: I need to make the tests pass. @ilevkivskyi @serhiy-storchaka

https://bugs.python.org/issue36280

The value is a string for string and byte literals, None otherwise.
It's 'u' for u... literals, 'b' for b... literals, '' for ... literals.
@serhiy-storchaka
Copy link
Member

Do you need indications for triple-quote strings?

Why do you need 'b' for bytes if you can use isinstance(node.value, bytes)?

What kind should be for concatenated '' and u'' literals? E.g.: 'abc' u'def'.

@gvanrossum
Copy link
Member Author

Do you need indications for triple-quote strings?

Not for this use case.

Why do you need 'b' for bytes if you can use isinstance(node.value, bytes)?

Good point. (I believe I was just copying that behavior from the Python 2 part of typed_ast, where it was considered useful.)

What kind should be for concatenated '' and u'' literals? E.g.: 'abc' u'def'.

For my use case it doesn't really matter; I'd rather not waste time trying to do something smarter than looking for the first segment.

Here's what I propose to do. I'll set it to 'u' if the first segment starts with 'u' (since ru'...' isn't allowed anyway), else I'll set it to NULL/None.

Sadly none of that helps me fixing the unit tests -- I believe the problems are all caused by the changes to the repr() of ast.Constant.

@gvanrossum gvanrossum changed the title [WIP] Add Constant.kind field bpo-36280: Add Constant.kind field Mar 13, 2019
Python/ast.c Outdated Show resolved Hide resolved
@miss-islington miss-islington merged commit 10f8ce6 into python:master Mar 13, 2019
@miss-islington
Copy link
Contributor

@gvanrossum: Status check is done, and it's a success ✅ .

@miss-islington
Copy link
Contributor

Sorry, I can't merge this PR. Reason: Pull Request is not mergeable.

@gvanrossum gvanrossum deleted the constant-kind branch March 13, 2019 20:02
gvanrossum added a commit to python/mypy that referenced this pull request Mar 15, 2019
To test with Python 3.8, this requires python/cpython#12295. The typeshed changes were in python/typeshed#2859 (and synced in #6540).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants