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

Preserve string kind modifiers #49

Merged
merged 2 commits into from Sep 15, 2017
Merged

Preserve string kind modifiers #49

merged 2 commits into from Sep 15, 2017

Conversation

@ilevkivskyi
Copy link
Collaborator

@ilevkivskyi ilevkivskyi commented Jul 24, 2017

This will help experimenting with python/mypy#3648

Currently we preserve only b string modifier on Python 2, this is a bit arbitrary and for the above mentioned PR we need to keep u. Instead of adding another special-casing I just always preserve all string modifiers in a short string kind on Str node, for example:

>>> st = ast3.parse("u'hi'")
>>> st.body[0].value.kind
'u'
@JelleZijlstra
Copy link

@JelleZijlstra JelleZijlstra commented Jul 24, 2017

Does typed-ast have backwards compatibility guarantees? You're dropping the has_b attribute from ast27 Str nodes.

@ilevkivskyi
Copy link
Collaborator Author

@ilevkivskyi ilevkivskyi commented Jul 24, 2017

@JelleZijlstra FWIW I added it some time ago by request from @gvanrossum but it was never used since then. It stayed deprecated for few last releases: https://github.com/python/typed_ast/blob/master/typed_ast/ast27.py#L23

@ilevkivskyi
Copy link
Collaborator Author

@ilevkivskyi ilevkivskyi commented Jul 24, 2017

Moreover, the new kind attribute can still be used instead if we will return to b later (only "API" is changed, not functionality).

@gvanrossum gvanrossum merged commit d498191 into python:master Sep 15, 2017
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Sep 15, 2017

Thanks! Using my new powers as a typed_ast committer to merge this.

@ddfisher
Copy link
Collaborator

@ddfisher ddfisher commented Sep 15, 2017

👍

All differences from the standard Python AST are documented in the module documentation. @ilevkivskyi, would you mind updating the docs here and here?

@ilevkivskyi ilevkivskyi deleted the ilevkivskyi:b-to-u branch Sep 15, 2017
@ilevkivskyi
Copy link
Collaborator Author

@ilevkivskyi ilevkivskyi commented Sep 15, 2017

All differences from the standard Python AST are documented in the module documentation. @ilevkivskyi, would you mind updating the docs here and here?

Yes, sure, I will make a PR with the docs. But probably not this week.

@ilevkivskyi ilevkivskyi mentioned this pull request Sep 17, 2017
Michael0x2a added a commit to Michael0x2a/mypy that referenced this pull request Dec 17, 2018
This pull request bumps the minimum allowed version of typed-ast to
version 1.1.1. This is mostly so that we can have
python/typed_ast#49, which we need to correctly
handle Literals containing unicode strings when analyzing Python 2
source code.
Michael0x2a added a commit to python/mypy that referenced this pull request Dec 17, 2018
This pull request bumps the minimum allowed version of typed-ast to
version 1.1.1. This is mostly so that we can have
python/typed_ast#49, which we need to correctly
handle Literals containing unicode strings when analyzing Python 2
source code.
Michael0x2a added a commit to Michael0x2a/typeshed that referenced this pull request Dec 18, 2018
We recently cut a new-ish release of typed-ast that [adds a new field][0]
named `kind` to the `ast27.Str` and `ast3.Str` classes. This field
stores whatever string modifiers (like `b` or `u`) were present on the
original string.

As a note, I've confirmed that this field is indeed a str (and not
bytes) for ast27's Str class.

  [0]: python/typed_ast#49
Michael0x2a added a commit to python/typeshed that referenced this pull request Dec 18, 2018
We recently cut a new-ish release of typed-ast that [adds a new field][0]
named `kind` to the `ast27.Str` and `ast3.Str` classes. This field
stores whatever string modifiers (like `b` or `u`) were present on the
original string.

As a note, I've confirmed that this field is indeed a str (and not
bytes) for ast27's Str class.

  [0]: python/typed_ast#49
msullivan added a commit that referenced this pull request Jan 8, 2019
The introduction of string kinds in #49 missed updating the 2to3 visitor
for it. Update the `visit_Str` case to pass `s.kind` to `Str`.

Fixes #66.
msullivan added a commit that referenced this pull request Jan 9, 2019
The introduction of string kinds in #49 missed updating the 2to3 visitor
for it. Update the `visit_Str` case to pass `s.kind` to `Str`.

Fixes #66.
gvanrossum pushed a commit that referenced this pull request Jan 20, 2019
Guido van Rossum
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
We recently cut a new-ish release of typed-ast that [adds a new field][0]
named `kind` to the `ast27.Str` and `ast3.Str` classes. This field
stores whatever string modifiers (like `b` or `u`) were present on the
original string.

As a note, I've confirmed that this field is indeed a str (and not
bytes) for ast27's Str class.

  [0]: python/typed_ast#49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.