Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Preserve string kind modifiers #49

Merged
merged 2 commits into from
Sep 15, 2017
Merged

Conversation

ilevkivskyi
Copy link
Member

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
Member

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

@ilevkivskyi
Copy link
Member Author

@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
Member Author

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
@gvanrossum
Copy link
Member

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

@ddfisher
Copy link
Collaborator

👍

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 b-to-u branch September 15, 2017 11:29
@ilevkivskyi
Copy link
Member Author

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
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
tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this pull request Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants